1   module MGRlib 
    2 
    3 
    4 
    5 
    6 
    7                 (setTextRegion, textReset, clear, clearEvent, func, 
    8                  line, setCursor, setEvent, setMode, shapeWindow,
    9                  stringTo, printOver, movePrintTo,writeVert) 
   10 
   11   where
   12 
   13 
   14 
   15 
   16   command :: String -> [Int] -> String
   17   command str ns = ('\ESC':foldr f "" ns)
   18                 where f n "" = show n ++ str
   19                       f n s  = show n ++ "," ++ s
   20 
   21 
   22 
   23 
   24 
   25   setTextRegion :: [Int] -> String
   26   setTextRegion = command "t" 
   27 
   28 
   29 
   30   textReset :: String
   31   textReset = ('\ESC':"t")
   32 
   33 
   34 
   35 
   36   clear :: String
   37   clear = "\^L"
   38 
   39 
   40 
   41 
   42   clearEvent event = command "e" [mapEvent event]
   43 
   44 
   45 
   46 
   47 
   48   mapEvent event = if ((event == 3) || (event == 4)) then (2-event) else event
   49 
   50 
   51 
   52 
   53 
   54 
   55 
   56 
   57   func :: Int -> String
   58   func mode = command "b" [mode]
   59 
   60 
   61 
   62 
   63   line :: [Int] -> String
   64   line = command "l"   -- x0 y0 x1 y1
   65 
   66 
   67 
   68 
   69 
   70 
   71   setCursor n = command "h" [n]
   72 
   73 
   74 
   75 
   76 
   77   setEvent event str = command ("e"++str) [mapEvent event, length str]
   78 
   79 
   80 
   81 
   82 
   83 
   84 
   85 
   86   setMode mode = command "S" [mode]
   87 
   88 
   89 
   90 
   91   shapeWindow :: [Int] -> String
   92   shapeWindow = command "W" -- x y w h
   93 
   94 
   95 
   96 
   97   stringTo :: Int -> Int -> Int -> String -> String
   98   stringTo win x y str = command ("."++str) [win,x,y,length str]
   99 
  100 
  101 
  102 
  103   printOver :: Int -> Int -> String -> String
  104   printOver w h str = concat [func 0, stringTo 0 w h (take (length str) spaces),func 4,stringTo 0 w h str,func 15]
  105                 where
  106                 spaces = ' ':spaces
  107 
  108 
  109 
  110   movePrintTo :: Int -> Int -> String -> String
  111   movePrintTo w h str = concat [func 4, stringTo 0 w h str, func 15]
  112 
  113 
  114 
  115   writeVert :: (Int,Int) -> [String] -> String
  116   writeVert (x,y) [] = []
  117   writeVert (x,y) (a:l) = printOver x y a ++ writeVert (x,(y+11)) l