Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@gdamore
Copy link
Owner

@gdamore gdamore commented Dec 8, 2025

Summary by CodeRabbit

  • New Features

    • Added VT100-based terminal control for more consistent behavior across terminals.
  • Bug Fixes

    • Switched rendering and input handling to the new VT-driven approach, reducing terminal-specific inconsistencies.
  • Chores

    • Updated copyright year to 2025.
    • Removed the mkinfo build tool and its generated terminal list.
    • Simplified bundled terminal capability data, trimming less-used features for a leaner terminal database.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

This PR removes the mkinfo tool and its data, simplifies the Termcap struct by removing many attribute/cursor/mouse/paste/URL fields, deletes parser paste/rune methods, updates many terminfo initializers, and adds a VT-based escape layer in TtyScreen; manifest years updated to 2025.

Changes

Cohort / File(s) Summary
Root & demo manifests
dub.json, demos/colors/dub.json
Bumped copyright year to 2025; formatting/author array normalized; removed ./mkinfo/ from root subPackages.
Mkinfo tool removal
mkinfo/dub.json, mkinfo/source/mkinfo.d, mkinfo/terms.txt
Deleted mkinfo build manifest, source tool, and terminal list (complete removal of mkinfo utility).
Termcap struct simplification
source/dcell/termcap.d
Removed ~30 Termcap fields (bells, clears, CA, cursor shapes/movements, many text attributes, paste/mouse/URL sequences, automargin); retained color/keypad-related fields.
Parser simplification
source/dcell/parser.d
Removed parsePaste() and parseRune() methods; minor CSI handling reformat; unit-test Termcap literals updated to match smaller Termcap.
Database test update
source/dcell/database.d
Removed mouse-related auto-configuration logic and updated test fixture caps2 to omit mouse field.
TtyScreen → VT layer
source/dcell/ttyscreen.d
Added internal Vt struct of VT100/derived sequences; TtyScreen constructor now TtyScreen(..., string term = ""); replaced many caps.* usages with vt.* equivalents and added legacy-terminal handling.
Terminfo modules cleaned
source/dcell/terminfo/*.d (aixterm, alacritty, ansi, dtterm, gnome, konsole, linux, rxvt, screen, vt100, vt102, vt220, vt320, vt420, xfce, xterm)
Removed identical sets of capability fields from all Termcap initializers (attribute/cursor/mouse/paste/URL/automargin-related entries) to match simplified Termcap.
Terminal I/O adjustments
source/dcell/termio.d
stop() no longer explicitly closes fd (calls ignoreResize(fd) before restore); blocking(bool) removed fcntl F_SETFL path (no longer toggles O_NONBLOCK).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Substantial behavioral changes concentrated in source/dcell/ttyscreen.d (new VT abstraction) warrant careful review.
  • Large, repetitive removals across many terminfo modules require spot-checking for consistency and dangling references.
  • Parser/API surface changes (parser.d, termcap.d) may introduce compilation or runtime incompatibilities; verify tests and consumers.

Files/areas to pay extra attention to:

  • source/dcell/ttyscreen.d — completeness and correctness of vt sequence mappings and legacy handling
  • source/dcell/termcap.d & source/dcell/parser.d — removed fields/methods and downstream references
  • source/dcell/terminfo/* — ensure all removed fields are consistently absent and no code still references them
  • source/dcell/mkinfo deletions — confirm no callers expect generated artifacts

Possibly related PRs

Poem

🐰 The mkinfo tool hopped off in the night,
Termcap fields trimmed, colors kept bright,
A little Vt nest now handles each tone,
Legacy whispers still get their own,
Hooray — the rabbit hops, the dcell burrow's grown.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Terminfo cleanups' directly corresponds to the main changes: removal of unused terminfo fields, deletion of the mkinfo tool, and simplification of termcap structures across multiple terminal definitions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch terminfo-cleanups

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fdb710f and 63a838d.

📒 Files selected for processing (22)
  • demos/colors/dub.json (1 hunks)
  • source/dcell/database.d (1 hunks)
  • source/dcell/parser.d (1 hunks)
  • source/dcell/termcap.d (0 hunks)
  • source/dcell/terminfo/aixterm.d (0 hunks)
  • source/dcell/terminfo/alacritty.d (0 hunks)
  • source/dcell/terminfo/ansi.d (0 hunks)
  • source/dcell/terminfo/dtterm.d (0 hunks)
  • source/dcell/terminfo/gnome.d (0 hunks)
  • source/dcell/terminfo/konsole.d (0 hunks)
  • source/dcell/terminfo/linux.d (0 hunks)
  • source/dcell/terminfo/rxvt.d (0 hunks)
  • source/dcell/terminfo/screen.d (0 hunks)
  • source/dcell/terminfo/vt100.d (0 hunks)
  • source/dcell/terminfo/vt102.d (0 hunks)
  • source/dcell/terminfo/vt220.d (0 hunks)
  • source/dcell/terminfo/vt320.d (0 hunks)
  • source/dcell/terminfo/vt420.d (0 hunks)
  • source/dcell/terminfo/xfce.d (0 hunks)
  • source/dcell/terminfo/xterm.d (0 hunks)
  • source/dcell/termio.d (1 hunks)
  • source/dcell/ttyscreen.d (20 hunks)
💤 Files with no reviewable changes (17)
  • source/dcell/terminfo/linux.d
  • source/dcell/terminfo/vt220.d
  • source/dcell/terminfo/screen.d
  • source/dcell/terminfo/ansi.d
  • source/dcell/terminfo/vt320.d
  • source/dcell/terminfo/vt102.d
  • source/dcell/terminfo/vt100.d
  • source/dcell/terminfo/vt420.d
  • source/dcell/terminfo/xfce.d
  • source/dcell/terminfo/aixterm.d
  • source/dcell/terminfo/xterm.d
  • source/dcell/terminfo/alacritty.d
  • source/dcell/terminfo/konsole.d
  • source/dcell/terminfo/dtterm.d
  • source/dcell/termcap.d
  • source/dcell/terminfo/gnome.d
  • source/dcell/terminfo/rxvt.d
🚧 Files skipped from review as they are similar to previous changes (1)
  • demos/colors/dub.json
🔇 Additional comments (10)
source/dcell/termio.d (3)

117-125: LGTM: Improved cleanup order in stop().

Moving ignoreResize(fd) inside the file-open guard and before flush()/restore() ensures the signal handler is properly cleaned up before terminal state restoration, preventing potential races during shutdown.


144-153: Critical issue from past review is now resolved.

The function correctly honors the b parameter and no longer contains the b = false; assignment that caused the busy-spin issue. The blocking/non-blocking behavior is now properly controlled via termios (VMIN/VTIME), matching the caller's intent.


274-287: Note: Signal handler temporarily modifies terminal state.

The handleSigWinCh handler intentionally sets VMIN=0 and VTIME=1 to wake the input loop, creating a temporary inconsistency between the actual terminal state and the PosixTty.block member variable. After a resize is detected, the caller should restore the desired blocking mode if needed.

This is a common pattern for resize notification, but verify that calling code properly re-establishes blocking state after handling resize events.

source/dcell/database.d (1)

152-152: LGTM - Test updated to reflect Termcap simplification.

The removal of the mouse field from the test Termcap initialization correctly reflects the broader changes in this PR to simplify the Termcap structure.

source/dcell/parser.d (1)

817-830: LGTM - Formatting improvement for paste handling.

The addition of braces around the conditional blocks improves code consistency. The paste handling logic (CSI 200 ~ for paste start, CSI 201 ~ for paste end) remains functionally equivalent.

source/dcell/ttyscreen.d (5)

41-106: LGTM - Well-structured VT escape sequence definitions.

The Vt struct provides a clean separation between fixed VT/ECMA-48 sequences (static enums) and sequences that can be disabled for legacy terminals (mutable strings). The escape sequences appear correct for standard VT100/ANSI terminals.


259-262: LGTM - Simplified mouse support detection.

Returning true unconditionally is appropriate since the implementation relies on the de-facto standard XTerm mouse protocol (as noted in the sendMouseEnable method at line 628-631), which all supported terminals are expected to understand.


150-151: LGTM - Clean VT-based escape sequence refactoring.

The transition from termcap-based sequences to VT-based sequences is well-implemented. The pattern of using Vt. for static/fixed sequences and vt. for instance-modifiable sequences (which can be disabled for legacy terminals) is clear and correct.

Also applies to: 175-184, 297-299, 318-318, 446-458, 467-471, 490-520, 551-571, 601-602, 633-644, 649-650


689-695: LGTM - Improved input loop exit handling.

The explicit check for the stopping signal ensures a clean shutdown path. This enhancement reduces the risk of the input loop hanging during termination.


108-136: The legacy terminal detection logic is appropriately designed.

The code correctly identifies genuinely legacy terminals (VT100-VT420 variants, ANSI, Linux console, Sun terminals) and disables OSC features for them. Modern terminals supported in the codebase (alacritty, konsole, rxvt, screen, xfce, dtterm) are correctly excluded from the legacy list. The approach aligns with the codebase's philosophy that terminals ignore unsupported sequences.


Comment @coderabbitai help to get the list of available commands and usage tips.

This will eliminate more incremental changes going forward.
Setting O_NONBLOCK on the underlying file was causing a file in phobos
when it tries to write out content, as it cannot cope with an incomplete write.

We only care aobut the VMIN/VTIME behavior to control terminal *input*,
and we presume that if VMIN and VTIME are both zero, read will still do
a non-blocking read, regardless of the setting of O_NONBLOCK.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
source/dcell/ttyscreen.d (1)

723-723: Missing term parameter in TtyScreen constructor call.

The term variable is available but not passed to TtyScreen, so legacy terminal detection (lines 120-124) will never trigger. Legacy terminals like vt100, ansi, linux, or sun won't have OSC functions properly disabled.

-    return new TtyScreen(newDevTty(), caps);
+    return new TtyScreen(newDevTty(), caps, term);
🧹 Nitpick comments (1)
source/dcell/ttyscreen.d (1)

667-670: Consider preserving exception details in assertion.

The assert(false) loses the original exception message, making debugging harder. Additionally, in release builds with assertions disabled, this could lead to silent continuation.

             catch (Exception e)
             {
-                assert(false);
+                assert(false, e.msg);
             }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4962b7f and 9bed71a.

📒 Files selected for processing (26)
  • demos/colors/source/colors.d (1 hunks)
  • dub.json (1 hunks)
  • mkinfo/dub.json (0 hunks)
  • mkinfo/source/mkinfo.d (0 hunks)
  • mkinfo/terms.txt (0 hunks)
  • source/dcell/database.d (1 hunks)
  • source/dcell/parser.d (1 hunks)
  • source/dcell/termcap.d (0 hunks)
  • source/dcell/terminfo/aixterm.d (0 hunks)
  • source/dcell/terminfo/alacritty.d (0 hunks)
  • source/dcell/terminfo/ansi.d (0 hunks)
  • source/dcell/terminfo/dtterm.d (0 hunks)
  • source/dcell/terminfo/gnome.d (0 hunks)
  • source/dcell/terminfo/konsole.d (0 hunks)
  • source/dcell/terminfo/linux.d (0 hunks)
  • source/dcell/terminfo/rxvt.d (0 hunks)
  • source/dcell/terminfo/screen.d (0 hunks)
  • source/dcell/terminfo/vt100.d (0 hunks)
  • source/dcell/terminfo/vt102.d (0 hunks)
  • source/dcell/terminfo/vt220.d (0 hunks)
  • source/dcell/terminfo/vt320.d (0 hunks)
  • source/dcell/terminfo/vt420.d (0 hunks)
  • source/dcell/terminfo/xfce.d (0 hunks)
  • source/dcell/terminfo/xterm.d (0 hunks)
  • source/dcell/termio.d (0 hunks)
  • source/dcell/ttyscreen.d (19 hunks)
💤 Files with no reviewable changes (21)
  • mkinfo/terms.txt
  • source/dcell/terminfo/vt100.d
  • source/dcell/terminfo/vt320.d
  • source/dcell/terminfo/ansi.d
  • source/dcell/terminfo/xfce.d
  • source/dcell/terminfo/linux.d
  • source/dcell/terminfo/vt220.d
  • source/dcell/terminfo/vt102.d
  • source/dcell/terminfo/screen.d
  • source/dcell/terminfo/gnome.d
  • source/dcell/terminfo/xterm.d
  • mkinfo/source/mkinfo.d
  • source/dcell/terminfo/dtterm.d
  • source/dcell/terminfo/konsole.d
  • source/dcell/termio.d
  • source/dcell/terminfo/vt420.d
  • source/dcell/terminfo/aixterm.d
  • source/dcell/terminfo/alacritty.d
  • mkinfo/dub.json
  • source/dcell/terminfo/rxvt.d
  • source/dcell/termcap.d
🔇 Additional comments (6)
dub.json (1)

2-11: LGTM!

The manifest changes are consistent with the PR's goal of removing the mkinfo build tool. Copyright year update and subPackages cleanup look correct.

demos/colors/source/colors.d (1)

135-183: LGTM! Improved error handling and event loop structure.

The try/catch pattern ensures s.stop() is called on exceptions, preventing terminal state from being left in raw mode. The timing output is a nice addition for performance insights.

One note: the assert(0, "error received") on line 170 will crash the demo if an error event occurs. This is acceptable for a demo but worth keeping in mind.

source/dcell/database.d (1)

152-152: LGTM!

Test data simplified to align with the Termcap structure changes in this PR.

source/dcell/parser.d (1)

817-830: LGTM!

The reformatting with explicit braces improves readability while preserving the paste handling logic.

source/dcell/ttyscreen.d (2)

41-106: Good centralization of terminal escape sequences.

The Vt struct provides a clean, organized location for terminal control sequences. The mix of enum constants for immutable sequences and regular fields for sequences that may need legacy overrides is a sensible design choice.


108-136: LGTM! Sensible legacy terminal handling.

The legacy detection covers common legacy terminals (vt*, ansi, linux, sun) and appropriately disables unsupported OSC/window management features for them.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
source/dcell/ttyscreen.d (1)

476-483: Add + 1 to convert 0-based Coord to 1-based terminal coordinates in goTo.

The goTo function passes cursor coordinates directly to the VT100 escape sequence setCursorPosition without adjustment:

puts(format!(Vt.setCursorPosition)(pos.y, pos.x));

However, Coord uses 0-based indexing internally:

  • Draw loops iterate from Coord(0, 0): for (pos.y = 0; pos.y < size.y; ...)
  • Mouse coordinates from the terminal are converted to 0-based with - 1 in handleMouse: auto x = p1 - 1; auto y = p2 - 1;

The VT100 escape sequence "\x1b[%d;%dH" requires 1-based coordinates. The fix is:

puts(format!(Vt.setCursorPosition)(pos.y + 1, pos.x + 1));
🧹 Nitpick comments (3)
source/dcell/parser.d (1)

789-831: Bracketed paste handling via CSI 200/201 is consistent and covered by tests.

The new p0 == 200 / p0 == 201 handling correctly:

  • Enters paste mode and clears pasteBuf on start.
  • Accumulates runes only while pasting is true (via postKey).
  • Emits a single paste event with the collected buffer on end, matching the unit test that expects paste.content == "A".

Given the old termcap-driven paste sequences are gone, this VT-based approach is appropriate.

You now have some dead state (pasteTime, pasteStart, pasteEnd) that’s no longer read anywhere; consider removing these fields in a follow-up to keep Parser lean.

source/dcell/ttyscreen.d (2)

143-193: Stop sequence is mostly sound but has minor redundancy and relies on blocking(true) behaving correctly.

The new stop() sequence:

  • Restores auto-margin, colors, SGR state, cursor shape/visibility, and clears the screen using VT sequences.
  • Disables paste, mouse, and focus reporting before flushing.
  • Uses the stopping Turnstile to coordinate with inputLoop, then calls ti.stop() and finally ti.restore().

Two minor points:

  • vt.cursorReset is emitted twice back-to-back; you can drop one of them with no behavioral change.
  • For PosixTty, ti.stop() already calls restore(), and stop() then calls ti.restore() again. This is harmless but redundant.

Once PosixTty.blocking(bool) is fixed to honor its argument again, the blocking(false) / blocking(true) calls here will correctly ensure the reader thread isn’t stuck in a blocking read while you shut it down.


253-263: hasMouse() now unconditionally returns true.

This is a behavior change from termcap-driven capability checks to “assume XTerm-style mouse reporting is available everywhere”. Given the rest of the code hard-codes XTerm mouse enable/disable sequences, this is consistent, but it does mean callers can no longer distinguish terminals that truly don’t support mouse tracking.

If you ever need that distinction again, consider deriving the result from term/legacy or a small allowlist instead of always returning true.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9bed71a and fdb710f.

📒 Files selected for processing (22)
  • demos/colors/dub.json (1 hunks)
  • source/dcell/database.d (1 hunks)
  • source/dcell/parser.d (1 hunks)
  • source/dcell/termcap.d (0 hunks)
  • source/dcell/terminfo/aixterm.d (0 hunks)
  • source/dcell/terminfo/alacritty.d (0 hunks)
  • source/dcell/terminfo/ansi.d (0 hunks)
  • source/dcell/terminfo/dtterm.d (0 hunks)
  • source/dcell/terminfo/gnome.d (0 hunks)
  • source/dcell/terminfo/konsole.d (0 hunks)
  • source/dcell/terminfo/linux.d (0 hunks)
  • source/dcell/terminfo/rxvt.d (0 hunks)
  • source/dcell/terminfo/screen.d (0 hunks)
  • source/dcell/terminfo/vt100.d (0 hunks)
  • source/dcell/terminfo/vt102.d (0 hunks)
  • source/dcell/terminfo/vt220.d (0 hunks)
  • source/dcell/terminfo/vt320.d (0 hunks)
  • source/dcell/terminfo/vt420.d (0 hunks)
  • source/dcell/terminfo/xfce.d (0 hunks)
  • source/dcell/terminfo/xterm.d (0 hunks)
  • source/dcell/termio.d (2 hunks)
  • source/dcell/ttyscreen.d (20 hunks)
💤 Files with no reviewable changes (17)
  • source/dcell/terminfo/vt220.d
  • source/dcell/terminfo/linux.d
  • source/dcell/terminfo/vt102.d
  • source/dcell/terminfo/vt320.d
  • source/dcell/terminfo/vt100.d
  • source/dcell/terminfo/aixterm.d
  • source/dcell/terminfo/ansi.d
  • source/dcell/terminfo/dtterm.d
  • source/dcell/terminfo/vt420.d
  • source/dcell/terminfo/xfce.d
  • source/dcell/terminfo/screen.d
  • source/dcell/terminfo/rxvt.d
  • source/dcell/terminfo/xterm.d
  • source/dcell/terminfo/gnome.d
  • source/dcell/terminfo/alacritty.d
  • source/dcell/termcap.d
  • source/dcell/terminfo/konsole.d
✅ Files skipped from review due to trivial changes (1)
  • demos/colors/dub.json
🔇 Additional comments (10)
source/dcell/termio.d (1)

117-125: Stop now correctly unregisters SIGWINCH before restoring termios.

Calling ignoreResize(fd) inside PosixTty.stop() pairs cleanly with watchResize(fd) in start() and avoids leaving the SIGWINCH handler installed once the TTY is no longer in use. No issues from this change.

source/dcell/database.d (1)

147-186: Simplified caps2 fixture still exercises the truecolor augmentation path correctly.

Dropping the mouse-related field from caps2 while keeping colors: 1 << 24 matches the PR’s capability trimming and remains compatible with the unittest expectations for RGB/color sequences.

source/dcell/ttyscreen.d (8)

41-136: VT escape struct and legacy gating look coherent.

Encapsulating all the VT escape sequences in the nested Vt struct and then selectively blanking out URL/title/window-size OSC codes for obvious legacy terms (vt*, ansi, linux, sun*) gives you a clear separation between “modern VT-like” and “legacy” behavior without complicating the rest of the code. Using instance string fields for the OSC sequences (so they can be set to "" for legacy) and enum string for fixed SGR/DEC private modes is a sensible split.

From a quick scan, all of the hard-coded SGR and DEC private mode values (bold/dim/italic/underline/blink/reverse/strikethrough, cursor show/hide, cursor shapes, alt-screen, paste, focus, auto‑margin) match the usual VT/xterm conventions.


295-305: setSize correctly guards on VT support for window-resize reports.

Conditioning the ESC[8;rows;cols t sequence on vt.setWindowSize != "" ensures you don’t send this on legacy terminals where you’ve deliberately disabled it. Marking all cells dirty and calling resize() afterward is the right thing to do whenever the terminal accepts a size change.


442-459: Attribute rendering via VT SGR codes is straightforward.

Switching sendAttrs to use the VT SGR constants (Vt.bold, Vt.underline, etc.) gets you out of the business of maintaining per-termcap attribute sequences. The mapping from Attr.* bits to SGR 1/2/3/4/5/7/9 looks correct, and terminals that don’t support some of these will simply ignore them.


461-472: Screen clear path is consistent with the new VT abstraction.

On a pending clear you:

  • Reset SGR with vt.sgr0 and end any active URL with vt.exitURL.
  • Reapply the default colors and attributes.
  • Use Vt.clear (home + clear screen) and flush.

This matches the VT-centric design and should leave both the terminal state and your internal style tracking in sync.


528-599: Draw path is consistent with VT usage and legacy URL disabling.

The updated draw() / drawCell() logic:

  • Hides the cursor while drawing (vt.hideCursor), then restores it via sendCursor().
  • Uses goTo for cursor movement when pos != pos_ instead of relying on auto-margin.
  • For monochrome caps, still simulates light/dark via Attr.reverse.
  • Clears c.style.url whenever vt.enterURL == "" so you don’t emit OSC 8 on terminals you’ve marked legacy.
  • Resets attributes with Vt.sgr0 before sending colors/attrs for a new cell.

All of this hangs together with the VT abstraction and your legacy gating.


626-645: Mouse enable/disable sequences hard-code the common XTerm variants.

sendMouseEnable now:

  • Always sends a full disable (?1000l/?1002l/?1003l/?1006l) first.
  • Then enables button, drag, motion, and SGR mouse mode (?1006h) based on the MouseEnable flags.

That’s a reasonable, explicit strategy for the de facto XTerm mouse protocol, especially now that terminfo mouse capabilities have been removed. Just be aware it assumes SGR mouse (1006) rather than older encodings; if you ever need to support those again, you’ll need additional toggles here.


647-651: Paste enable/disable correctly matches parser’s bracketed-paste handling.

Using Vt.enablePaste / Vt.disablePaste (CSI ? 2004 h/l) here lines up with the parser’s CSI 200/201 handling and the unit test that injects those sequences. That keeps the send/receive paths consistent without relying on termcap data.


653-705: New stopping handshake gives inputLoop a clean shutdown path.

The added block:

if (stopping.get())
{
    stopping.set(false);
    return;
}

combined with TtyScreen.stop() calling stopping.set(true) and then stopping.wait(false) provides a simple, explicit handshake to exit the inputLoop without resorting to out-of-band thread termination.

Once PosixTty.blocking(true/false) is fixed to behave as intended, the loop will again switch between blocking and non‑blocking reads based on parser state, and this stop signaling should remain reliable.

Comment on lines 144 to 153
void blocking(bool b) @trusted
{
termios tio;
b = false;
enforce(tcgetattr(fd, &tio) >= 0);
tio.c_cc[VMIN] = b ? 1 : 0;
tio.c_cc[VTIME] = 0;

enforce(tcsetattr(fd, TCSANOW, &tio) >= 0);
fcntl(fd, F_SETFL, b ? 0 : O_NONBLOCK);
block = b;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

blocking(bool) now ignores its argument and can cause a busy‑spin input loop.

Overwriting the b parameter with false means:

  • Callers can never request blocking behavior; VMIN is always set to 0 and block is always false.
  • read() on the TTY will effectively be non‑blocking all the time.
  • TtyScreen.inputLoop() still toggles blocking(true) / blocking(false) to control whether the read blocks, so with this change the loop will busy‑poll and can peg a CPU core when there’s no input.

You can keep the removal of the F_SETFL logic but should honor the requested mode again:

     void blocking(bool b) @trusted
     {
         termios tio;
-        b = false;
         enforce(tcgetattr(fd, &tio) >= 0);
         tio.c_cc[VMIN] = b ? 1 : 0;
         tio.c_cc[VTIME] = 0;
 
         enforce(tcsetattr(fd, TCSANOW, &tio) >= 0);
         block = b;
     }

This restores the intended distinction between blocking and non‑blocking behavior using only termios.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void blocking(bool b) @trusted
{
termios tio;
b = false;
enforce(tcgetattr(fd, &tio) >= 0);
tio.c_cc[VMIN] = b ? 1 : 0;
tio.c_cc[VTIME] = 0;
enforce(tcsetattr(fd, TCSANOW, &tio) >= 0);
fcntl(fd, F_SETFL, b ? 0 : O_NONBLOCK);
block = b;
}
void blocking(bool b) @trusted
{
termios tio;
enforce(tcgetattr(fd, &tio) >= 0);
tio.c_cc[VMIN] = b ? 1 : 0;
tio.c_cc[VTIME] = 0;
enforce(tcsetattr(fd, TCSANOW, &tio) >= 0);
block = b;
}
🤖 Prompt for AI Agents
In source/dcell/termio.d around lines 144 to 154, the function blocking(bool b)
currently overwrites the parameter with "b = false" which ignores the caller's
intent and forces non‑blocking reads; remove the "b = false" assignment so the
passed argument is honored, keep the existing tcgetattr/tcsetattr calls, set
tio.c_cc[VMIN] = b ? 1 : 0 and tio.c_cc[VTIME] = 0 as written, and ensure block
= b remains so the object state reflects the requested mode; this restores
proper blocking vs non‑blocking TTY behavior using termios only.

We're moving to delete the terminfo database, and this is more work
on that path.  We have better support for standard escapes, as the
terminals have common and compatible functionality (the terminfo DB
had pointless, from our perspective, differences).

This also eliminates the automargin bug hackery, as no supported
terminals actually need it.

The terminfo capabilities have shrunk considerably.  We still need
to sort out a few last bits, before delete this entirely.

This also has some termio fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants