2 First Step: Hello, TUI🔗ℹ

#lang racket
 
(require tui)
 
(define (wait-for-escape)
  (let loop ()
    (define ev (read-event))
    (unless (and (key-event? ev)
                 (eqv? (key-event-key ev) 'escape))
      (loop))))
 
(with-tui
 (λ ()
   (cursor-hide)
   (screen-clear)
   (put-at 3 5 "Hello, TUI!")
   (put-rgb-fg-at 5 5 255 128 0 "A terminal UI in Racket.")
   (put-at 7 5 "Press Esc to quit.")
   (wait-for-escape)))

Key points:

  • with-tui enters and leaves TUI mode, restoring the terminal on exit.

  • cursor-hide hides the cursor; screen-clear clears the screen.

  • put-at writes text at (row col). Coordinates start at 1; the top-left cell is (1 1).

  • put-rgb-fg-at writes colored text at a position. Most color functions have -at and -at! variants.

  • wait-for-escape waits for Esc with read-event; Input introduces input properly.

Do not quit with exit; it skips cleanup. Use with-tui and an event loop, or the small waiting loop above.