Commit Graph

35 Commits

Author SHA1 Message Date
11a70956a0 fix: use ioctl on fd 0 (stdin) as primary sizing method
The parent's fd 0 IS the real terminal when running from a shell.
This directly queries the terminal size without subprocess or
alien complexity. Added proper when guard on the unix-ioctl result.
2026-05-14 14:48:54 -04:00
9a54b7ade6 fix: check unix-ioctl return value before reading winsize
unix-ioctl returns NIL on failure, but the code still reads the
uninitialized alien winsize buffer, getting garbage values for
cols and rows (often 0 for rows). Now checks 'ok' before reading.
2026-05-14 14:47:43 -04:00
aa73171c30 fix: use :input :interactive for stty size subprocess
:input :interactive opens /dev/tty for the child's stdin, giving
stty access to the real terminal for its ioctl query.
2026-05-14 14:44:15 -04:00
eedf065e6e fix: use :input :inherit for stty size subprocess
:input :inherit preserves the parent's fd 0 (the terminal) in the
child process, so stty can query it via ioctl. Previous approaches
(:input :interactive, /dev/tty) all failed because uiop's process
setup redirects stdin away from the terminal.
2026-05-14 14:41:45 -04:00
21c7b1c2d9 fix: replace stty size with tput cols/lines in backend-size
stty size returns incomplete data when run through uiop:run-program
(the child may not have terminal access). tput is a terminfo utility
that outputs a single number per call, avoiding parsing issues.
Works reliably in any subprocess context.
2026-05-14 14:40:11 -04:00
733ba7c1b8 fix: remove :input :interactive from stty size subprocess
:input :interactive causes uiop to block on /dev/tty in the parent.
stty size queries terminal via ioctl, not stdin — no input
redirection needed.
2026-05-14 14:30:17 -04:00
31f864471c fix: use :input :interactive for stty size subprocess
SBCL's stdin during --load is the load file, NOT the terminal.
When uiop:run-program creates a subprocess, it inherits this
stdin, so 'stty size' reads from the load file and fails.
:input :interactive opens /dev/tty for the child's stdin,
matching the behavior of 'stty size' from an interactive shell.
2026-05-14 14:24:55 -04:00
4b1ff3ed0f fix: move stty size to first priority in backend-size
stty size via subprocess is the most reliable method — it
returns the correct 59x83 from the user's terminal. Move it
before ioctl to ensure it's tried first.
2026-05-14 14:22:27 -04:00
fe301dc25b fix: run stty size via 'sh -c' with /dev/tty redirection
uiop:run-program may redirect the child's stdin, preventing stty
from querying the terminal. 'stty size < /dev/tty' explicitly
reads from the controlling terminal regardless of stdin setup.
2026-05-14 14:20:22 -04:00
4df3048a13 fix: add stty size subprocess fallback in both backends
stty size via uiop:run-program is the most reliable method —
it works from the shell on every Unix system and bypasses
alien/ioctl quirks. Placed between stdout ioctl and /dev/tty
ioctl in the fallback chain.
2026-05-14 14:15:30 -04:00
41e2b867be fix: use O_RDONLY (0) for /dev/tty open, guard invalid fd 2026-05-14 14:10:58 -04:00
a227a52c48 fix: use raw O_RDWR=2 constant (sb-unix:o-rdwr doesn't exist) 2026-05-14 13:57:03 -04:00
37f83db35e fix: replace stty/tput fallback with direct ioctl on /dev/tty
uiop:run-program can inherit different terminal state than the
interactive shell. Opening /dev/tty directly and calling ioctl
on that fd is equivalent to what the shell's stty does, and
works regardless of SBCL's fd inheritance quirks.
2026-05-14 13:56:16 -04:00
9b472e281f fix: remove env var fallback for COLUMNS/LINES (SBCL strips them)
SBCL unconditionally strips COLUMNS and LINES from the environment,
so posix-getenv always returns nil for those names. stty size is
the reliable cross-platform fallback for terminal dimensions.
2026-05-14 13:46:13 -04:00
4fa7e98b80 fix: set both dimensions from stty, add tput fallback, export shell vars
- stty size returns 'rows cols'. Old code set only one dimension
  when both env vars were missing; new code sets both.
- Added tput cols/lines as final env-var fallback for systems
  where COLUMNS/LINES are not exported and stty is unavailable.
- Added 'export COLUMNS LINES' to the passepartout script so
  SBCL can read them from the environment.
2026-05-14 13:36:54 -04:00
5e9a974981 fix: fill missing env dimension from stty size
When only COLUMNS or only LINES is set, run 'stty size' to get the
other dimension. This handles tmux/screen where only one env var
is exported.
2026-05-14 13:14:22 -04:00
4b9482c09a fix: add env var fallback to backend-size in both backends
ioctl on stdout's fd can return 80x24 even when the terminal is
larger. Add COLUMNS/LINES from the shell as a fallback. Also adds
ioctl-based sizing to simple-backend (was hardcoded 80x24).
2026-05-14 13:12:49 -04:00
83a6e87720 fix: simplify backend-size with direct when guard on values
The try-ioctl function returns (values cols rows) only when both
are valid integers > 0. or propagates complete pairs. This avoids
the nil-in-h crash from partial ioctl results.
2026-05-14 13:11:16 -04:00
db07f8c3a7 fix: guard ioctl results with when to avoid partial values
ignore-errors + ioctl can return (values 80 nil) when the fd exists
but isn't a terminal. or propagates partial values, causing nil in
w or h. Wrap with multiple-value-bind + when to filter.
2026-05-14 13:07:55 -04:00
4a86ae3274 fix: ioctl on stdin fd (0) first, then stdout fd, then env vars
The user's terminal reports 186x60 via stty (which uses stdin fd)
and via COLUMNS/LINES, but ioctl on stdout's fd returns 80x24.
Priority: fd 0 → backend output fd → env vars → 80x24 fallback.
2026-05-14 13:07:05 -04:00
7813e27907 fix: revert to simple ioctl-first with env var fallback
The previous logic (check ioctl result, prefer env when 80x24)
added complexity and crashes. Simple or with env vars after ioctl
is safe: ioctl returns 80x24 on stdout fd mismatch, env vars
(COLUMNS/LINES from shell) provide the correct initial size.
2026-05-14 13:05:53 -04:00
abe4edaffc fix: fallback to stty size when LINES env var is missing
Some environments (tmux) export COLUMNS but not LINES. Use
'stty size' as a fallback for the missing dimension.
2026-05-14 13:04:57 -04:00
1ac6ca02ee fix: handle nil env vars in backend-size
parse-integer errors on nil input. Guard with when before parsing.
2026-05-14 13:03:42 -04:00
0e0151664e fix: prefer env vars over ioctl when ioctl returns 80x24
ioctl on stdout's fd can return the default 80x24 even when the
terminal is much larger (fd mismatch). The new logic:

1. Try ioctl — if it returns >80x24, trust it (correct at runtime).
2. If ioctl returned 80x24 (suspicious default), try COLUMNS/LINES
   from the shell environment instead.
3. If both fail, return whatever ioctl gave us (80x24).

This fixes initial sizing on terminals where ioctl disagrees with
the real TTY size, without breaking runtime SIGWINCH resize
(which always re-queries ioctl, and that is correct after resize).
2026-05-14 13:02:09 -04:00
5c8a253171 fix: add / env var fallback in backend-size
ioctl on stdout's fd can disagree with the real terminal size when
the process is started with stdout redirected or in some terminal
multiplexer configurations. / are set by every POSIX
shell at process start and reflect the actual terminal dimensions.

Priority: ioctl → env vars → 80x24 fallback.
This covers both initial sizing and dynamic SIGWINCH-driven resize.
2026-05-14 12:57:01 -04:00
7cdb556531 fix: remove %query-terminal-size completely
The CSI 18t query leaks into the threaded keyboard reader because
the response arrives on stdin after the reader thread starts. The
response bytes get queued as key events and inserted as text into
the TUI input buffer. Removing the query entirely — ioctl is
sufficient for terminal size detection on all modern terminals.
2026-05-14 11:22:12 -04:00
5a3b882f93 fix: add blocking-read-based CSI 18t terminal size query fallback
%query-terminal-size uses blocking read-char on an fd 0 stream
to read the terminal's response to \033[18t. This works even when
unix-simple-poll on fd 0 returns NIL (unlike read-char-no-hang).
Added as fallback in both modern and simple backends.
2026-05-14 10:14:40 -04:00
b80bd77d84 fix: remove CSI 18t terminal query (read-char-no-hang on fd 0 never returns)
The %query-terminal-size function sent \033[18t and tried to read
the response via read-char-no-hang on fd 0, which always returns nil
in this SBCL environment. The response leaked into user input,
displaying garbled CSI sequences. Rely on ioctl only.
2026-05-14 09:32:25 -04:00
14b41831c3 fix: disable kitty keyboard, fix CSI parser crashes
- Disabled \033[?u kitty keyboard protocol in modern-backend
  (converts all keys to escape sequences, breaking Ctrl+letter dispatch)
- Fixed parse-csi-sequence: use multiple-value-bind instead of let*
  with destructuring-bind (lost secondary return value from read-param)
- Fixed parse-csi-params format string: pass char-code of terminator
  as distinct argument for ~d, keeping the character for ~C
- Added %query-terminal-size in classes.lisp: ANSI CSI 18t fallback
  for terminal size detection when ioctl fails or returns zero
2026-05-14 09:31:09 -04:00
22886c1794 fix: add draw-text method for raw 2D arrays
Application code (passepartout TUI) calls draw-text with a framebuffer
(2D array) as the first argument, but draw-text only had methods for
framebuffer-backend CLOS instances. Added a method on array that sets
cells directly on the framebuffer array, matching make-framebuffer's
return type.
2026-05-13 16:06:05 -04:00
Hermes Agent
3cbcfd2d75 v1.0.0 release
Bug fixes:
- Fix OSC8 format strings (backslash escape layering) in modern-backend.org
  - Test format string had single backslash instead of double, causing
    unclosed CL string that cascaded through 3 subsequent test forms
  - Implementation format string had leading escaped quote (not a string
    opener) and triple-backslash ending (also not a string terminator)
- Fix missing closing parens in border-char-rounded and border-char-double tests
- Fix ASDF input-tests pathname (file lives in tests/, not src/components/)

New features:
- Implement suspend-backend / resume-backend protocol methods
  - modern-backend: exit/enter alt screen, re-enable mouse/kitty/bracketed-paste
  - simple-backend: no-ops (no terminal state to preserve)

Infrastructure:
- Update test suite to cover suspend/resume (backend + modern-backend suites)
- 454 checks, 100% pass across 14 test suites
2026-05-12 20:00:27 +00:00
Hermes Agent
352f27e260 fix: osc8-link doubled backslashes in format string
The osc8-link implementation and its test both had doubled
backslashes (\\ -> \\) in their format strings, producing two
literal backslashes at runtime instead of the single backslash
needed for the OSC 8 string terminator (ST = ESC \).

Fix: change \\ to \\ in both the implementation and test format
strings. The tangled .lisp files now have correct escaped
backslashes (\) producing one backslash in the runtime string.

Additionally clean up a patch artifact that left a stray backslash
before the opening quote.
2026-05-12 19:26:00 +00:00
Hermes Agent
29f99a576d literate: restructure all 19 org files with per-function blocks and prose
Every function, defclass, defstruct, defgeneric, defmethod, defmacro,
defvar, and defparameter in every org file now has its own #+BEGIN_SRC
block with literate prose above it explaining the design reasoning.

Block counts before → after:
  package.org:           1 → 7
  container-package.org: 1 → 1 (prose expanded)
  dirty.org:             4 → 6
  render.org:           10 → 25
  theme.org:             6 → 19
  box-renderable.org:    9 → 29
  scrollbox.org:         8 → 26
  tabbar.org:            5 → 10
  backend-protocol.org:  8 → 66
  modern-backend.org:   17 → 53
  detection.org:         4 → 6
  layout-engine.org:     9 → 36
  framebuffer.org:       8 → 37
  markdown-renderer.org:13 → 38
  dialog.org:           17 → 23 (merged dual structure)
  mouse.org:             4 → 25
  select.org:           12 → 30
  slot.org:              4 → 12
  text-input.org:       11 → 53

Total: ~153 blocks → ~502 blocks

Bugs fixed during restructuring:
- render.org: stray π character typo (backenπd → backend)
- modern-backend.org: sgr-attr missing closing paren + #+END_SRC
- detection.org: invalid #\Esc character reference
- select.org: extra closing paren in select-visible-options

All 13 test suites pass at 100%.
2026-05-12 18:55:07 +00:00
Hermes Agent
c77c6b9d02 literate: convert org/modern-backend.org from doc-only to tangle source
Now tangles to modern.lisp + modern-tests.lisp.
Deleted hand-written originals and regenerated from org — GREEN.
2026-05-12 17:14:37 +00:00
Hermes Agent
47094c48e5 restructure: move backend/ and layout/ into src/; convert README to org syntax; fix demo package conflict and alien-sap ioctl; update ROADMAP with v0.15.0; remove stale files
- Move backend/ and layout/ directories into src/
- Update all path references in ASD, scripts, docs
- Convert README.org from Markdown syntax to proper Org-mode
- Fix demo.lisp use-package conflict (both backend and input export #:read-event)
- Fix modern-backend TIOCGWINSZ ioctl alien type (alien-sap wrapper)
- Add v0.15.0 section to ROADMAP, update line count to 5760
- Add known gaps (suspend/resume-backend, slot modes) to v1.0.0 checklist
- Remove docs/plans/, debug-layout.lisp, system-index.txt, ci-watchdog.sh
- Move tangle.py to Hermes skill (org-babel-tangle)
- Add .gitignore for fasl files
2026-05-12 16:57:19 +00:00