Moontalk server and client (provided by many parties)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.3KB

  1. require util.4th
  2. require logger.4th
  3. \ The standard output will only be redirected in application code,
  4. \ not globally in gforth.
  5. \ We always log to a file but we have an optional hook.
  6. true variable! (stdout)
  7. true variable! (stdout-logger)
  8. true variable! (stdout-hook)
  9. : oldtype type ;
  10. : oldemit emit ;
  11. defer (emit)
  12. defer (type)
  13. : type ( str -- )
  14. (stdout) @ IF 2dup oldtype THEN
  15. (stdout-logger) @ IF 2dup logger.log THEN
  16. (stdout-hook) @ IF 2dup (type) THEN
  17. 2drop ;
  18. create (emit-buffer) 1 chars allot
  19. : emit ( c -- )
  20. (emit-buffer) c! (emit-buffer) 1 chars type ;
  21. : ." ( "str" -- )
  22. [char] " parse
  23. state @ IF
  24. ]] sliteral type [[
  25. ELSE
  26. type
  27. THEN ; immediate
  28. : space ( -- ) bl emit ;
  29. : cr ( -- ) 10 emit ;
  30. : . ( n -- )
  31. to-string type bl emit ;
  32. : .s ( -- )
  33. ." < " depth . ." > "
  34. depth 0> IF
  35. depth 0
  36. BEGIN 2dup > WHILE 1+ rot >r REPEAT
  37. drop 0
  38. BEGIN 2dup > WHILE 1+ r> dup . -rot REPEAT
  39. 2drop
  40. THEN ;
  41. : stdout ( flag -- ) (stdout) ! ;
  42. : stdout-logger ( flag -- ) (stdout-logger) ! ;
  43. : stdout-hook ( flag -- ) (stdout-hook) ! ;
  44. : stdout-hook-reset ( -- )
  45. ['] drop IS (emit)
  46. ['] 2drop is (type) ;
  47. : stdout-hook-emit ( xt -- )
  48. \ xt ( c -- )
  49. is (emit) ;
  50. : stdout-hook-type ( xt -- )
  51. \ xt ( str -- )
  52. is (type) ;
  53. stdout-hook-reset