Set terminal tab title to scrcpy and device name#6825
Open
zxmpg41 wants to merge 1 commit into
Open
Conversation
Collaborator
|
Thank you, interesting. 👍 I think it should be printed only when the output is a tty (using Also, please rebase onto |
On startup, set the terminal tab/window title to "scrcpy" so the tab is immediately identifiable. Once the device is connected, update the title to "scrcpy - <device name>" (or "scrcpy - <window-title>" if --window-title is provided). On exit, clear the title so the shell can restore its own. OSC 0 escape sequences are used for cross-platform support (Windows Terminal, macOS Terminal, xterm). On Windows, SetConsoleTitleA() is also called as a fallback for legacy console hosts (cmd.exe, conhost). The same behaviour applies in OTG mode.
dfbefce to
d98697a
Compare
Author
|
Good point. I've added |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Set the terminal tab/window title to
scrcpywhen the program starts, and update it toscrcpy - <device name>once a device is connected. This makes it easy to identify scrcpy tabs when multiple tabs are open in a terminal multiplexer or tabbed terminal emulator (e.g. Windows Terminal, macOS Terminal, tmux).The title respects
--window-title: if a custom window title is provided, the terminal tab title becomesscrcpy - <custom title>instead of using the device name.The original terminal title is restored (cleared) when scrcpy exits, allowing the shell to reset its own title on the next prompt.
Changes
app/src/util/term.h— declared new functionsc_term_set_title(const char *title)app/src/util/term.c— implementedsc_term_set_title(): only emits output when stdout is a TTY (isatty()on Unix/macOS,_isatty()on Windows), so piping (e.g.scrcpy | tee logs.txt) is not affected; emits an OSC 0 escape sequence (\033]0;<title>\007) to stdout, supported by all modern terminal emulators; on Windows additionally callsSetConsoleTitleA()unconditionally as a fallback for legacy console hosts (cmd.exe,conhost) that do not process VT sequencesapp/src/main.c— callssc_term_set_title("scrcpy")immediately on startup; callssc_term_set_title("")on exit to restore the terminal titleapp/src/scrcpy.c— callssc_term_set_title("scrcpy - <name>")after the device handshake completes (using--window-titleif provided, otherwise the device name reported by the server); callssc_term_set_title("")on exitapp/src/usb/scrcpy_otg.c— same behaviour in OTG mode: updates the terminal tab title toscrcpy - <USB product name>once the device is known; callssc_term_set_title("")on exit