home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rox.zip / cmdline.rox < prev    next >
Text File  |  1994-04-08  |  6KB  |  224 lines

  1. :class CmdLine
  2.  
  3. :*--------------------------------------------------------------------
  4. :*
  5. :*--------------------------------------------------------------------
  6. :method init
  7.  
  8.    prevLine.0 = 0
  9.  
  10.    key._1B   = "esc"
  11.    key._08   = "backsp"
  12.    key._09   = "tab"
  13.    key._0D   = "enter"
  14.    key._003B = "f1"
  15.    key._003C = "f2"
  16.    key._003D = "f3"
  17.    key._003E = "f4"
  18.    key._003F = "f5"
  19.    key._0040 = "f6"
  20.    key._0041 = "f7"
  21.    key._0042 = "f8"
  22.    key._0043 = "f9"
  23.    key._0044 = "f10"
  24.    key._0085 = "f11"
  25.    key._0086 = "f12"
  26.    key._E048 = "cup"
  27.    key._E050 = "cdown"
  28.    key._E04B = "cleft"
  29.    key._E04D = "cright"
  30.    key._E047 = "home"
  31.    key._E04F = "end"
  32.    key._E049 = "pageup"
  33.    key._E051 = "pagedown"
  34.    key._E052 = "ins"
  35.    key._E053 = "del"
  36.  
  37.    rc = RoxAddVar(self,"prevline.0")
  38.    rc = RoxAddVar(self,"key._1B")
  39.    rc = RoxAddVar(self,"key._08")
  40.    rc = RoxAddVar(self,"key._09")
  41.    rc = RoxAddVar(self,"key._0D")
  42.    rc = RoxAddVar(self,"key._003B")
  43.    rc = RoxAddVar(self,"key._003C")
  44.    rc = RoxAddVar(self,"key._003D")
  45.    rc = RoxAddVar(self,"key._003E")
  46.    rc = RoxAddVar(self,"key._003F")
  47.    rc = RoxAddVar(self,"key._0040")
  48.    rc = RoxAddVar(self,"key._0041")
  49.    rc = RoxAddVar(self,"key._0042")
  50.    rc = RoxAddVar(self,"key._0043")
  51.    rc = RoxAddVar(self,"key._0044")
  52.    rc = RoxAddVar(self,"key._0085")
  53.    rc = RoxAddVar(self,"key._0086")
  54.    rc = RoxAddVar(self,"key._E048")
  55.    rc = RoxAddVar(self,"key._E050")
  56.    rc = RoxAddVar(self,"key._E04B")
  57.    rc = RoxAddVar(self,"key._E04D")
  58.    rc = RoxAddVar(self,"key._E047")
  59.    rc = RoxAddVar(self,"key._E04F")
  60.    rc = RoxAddVar(self,"key._E049")
  61.    rc = RoxAddVar(self,"key._E051")
  62.    rc = RoxAddVar(self,"key._E052")
  63.    rc = RoxAddVar(self,"key._E053")
  64.  
  65. :*--------------------------------------------------------------------
  66. :*
  67. :*--------------------------------------------------------------------
  68. :method getLine
  69.  
  70.    parse value SysCurPos() with origRow origCol .
  71.  
  72.    line = ""
  73.    currRow = origRow
  74.    currCol = origCol
  75.    currOfs = 0
  76.    toFill  = 78 - origCol
  77.    insert  = 0
  78.  
  79.    currLine = prevLine.0
  80.    firstCup = 1
  81.  
  82.    key = ""
  83.    do while (key <> "enter")
  84.       lastKey = key
  85.       key     = getKey()
  86.  
  87.       select
  88.          when (key = "ins") then
  89.             do
  90.             if (insert = 1) then
  91.                insert = 0
  92.             else
  93.                insert = 1
  94.  
  95.             iterate
  96.             end
  97.  
  98.          when (key = "enter") then
  99.             nop
  100.  
  101.          when (key = "cup") | (key = "cdown") then
  102.             do
  103.             if (prevLine.0 = 0) then
  104.                iterate
  105.  
  106.             if (key = "cup") then
  107.                do
  108.                if (firstCup) then
  109.                   firstCup = 0
  110.                else
  111.                   currLine = currLine - 1
  112.                end
  113.             else
  114.                currLine = currLine + 1
  115.  
  116.             if (currLine <= 0) then
  117.                currLine = prevLine.0
  118.  
  119.             if (currLine > prevLine.0) then
  120.                currLine = 1
  121.  
  122.             line = prevLine.currLine
  123.             currOfs = length(line)
  124.             end
  125.  
  126.          when (key = "del") then
  127.             line = delstr(line,currOfs+1,1)
  128.  
  129.          when (key = "cright") then
  130.             do
  131.             if (currOfs < length(line)) then
  132.                currOfs = currOfs + 1
  133.             end
  134.  
  135.          when (key = "cleft") then
  136.             do
  137.             if (currOfs > 0) then
  138.                currOfs = currOfs - 1
  139.             end
  140.  
  141.          when (key = "home") then
  142.             currOfs = 0
  143.  
  144.          when (key = "end") then
  145.             currOfs = length(line)
  146.  
  147.          when (key = "esc") then
  148.             do
  149.             line    = ""
  150.             currOfs = 0
  151.             end
  152.  
  153.          when (key = "backsp") then
  154.             do
  155.             if (currOfs <= 0) then
  156.                iterate
  157.             line = delstr(line,currOfs,1)
  158.             currOfs = currOfs - 1
  159.             end
  160.  
  161.          otherwise
  162.             if (length(key) > 1) then
  163.                iterate
  164.  
  165.             if (insert) then
  166.                line = insert(key,line,currOfs)
  167.             else
  168.                line = overlay(key,line,currOfs+1)
  169.  
  170.             currOfs = currOfs + 1
  171.       end
  172.  
  173.       rc = SysCurPos(origRow,origCol)
  174.       rc = charout("STDOUT:",left(line,toFill))
  175.       rc = SysCurPos(origRow,origCol + currOfs)
  176.    end
  177.  
  178.    if (line <> "") & (lastKey <> "cup") & (lastKey <> "cdown") then
  179.       do
  180.       o = prevLine.0 + 1
  181.       prevLine.0 = o
  182.       prevLine.o = line
  183.       rc = RoxAddVar(self,"prevLine."o)
  184.       end
  185.  
  186.    return line
  187.  
  188. /*------------------------------------------------------------------
  189.  * get key
  190.  *------------------------------------------------------------------*/
  191. getKey: procedure expose key.
  192.  
  193.    /*------------------------------------------------------------------
  194.     * get first key
  195.     *------------------------------------------------------------------*/
  196.    call on halt  name ignore
  197.  
  198.    key  = SysGetKey("NOECHO")
  199.    ckey = c2x(key)
  200.  
  201.    /*------------------------------------------------------------------
  202.     * get second 'key' if needed
  203.     *------------------------------------------------------------------*/
  204.    if (ckey = "E0") | (ckey = "00") then
  205.       ckey = ckey || c2x(SysGetKey("NOECHO"))
  206.  
  207.    /*------------------------------------------------------------------
  208.     * look it up
  209.     *------------------------------------------------------------------*/
  210.    ckey = "_"ckey
  211.    name = key.ckey
  212.  
  213.    if (symbol("key."ckey) = "LIT") then
  214.       return key
  215.    else
  216.       return key.ckey
  217.  
  218. /*------------------------------------------------------------------
  219.  * handle break
  220.  *------------------------------------------------------------------*/
  221. ignore:
  222.    return ""
  223.  
  224.