-
Notifications
You must be signed in to change notification settings - Fork 3
Reorganize platform support, improve comments. #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The purpose here is to improve readability and maintainability.
Also this makes the PosixTty and WinTty public, which can allow others to make use of them connected to different files, etc.
WalkthroughRefactors the terminal I/O layer: adds a new public Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant common.d as common.newScreen()
participant TtyScreenCtor as TtyScreen.this()
rect rgba(0,128,255,0.06)
Caller->>common.newScreen(): newScreen()
common.newScreen()->>TtyScreenCtor: return new TtyScreen()
end
alt POSIX
TtyScreenCtor->>PosixTty: PosixTty("/dev/tty")
PosixTty->>PosixTty: open device, save termios
else Windows
TtyScreenCtor->>WinTty: WinTty()
WinTty->>WinTty: get handles, save modes
end
TtyScreenCtor->>TtyScreenCtor: initialize screen with Tty
Note over Caller,TtyScreenCtor: Caller then uses TtyScreen methods -> delegates to underlying Tty for start/read/write/resize
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (5)
source/dcell/common.d (1)
16-22: Comment is incomplete for Windows support.The doc comment mentions only POSIX (
/dev/ttyand$TERM), butTtyScreen()now handles Windows as well (viaWinTty). Consider updating the comment to reflect cross-platform behavior./** - * Obtain a new screen. On POSIX this is connected to /dev/tty - * using the $TERM environment variable. + * Obtain a new screen. On POSIX this is connected to /dev/tty + * using the $TERM environment variable. On Windows this uses + * the console APIs. */source/dcell/termio.d (2)
127-128: Minor typo in comment.- // If cores.sys.posix.sys.ioctl had more complete and accurate data... + // If core.sys.posix.sys.ioctl had more complete and accurate data...
232-233: Minor typo: "clearning" → "clearing".- // this can fail, we're just clearning the signaled state + // this can fail, we're just clearing the signaled statesource/dcell/wintty.d (2)
139-141: Check return value of ReadConsoleInputW.The return value indicates success/failure but is ignored. While the error path may be rare, consider validating the call succeeded before processing the records.
- ReadConsoleInput(input, recs.ptr, 128, &nrec); + if (!ReadConsoleInputW(input, recs.ptr, 128, &nrec)) + return result;
61-66: Consider checking CreateEventW result.
CreateEventWcan fail and returnNULL. Adding validation would improve robustness:this() { input = GetStdHandle(STD_INPUT_HANDLE); output = GetStdHandle(STD_OUTPUT_HANDLE); eventH = CreateEventW(null, true, false, null); + if (eventH is null) + throw new Exception("Failed to create event handle"); }Note: This would require removing
@nogc nothrowor using a different error handling strategy.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
source/dcell/common.d(1 hunks)source/dcell/termio.d(2 hunks)source/dcell/tty.d(1 hunks)source/dcell/ttyscreen.d(4 hunks)source/dcell/wintty.d(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: gdamore
Repo: gdamore/dcell PR: 27
File: source/dcell/ttyscreen.d:763-766
Timestamp: 2025-12-08T19:10:45.993Z
Learning: In source/dcell/ttyscreen.d, the newTtyScreen() factory function intentionally does not accept a term parameter because the TtyScreen constructor handles environment variable resolution internally with an optional term parameter. Users needing to override the terminal type should call the constructor directly: new TtyScreen(newDevTty(), "custom-term").
📚 Learning: 2025-12-08T19:10:45.993Z
Learnt from: gdamore
Repo: gdamore/dcell PR: 27
File: source/dcell/ttyscreen.d:763-766
Timestamp: 2025-12-08T19:10:45.993Z
Learning: In source/dcell/ttyscreen.d, the newTtyScreen() factory function intentionally does not accept a term parameter because the TtyScreen constructor handles environment variable resolution internally with an optional term parameter. Users needing to override the terminal type should call the constructor directly: new TtyScreen(newDevTty(), "custom-term").
Applied to files:
source/dcell/common.dsource/dcell/tty.dsource/dcell/wintty.dsource/dcell/ttyscreen.dsource/dcell/termio.d
📚 Learning: 2025-12-08T19:17:33.678Z
Learnt from: gdamore
Repo: gdamore/dcell PR: 27
File: source/dcell/ttyscreen.d:448-494
Timestamp: 2025-12-08T19:17:33.678Z
Learning: In source/dcell/ttyscreen.d, Color.reset is defined as a value above the range of valid colors. In the sendColors() function, after emitting the reset sequence (vt.resetFgBg), Color.reset values naturally skip all subsequent color-setting logic (isRGB checks and palette range checks < 8, < 256) because they are out of range, which is the correct behavior by design.
Applied to files:
source/dcell/ttyscreen.d
🔇 Additional comments (6)
source/dcell/tty.d (1)
24-90: Well-designed interface for TTY abstraction.The
Ttyinterface cleanly separates platform-specific terminal I/O from the VT logic. The method signatures are appropriate for the use cases, and the documentation is thorough.source/dcell/termio.d (2)
360-391: Signal handler supports only one active TTY at a time.The
watchResize/ignoreResizemechanism uses a single globalsigFd, so only the firstPosixTtyinstance will receive resize notifications. This is likely acceptable for typical single-screen usage, but worth documenting if multiple TTY instances might be used concurrently.
56-108: LGTM: Clean lifecycle management.The
PosixTtyclass properly manages the file descriptor lifecycle withstart(),stop(), andclose()methods. The pattern of saving terminal state on start and restoring on close is correct.source/dcell/ttyscreen.d (2)
131-149: Clean platform-aware constructor.The no-arg constructor properly handles platform detection with scoped imports for
PosixTtyandWinTty. Theelsebranch throwing an exception for unsupported platforms is good defensive programming.
151-236: LGTM: Constructor with Tty parameter.The constructor properly initializes the screen with the provided
Ttyinstance and handles terminal type detection via environment variables. The legacy terminal handling is thorough.source/dcell/wintty.d (1)
169-189: LGTM: Efficient chunked Unicode output.The
writemethod correctly converts UTF-8 to UTF-16 usingbyWcharand writes in chunks to avoid buffer overflow. Good approach for Windows console output.
Summary by CodeRabbit
Release Notes
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.