  % Title "Console Demo"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  % NoEscape
  $ filename "t.exe"
 'uses RTL64
  uses consoleG

  function DOS(string s)
  ======================
  string c
  static STARTUPINFO         infs
  static PROCESS_INFORMATION infp
  if s then c="cmd.exe /c " else c="cmd.exe "
  CreateProcess null,c+s,0,0,0,0,0,0,@infs,@infp
  WaitForMultipleObjects 1,@infp.hthread,1,-1
  CloseHandle infp.hProcess
  CloseHandle infp.hThread
  end function


  sub main()
  ==========
  static string dtxt, s
  cls 0,.15,.2
  '
  'TITLE
  pushstate
  scale 2.,1.25
  typeface=0
  printl "COMMAND"
  popstate
  '
  move 0,-3
  '
  'LISTING
  pushstate
  sys a,b,c
  sys le=len dtxt
  scale 1
  typeface=1
  b=1
  static sys lino,sttp,lkey,d
  if lkey=VK_DOWN
    sttp+=1
    if sttp>d then sttp=d
  elseif lkey=VK_UP
    sttp-=1
    if sttp<0 then sttp=0
  end if
  lkey=0
  d=0
  do
    if b>le then
      exit do
    end if
    a=instr b,dtxt,cr
    if a=0 then a=len dtxt+1
    d++
    if d>sttp then 
      s=mid(dtxt,b,a-b)
      printl s
      c++ 'linecounter
      if c>22 then exit do
    end if
    b=a+1
  end do
  popstate
  '
  'INPUT
  move 0,-25
  PushState
    color .20,.80,.80,.99
    typeface=2
    color .90,.00,.00,.88
    shading
    PushState
      scale .5
      move 0,.5
      go sphere
    PopState
    flat
    color .80,.80,.00,.88
    move 1
    typeface=1
    input inputs
    lkey=lastkey
    typeface=0
  PopState
  '
  '
  'COMMAND PROCESSING
  printl
  color .00,.80,.80
  if LastInput
    s=ltrim rtrim LastInput
    LastInput=""
    inputs=""
    if s
      s=lcase s
      le=len s
      'COMMAND INTERCEPTS
      if s="exit" then
        CloseWindow
      elseif left(s,3)="cd "
        s=ltrim mid s,4
        SetCurrentDirectory s
      else 
        DOS s+">temp.txt"
        dtxt=getfile "temp.txt"
      end if
    end if

  end if
  printl ""
  lastkey=0
  lastchar=0
  '
  end sub

  EndScript
