Repository navigation
feat: add window_title to shpool list --json
#441
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
Open
GeoffChurch
wants to merge
2
commits into
shell-pool:master
Choose a base branch
from
GeoffChurch:session-titles
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,11 +106,33 @@ pub struct SessionLifecycleState { | |
| pub attachment: Option<Attachment>, | ||
| } | ||
|
|
||
| /// A session's current window title. Written by the shell->client thread | ||
| /// whenever the window title changes, and read by `handle_list`. Kept out of | ||
| /// `inner` for the same reason as [`SessionLifecycleState::attachment`]. | ||
| #[derive(Debug, Default)] | ||
| pub struct SessionWindowTitle { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing, I don't think we should reify this in a data structure like this |
||
| window_title: Mutex<Option<String>>, | ||
| } | ||
|
|
||
| impl SessionWindowTitle { | ||
| /// Record a new window title, replacing any non-UTF-8 bytes with U+FFFD. | ||
| pub fn set(&self, window_title: Option<&[u8]>) { | ||
| *self.window_title.lock() = | ||
| window_title.map(|window_title| String::from_utf8_lossy(window_title).into_owned()); | ||
| } | ||
|
|
||
| /// Return a copy of the current window title. | ||
| pub fn get(&self) -> Option<String> { | ||
| self.window_title.lock().clone() | ||
| } | ||
| } | ||
|
|
||
| /// Session represent a shell session | ||
| #[derive(Debug)] | ||
| pub struct Session { | ||
| pub started_at: time::SystemTime, | ||
| pub lifecycle: SessionLifecycle, | ||
| pub window_title: Arc<SessionWindowTitle>, | ||
| pub child_pid: libc::pid_t, | ||
| pub child_exit_notifier: Arc<ExitNotifier>, | ||
| pub shell_to_client_ctl: Arc<Mutex<ShellToClientCtl>>, | ||
|
|
@@ -260,6 +282,7 @@ pub struct ShellToClientArgs { | |
| // true if the client is still live, false if it has hung up on us. | ||
| pub heartbeat_ack: crossbeam_channel::Sender<(u64, bool)>, | ||
| pub child_exit_notifier: Arc<ExitNotifier>, | ||
| pub window_title: Arc<SessionWindowTitle>, | ||
| } | ||
|
|
||
| impl SessionInner { | ||
|
|
@@ -291,6 +314,9 @@ impl SessionInner { | |
|
|
||
| let mut output_spool = | ||
| session_restore::new(config, &args.tty_size, args.scrollback_lines, &name); | ||
| // The raw bytes last written to `args.window_title`, cached locally so checking | ||
| // for changes doesn't lock `args.window_title`. | ||
| let mut last_window_title: Option<Vec<u8>> = None; | ||
| let mut buf: Vec<u8> = vec![0; consts::BUF_SIZE]; | ||
| let mut poll_fds = [poll::PollFd::new( | ||
| watchable_master.borrow_fd(), | ||
|
|
@@ -601,6 +627,11 @@ impl SessionInner { | |
|
|
||
| if has_seen_prompt_sentinel { | ||
| output_spool.process(buf); | ||
| let window_title = output_spool.window_title(); | ||
| if window_title != last_window_title.as_deref() { | ||
| args.window_title.set(window_title); | ||
| last_window_title = window_title.map(<[u8]>::to_vec); | ||
| } | ||
| } | ||
|
|
||
| let mut reset_client_conn = false; | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
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.
It seems a bit strange to store the title persistantly in the session struct. I would think it would be better to always dynamically fetch it from the term impl.