-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add support for window title manipulation (fixes #29) #44
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
WalkthroughAdds Screen.setTitle(string) to the public API, implements title storage and OSC/DSC emission and restoration in TtyScreen across start/draw/stop, and updates demos to call setTitle and add scope(exit) cleanup for stopping the screen. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Demo as Demo (mouse/colors/hello)
participant ScreenIface as Screen
participant Tty as TtyScreen
participant Terminal as Terminal Emulator
Demo->>ScreenIface: setTitle(title)
ScreenIface->>Tty: setTitle(title) -- store title
Note right of Tty: internal title state updated
alt on start or draw when started and title set
Tty->>Terminal: emit OSC set-title sequence
else on start/draw when no title or on restore
Tty->>Terminal: emit OSC restore-title sequence
end
alt on stop
Tty->>Terminal: emit OSC restore-title sequence
end
Estimated code review effortπ― 4 (Complex) | β±οΈ ~45 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touchesβ Passed checks (3 passed)
β¨ Finishing touchesπ§ͺ Generate unit tests (beta)
π Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro π Files selected for processing (5)
π§ Files skipped from review as they are similar to previous changes (2)
π§° Additional context usedπ§ Learnings (2)π Learning: 2025-12-08T19:10:45.993ZApplied to files:
π Learning: 2025-12-08T19:17:33.678ZApplied to files:
π Additional comments (10)
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: 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)
252-286: Addvt.restoreTitlecall tostop()to balance the title stack
start()saves the window title viavt.saveTitle(and conditionally restores/resaves when no custom title is set), butstop()never emitsvt.restoreTitle. This leaves the saved title on the terminal's title stack and can prevent the original window title from being explicitly restored on exit. The implementation ofsetTitle()shows the developer understood this stack behavior (with its comment "restore previously saved title, but also make sure it remains on the stack"), making the omission instop()appear unintentional.Add the restore sequence early in
stop(), guarded by a capability check:void stop() { if (!started) return; + if (vt.restoreTitle.length) + { + puts(vt.restoreTitle); + } + puts(vt.enableAutoMargin); puts(vt.resetFgBg); ...While xterm, VTE, and kitty all support the standard CSI 23;2t sequence, terminal behavior with title stacks varies by emulator version and configuration (e.g., xterm's
allowTitleOpssetting). Test the placement and interaction with alternate-screen cleanup across your target terminals to ensure the title is restored correctly.
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (3)
demos/mouse/source/mouse.d(1 hunks)source/dcell/screen.d(1 hunks)source/dcell/ttyscreen.d(3 hunks)
π§° Additional context used
π§ Learnings (1)
π 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/ttyscreen.d
π Additional comments (2)
demos/mouse/source/mouse.d (1)
107-112: Title-setting call placement looks goodCalling
s.setTitle("Dcell Event Demo");right afterstart()and input-mode setup cleanly demonstrates the new API and ensures the title is applied while the screen is active. No issues here.source/dcell/screen.d (1)
150-155: NewScreen.setTitleAPI looks fine; consider clarifying semantics and impactThe interface addition is reasonable and matches existing naming conventions (
setSize,setStyle), but a couple of clarifications could help:
- This is a breaking change for any external
Screenimplementations; they'll now need to add asetTitlestub. Consider noting that in release notes or appropriate version markers.- The documentation could specify when it's valid to call
setTitle(e.g., allowed beforestart(), afterstop(), or only while active) and explicitly note that implementations on non-windowed or legacy terminals are free to treat it as a no-op.This guidance will make it easier for alternative backends to implement the method consistently.
ff86c86 to
3777731
Compare
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: 1
β»οΈ Duplicate comments (1)
source/dcell/ttyscreen.d (1)
445-459: Missingflush()call whenstartedistrue.The issues from the previous review remain unaddressed. When
startedistrue, aflush()call should follow theputs()to match the pattern insetSize()(line 420) andsendPasteEnable()(line 834). Additionally, the pre-start stack manipulation is redundant sincestart()already handles title stack management.
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (3)
demos/mouse/source/mouse.d(1 hunks)source/dcell/screen.d(1 hunks)source/dcell/ttyscreen.d(5 hunks)
π§ Files skipped from review as they are similar to previous changes (2)
- demos/mouse/source/mouse.d
- source/dcell/screen.d
π§° Additional context used
π§ Learnings (1)
π 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/ttyscreen.d
π Additional comments (3)
source/dcell/ttyscreen.d (3)
276-284: LGTM: Title handling in start() is well-structured.The conditional logic correctly handles both cases: applying a pre-set title or maintaining the original terminal title via the save/restore stack.
303-303: LGTM: Restoring title on stop() ensures proper cleanup.This correctly restores the original window title when the screen stops.
543-543: LGTM: Appropriate state variable for title management.
source/dcell/ttyscreen.d
Outdated
| string exitURL = "\x1b]8;;\x1b\\"; | ||
| string setWindowSize = "\x1b[8;%d;%dt"; | ||
| // Some terminals do not support the title stack, but do support | ||
| // changing the title. FOr those we set the title back to the |
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.
Typo: "FOr" should be "For".
- // changing the title. FOr those we set the title back to the
+ // changing the title. For those we set the title back to theπ 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.
| // changing the title. FOr those we set the title back to the | |
| // changing the title. For those we set the title back to the |
π€ Prompt for AI Agents
In source/dcell/ttyscreen.d around line 103, the comment contains a typo: "FOr"
should be corrected to "For"; update the comment text to use proper
capitalization ("For those we set the title back to the") and save the file.
3777731 to
bf746f9
Compare
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: 0
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)
238-248: Guard methods against empty vt. format strings to avoidFormatExceptionon legacy terminals*In the legacy path (lines 238β248), several
vt.*attributes are set to""(empty strings). This creates a critical issue in methods that pass arguments toformat(): callingformat("", arg)in D'sstd.formatthrowsFormatExceptionbecause the empty format string cannot accept arguments.The following methods are affected and will crash:
setTitle()(line 451):format(vt.setTitle, title)enterURL()(line 481):format(vt.enterURL, url)exitURL()(line 489):format(vt.exitURL, url)setWindowSize()(line 497):format(vt.setWindowSize, width, height)Add length checks before format calls to make these methods harmless on legacy terminals:
void setTitle(string title) { this.title = title; - if (started) - { - puts(format(vt.setTitle, title)); - flush(); - } + if (started && vt.setTitle.length) + { + puts(format(vt.setTitle, title)); + flush(); + } }Apply the same pattern to
enterURL(),exitURL(), andsetWindowSize().Note: Methods without format arguments (
saveTitle,restoreTitle,enableCsiU,disableCsiU) will not throw but will produce no output, which is acceptable; however, applying the guard for consistency is recommended.
β»οΈ Duplicate comments (1)
source/dcell/ttyscreen.d (1)
102-107: Fix comment typo (βFOrβ β βForβ)Minor nit: Line 103 reads
FOrinstead ofFor; worth correcting while youβre here.- // Some terminals do not support the title stack, but do support - // changing the title. FOr those we set the title back to the + // Some terminals do not support the title stack, but do support + // changing the title. For those we set the title back to the
π§Ή Nitpick comments (1)
source/dcell/screen.d (1)
150-155: Clarify semantics ofsetTitle("")in the interface contractThe method is well-placed, but the doc doesnβt specify what an empty title string should mean (clear/unset vs restore original vs βno-opβ). Since
TtyScreenalready treats empty differently before/afterstart(), itβd be good to document the intended semantics here so other backends and callers can align.
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (3)
demos/mouse/source/mouse.d(1 hunks)source/dcell/screen.d(1 hunks)source/dcell/ttyscreen.d(5 hunks)
π§ Files skipped from review as they are similar to previous changes (1)
- demos/mouse/source/mouse.d
π§° Additional context used
π§ Learnings (1)
π 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/screen.dsource/dcell/ttyscreen.d
π Additional comments (1)
source/dcell/ttyscreen.d (1)
271-284: Title save/restore aroundstart()/stop()looks consistentThe new logic to
saveTitleon start, apply either the explicittitleorrestoreTitle+saveTitlewhen no title is set, and thenrestoreTitleon stop appears balanced and should behave correctly across multiple start/stop cycles for both stack-capable and simpler terminals.Also applies to: 303-303
bf746f9 to
4077086
Compare
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: 0
π§Ή Nitpick comments (1)
source/dcell/ttyscreen.d (1)
276-284: Clarify null vs empty string semantics fortitlefield.In D,
if (title)distinguishes betweennull(never set) and""(explicitly empty). IfsetTitle("")is called, the condition is true and an empty title is emitted, whereasnulltakes theelsepath. If this distinction is intentional, a brief comment would help API consumers understand the behavior.+ // Note: null means no title set (use original), "" means explicitly empty title if (title) { puts(format(vt.setTitle, title)); }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (3)
demos/mouse/source/mouse.d(1 hunks)source/dcell/screen.d(1 hunks)source/dcell/ttyscreen.d(5 hunks)
π§ Files skipped from review as they are similar to previous changes (2)
- source/dcell/screen.d
- demos/mouse/source/mouse.d
π§° Additional context used
π§ Learnings (2)
π 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/ttyscreen.d
π Additional comments (4)
source/dcell/ttyscreen.d (4)
102-107: LGTM - Typo fixed, fallback strategy is sound.The dual-sequence approach in
restoreTitle(OSC 2 empty + XTWINOPS pop) gracefully handles both stack-supporting and non-stack terminals. The typo from the previous review has been corrected.
303-303: LGTM - Proper title restoration on stop.Restoring the title before exiting the alternate screen and other cleanup is the correct sequencing for terminal state restoration.
445-453: LGTM - Previous concerns addressed.The implementation now correctly flushes after emitting the title sequence when started, and properly defers to
start()for title handling when not yet started. This aligns with the pattern used bysetSize()andsendPasteEnable().
537-537: LGTM!Appropriate field declaration for tracking title state.
Changing to the alternate screen apparently breaks kitty protocol on kitty, because the alt screen has different values there. We need to switch to it before doing other things.
Using a scope exit ensures that we put things back properly.
4077086 to
7fcdcdc
Compare
Summary by CodeRabbit
New Features
Bug Fixes / Reliability
βοΈ Tip: You can customize this high-level summary in your review settings.