Commit55b61c9bRecorded26 Feb 2026Repositorysigil-tui

Add sigil-tui package skeleton and terminal control layer

Message

Creates (sigil tui terminal) module with with-terminal, alternate screen, mouse tracking, and terminal size convenience wrappers. Adds package to workspace with sigil-stdlib, sigil-ansi, sigil-socket dependencies.

Changed
 package.sgl                | 17 +++++++++++++++++
 src/sigil/tui/terminal.sgl | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
Diff
package.sgladded
@@ -0,0 +1,17 @@
+1
;;; sigil-tui - Terminal UI toolkit
+2
;;;
+3
;;; Immediate-mode terminal UI with grid-based rendering, input parsing,
+4
;;; layout, and components for building interactive terminal applications.
+5
+6
(package
+7
name: "sigil-tui"
+8
version: "0.7.0"
+9
description: "Terminal UI toolkit for Sigil"
+10
url: "https://codeberg.org/sigil/sigil"
+11
license: "BSD-3-Clause"
+12
authors: (list "David Wilson <[email protected]>")
+13
+14
dependencies: (list
+15
(from-workspace name: "sigil-stdlib")
+16
(from-workspace name: "sigil-ansi")
+17
(from-workspace name: "sigil-socket")))
src/sigil/tui/terminal.sgladded
@@ -0,0 +1,87 @@
+1
;;; (sigil tui terminal) - Terminal control layer
+2
;;;
+3
;;; Wraps native terminal primitives with Scheme-level conveniences
+4
;;; for raw mode, alternate screen, mouse tracking, and terminal queries.
+5
+6
(define-library (sigil tui terminal)
+7
(import (sigil core)
+8
(sigil terminal))
+9
+10
(export with-terminal
+11
alternate-screen-on
+12
alternate-screen-off
+13
enable-mouse-tracking
+14
disable-mouse-tracking
+15
terminal-columns
+16
terminal-rows)
+17
+18
(begin
+19
+20
;; ============================================================
+21
;; Escape sequences
+22
;; ============================================================
+23
+24
(define esc "\x1b;")
+25
+26
;;; Switch to the alternate screen buffer.
+27
(define (alternate-screen-on)
+28
(: -> void?)
+29
(terminal-write-raw (string-append esc "[?1049h")))
+30
+31
;;; Switch back to the normal screen buffer.
+32
(define (alternate-screen-off)
+33
(: -> void?)
+34
(terminal-write-raw (string-append esc "[?1049l")))
+35
+36
;;; Enable SGR extended mouse tracking.
+37
(define (enable-mouse-tracking)
+38
(: -> void?)
+39
;; 1000 = basic mouse, 1006 = SGR extended format
+40
(terminal-write-raw (string-append esc "[?1000h" esc "[?1006h")))
+41
+42
;;; Disable mouse tracking.
+43
(define (disable-mouse-tracking)
+44
(: -> void?)
+45
(terminal-write-raw (string-append esc "[?1006l" esc "[?1000l")))
+46
+47
;;; Get the number of terminal columns.
+48
(define (terminal-columns)
+49
(: -> integer?)
+50
(car (terminal-size)))
+51
+52
;;; Get the number of terminal rows.
+53
(define (terminal-rows)
+54
(: -> integer?)
+55
(cdr (terminal-size)))
+56
+57
;; ============================================================
+58
;; Terminal session management
+59
;; ============================================================
+60
+61
;;; Run a thunk with the terminal in raw mode and alternate screen.
+62
;;;
+63
;;; Sets up raw mode, alternate screen, and hidden cursor on entry.
+64
;;; Restores everything on exit (normal or exception).
+65
;;;
+66
;;; ```scheme
+67
;;; (with-terminal
+68
;;; (lambda ()
+69
;;; ;; Terminal is in raw mode, alternate screen active
+70
;;; (terminal-write-raw "Hello from raw mode!")
+71
;;; (let loop ()
+72
;;; (let ((input (terminal-read-raw 64)))
+73
;;; (when input (loop))))))
+74
;;; ```
+75
(define (with-terminal thunk)
+76
(: procedure? -> any?)
+77
(dynamic-wind
+78
(lambda ()
+79
(terminal-raw-mode! #t)
+80
(alternate-screen-on)
+81
(terminal-write-raw (string-append esc "[?25l"))) ;; hide cursor
+82
thunk
+83
(lambda ()
+84
(disable-mouse-tracking)
+85
(terminal-write-raw (string-append esc "[?25h")) ;; show cursor
+86
(alternate-screen-off)
+87
(terminal-raw-mode! #f))))))