feat(cli): set terminal title to project name#988
feat(cli): set terminal title to project name#988zerone0x wants to merge 3 commits intovoidzero-dev:mainfrom
Conversation
Instead of showing just "vp" as the terminal window title, read the project name from the nearest package.json and set it as the terminal title using the OSC 0 escape sequence. This applies to both the global CLI and the local CLI entry points. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ Deploy Preview for viteplus-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| pub fn set_terminal_title(title: &str) { | ||
| use std::io::Write; | ||
|
|
||
| if !std::io::stdout().is_terminal() || std::env::var_os("CI").is_some() { |
There was a problem hiding this comment.
Will there be similar issues to #986? Under what conditions would title not be supported?
There was a problem hiding this comment.
Good call. #986 is different because it is about OSC queries (OSC 10/11/4): those write to the tty and then wait for a response, so unsupported/non-forwarding environments can hang or leak responses.
OSC 0 title setting is write-only, so it should not have the same blocking class of issue. The possible failure modes are:
- stdout is not a TTY / CI: no terminal to update
TERM=dumb, missing/disabled ANSI/VT support, or older Windows console hosts without VT processing: escape bytes could be printed literally- terminal multiplexers/remotes may ignore or rewrite the title sequence
- individual terminal emulators may simply ignore OSC 0
I pushed 8ff6964 to make the fallback more conservative: it now only emits OSC 0 when stdout is a TTY, not CI/GitHub Actions, and the existing supports-color terminal capability check says ANSI/VT escapes are supported. I also sanitize control characters from the package name before writing the title. If unsupported, this is a no-op.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 414beb4bae
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !std::io::stdout().is_terminal() || std::env::var_os("CI").is_some() { | ||
| return; | ||
| } | ||
|
|
||
| let _ = write!(std::io::stdout(), "\x1b]0;{title}\x07"); |
There was a problem hiding this comment.
Check terminal capability before writing OSC 0
This emits ESC]0;…BEL on any TTY except CI, but that is broader than the terminal-capability checks we already use elsewhere in header.rs. In environments where stdout is a terminal but OSC/VT sequences are not supported—e.g. TERM=dumb, or Windows console hosts that have not enabled ENABLE_VIRTUAL_TERMINAL_PROCESSING—users will see the raw bytes at the top of every vp invocation instead of just getting a title update. Please gate this on real escape-sequence support before writing to stdout.
Useful? React with 👍 / 👎.
zerone0x
left a comment
There was a problem hiding this comment.
PR #986 dealt with OSC color queries (OSC 10/11), which many terminals don't respond to and can cause hangs. OSC 0 (set window title) is a write-only escape — it doesn't wait for a terminal response, so there's no risk of blocking or timeout. It's supported by virtually all modern terminal emulators (xterm, iTerm2, Terminal.app, Windows Terminal, GNOME Terminal, etc.).
The only case where it's "not supported" is if a terminal simply ignores the sequence, which is harmless. The current guards (is_terminal() + CI check) should be sufficient.
Summary
package.jsonand set it as the terminal window title using the OSC 0 escape sequence (ESC ] 0 ; <title> BEL)vpbinary) and the local CLI entry pointpackage.jsonwith anamefield is foundFixes #978
Test plan
vite_sharedtests pass (31 passed, 1 ignored)vp devin a project directory and verify the terminal tab/window title shows the project name instead of "vp"vpoutside any project directory and verify no error occurs (graceful fallback)🤖 Generated with Claude Code