Skip to content

feat(cli): set terminal title to project name#988

Open
zerone0x wants to merge 3 commits intovoidzero-dev:mainfrom
zerone0x:feat/terminal-title-project-name
Open

feat(cli): set terminal title to project name#988
zerone0x wants to merge 3 commits intovoidzero-dev:mainfrom
zerone0x:feat/terminal-title-project-name

Conversation

@zerone0x
Copy link
Copy Markdown
Contributor

Summary

  • Read the project name from the nearest package.json and set it as the terminal window title using the OSC 0 escape sequence (ESC ] 0 ; <title> BEL)
  • Applies to both the global CLI (vp binary) and the local CLI entry point
  • Falls back gracefully: no-op when stdout is not a terminal, when running in CI, or when no package.json with a name field is found

Fixes #978

Test plan

  • vite_shared tests pass (31 passed, 1 ignored)
  • Run vp dev in a project directory and verify the terminal tab/window title shows the project name instead of "vp"
  • Run vp outside any project directory and verify no error occurs (graceful fallback)
  • Verify CI pipeline passes

🤖 Generated with Claude Code

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>
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 17, 2026

Deploy Preview for viteplus-preview ready!

Name Link
🔨 Latest commit 8ff6964
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/69f351b0524c19000825f28a
😎 Deploy Preview https://deploy-preview-988--viteplus-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread crates/vite_shared/src/header.rs Outdated
pub fn set_terminal_title(title: &str) {
use std::io::Write;

if !std::io::stdout().is_terminal() || std::env::var_os("CI").is_some() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will there be similar issues to #986? Under what conditions would title not be supported?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Mar 19, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread crates/vite_shared/src/header.rs Outdated
Comment on lines +535 to +539
if !std::io::stdout().is_terminal() || std::env::var_os("CI").is_some() {
return;
}

let _ = write!(std::io::stdout(), "\x1b]0;{title}\x07");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

@zerone0x zerone0x left a comment

Choose a reason for hiding this comment

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

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.

@TheAlexLichter TheAlexLichter requested a review from fengmk2 May 4, 2026 14:58
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.

Set terminal title

2 participants