  #compact
  % filename "t.exe"
  % Title "Console Demo (F1 help)"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
 '% NoEscape
  % WindowOpacity 244 'max 255

  'uses RTL64
  uses ConsoleG
  'uses ParseUtil

  macro LineEdit(a,s,pkl,b,e,en,n)
  ================================
  scope
  int i,m,p,q
  m=picked and 0xff0000
  p=picked and 0xff
  q=picked>>8 and 0xff
  if not pks=pkl
    inputs=s[pkl]
  end if
  cp=q
  a=input inputs
  q=cp
  '
  'SPLIT LINE / DELETE MERGE
  if a=13
    s[pkl]=left inputs,cp-1
    inputs=mid inputs,cp
    q=1
    pkl++ : p++
    if p>n then
      b+=1 : p=n : e=b+n-1
    end if
    '
    ''INSERT BELOW PKL
    for i=en to pkl step -1: s[i+1]=s[i] : next
    en++ 'incr last line
  elseif a=8 and pkl>1
    pkl--  : p--
    if p<1 then b-=1 : p=1 : e=b+n-1
    q=len s[pkl]+1
    inputs=s[pkl]+inputs
    for i=pkl+1 to <en : s[i]=s[i+1] : next
    en-=1
  elseif a=46 and pkl<en
    inputs+=s[pkl+1]
    for i=pkl+1 to <en : s[i]=s[i+1] : next
    en-=1
  end if
  picked=p+q*0x100+m
  if a then pickex=picked
  s[pkl]=inputs
  lastkey=0
  lastchar=0
  pks=pkl
  end scope
  end macro
  '
  '
  macro DelLines()
  ================
  en-=c
  k=i+c
  for j=i to en
    s[j]=s[k]
    k++
  next
  end macro
  '
  macro CopyLines()
  =================
  k=i
  for j=1 to c
    cut[j]=s[k]
    k++
  next
  cutn=c
  end macro
  '
  macro CutLines()
  ================
  CopyLines
  DelLines
  end macro
  '
  macro InsLines()
  ================
  k=en+cutn
  for j=en to i step-1
    s[k]=s[j]
    k--
  next
  en+=cutn
  k=i
  for j=1 to cutn
    s[k]=cut[j]
    k++
  next
  end macro
  '
  macro SelectUsingKeys(a,b,e,en,n)
  =================================
  scope
  'A  ACTIVE STEP
  'B  START OF BLOCK
  'E  END OF BLOCK
  'EN END OF DATA
  'N  WINDOW SIZE
  int c,i,j,k,m,p,q,r
  m=picked and 0xff0000 'group object
  p=picked and 0x0000ff 'line
  q=picked and 0x00ff00 'character
  r=pickex and 0x0000ff 'line
  if p>r then
    i=r
    c=p-r+1
  elseif p<r
    i=p
    c=r-p+1
  else
    i=p
    c=1
  end if
  if key[VK_CONTROL]
    select lastkey
    case 0x2E 'del' 46
      DelLines  : a=1
    case 0x43 'C'
      CopyLines : a=1
    case 0x56 'V'
      InsLines  : a=1
    case 0x58 'X'
      CutLines  : a=1
    case 33
      a=en : b=1      : i=1 'ctrl-pgup
    case 34
      a=en : b=en+1-n : i=n 'ctrl-pgdn
    end select
  else
    select lastkey
    case  9  : a=9
    case 33  : a=-n : if b+a>=1  then b+=a 'pgup
    case 34  : a=n  : if b+a<=en then b+=a 'pgdn
    case 38  : ' up
      a=-1
      if i+b+a>=1
        if i>1
          i+=a
        else
          if b>1
            b+=a
          end if
        end if
      end if
    case 40  : 'down
      a=1
      if i+b+a-1<=en
        if i+a<=n
          i+=a
        else
          b+=a
        end if
      end if
    end select
  end if
  if a then
    picked=m+q+i
    pickex=picked
    lastkey=0
    lastchar=0
    pks=0
    e=b+n-1
  end if
  end scope
  end macro


  function main()
  ===============
  int i,p
  static string fi,t
  static string s[1000]
  static int en
  static int a,le,pks,pkl,pke,pickex
  int sv,ev
  '
  'FILL DATA
  if opening
    static int n=20,b=1,e=n,j=0 
    fi="ScrollEdit1.o2bas"
    t=getfile fi
    le=len t
    '
    'SPLIT INTO LINES
    en=0 : a=0 : b=1
    do
      a=instr b,t,cr
      if a=0 then
        a=le+1
        if a>b then
          en++ : s[en]=mid t,b,a-b 'FINAL
        end if
        exit do
      end if
      en++ : s[en]=mid t,b,a-b
      b=a+2
    end do
    b=1
    picked=1
    pickex=1
  end if
  float  a
  cls 0,0.2,0.2
  picksetup
  '
  'ARROW KEYS ETC FOR SCROLLING LISTS
  '
  j=picked and 0xff
  if j>0 and j<=n
    SelectUsingKeys sv,b,e,en,n
    pkl=b+j-1
  end if
  '
  j=pickex and 0xff
  pke=b+j-1
  '
  pushstate 'main
  scale 1.25,1
  printl "File: " fi
  scale .8,1
  printl
  picktext=0x1000
  for i=b to e
    picktext+=0x100
    if i>en
      printl
    else
      PushState
        color .99,.00,.00
        print i
      PopState
      a=0.2
      move 3 'margin
      PushState
      if i>=pkl and i<=pke then a=1
      if i>=pke and i<=pkl then a=1
      if pkl=i 'mouse picker
        'EDIT IN LINE
        color .80,.80,.00,.88
        '
        --------------------------
        LineEdit ev,s,pkl,b,e,en,n
        --------------------------
        '
      else
        print s[i]
      end if
      PopState
      move -3,-1 'cr lf
      PushState
        Color .10,.10,.70, a
        move -0.5,0.9,-0.001
        PutBoxArea 20,1 'line bar
      PopState
      PickLabel 0
    end if
  next
  picklabel 0
  '
  '
  popstate 'main
  '
  '=======
  'F1 HELP
  '=======
  '
  if key[0x70]
    pushstate
    move 20,0
    color .8,.5
    scale  1.5,1.0
    printl "Active Keys:"
    printl
    scale  1/1.5,1.0
    printl "Left Right Up Down"
    printl "Home End PgUp PgDn"
   'printl "Space"
   'printl "Tab"
    printl "Enter"
    printl "Esc"    tab "Exit"
    printl "Ctrl-P" tab "Take snapshot"
    printl "F1 This help panel"
    printl
    scale 1.5,1.0
    printl "Mouse:"
    scale 1/1.5,1.0
    printl "Left Click to Select"
    popstate
  end if
  '
  lastkey=0
  lastchar=0
  '
  end function

  EndScript
