PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/fth/termio.fth

https://github.com/cataska/pforth
Forth | 88 lines | 74 code | 14 blank | 0 comment | 2 complexity | 09529f50b8e0fd875238ab7a35abed24 MD5 | raw file
  1. \ Terminal I/O
  2. \
  3. \ Requires an ANSI compatible terminal.
  4. \
  5. \ To get Windows computers to use ANSI mode in their DOS windows,
  6. \ Add this line to "C:\CONFIG.SYS" then reboot.
  7. \
  8. \ device=c:\windows\command\ansi.sys
  9. \
  10. \ Author: Phil Burk
  11. \ Copyright 1988 Phil Burk
  12. \ Revised 2001 for pForth
  13. ANEW TASK-TERMIO.FTH
  14. decimal
  15. $ 08 constant ASCII_BACKSPACE
  16. $ 7F constant ASCII_DELETE
  17. $ 1B constant ASCII_ESCAPE
  18. $ 01 constant ASCII_CTRL_A
  19. $ 05 constant ASCII_CTRL_E
  20. $ 18 constant ASCII_CTRL_X
  21. \ ANSI Terminal Control
  22. : ESC[ ( send ESCAPE and [ )
  23. ASCII_ESCAPE emit
  24. ascii [ emit
  25. ;
  26. : CLS ( -- , clear screen )
  27. ESC[ ." 2J"
  28. ;
  29. : TIO.BACKWARDS ( n -- , move cursor backwards )
  30. ESC[
  31. base @ >r decimal
  32. 0 .r
  33. r> base !
  34. ascii D emit
  35. ;
  36. : TIO.FORWARDS ( n -- , move cursor forwards )
  37. ESC[
  38. base @ >r decimal
  39. 0 .r
  40. r> base !
  41. ascii C emit
  42. ;
  43. : TIO.ERASE.EOL ( -- , erase to the end of the line )
  44. ESC[
  45. ascii K emit
  46. ;
  47. : BELL ( -- , ring the terminal bell )
  48. 7 emit
  49. ;
  50. : BACKSPACE ( -- , backspace action )
  51. 8 emit space 8 emit
  52. ;
  53. 0 [IF] \ for testing
  54. : SHOWKEYS ( -- , show keys pressed in hex )
  55. BEGIN
  56. key
  57. dup .
  58. ." , $ " dup .hex cr
  59. ascii q =
  60. UNTIL
  61. ;
  62. : AZ ascii z 1+ ascii a DO i emit LOOP ;
  63. : TEST.BACK1
  64. AZ 5 tio.backwards
  65. 1000 msec
  66. tio.erase.eol
  67. ;
  68. : TEST.BACK2
  69. AZ 10 tio.backwards
  70. 1000 msec
  71. ." 12345"
  72. 1000 msec
  73. ;
  74. [THEN]