-
-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tmux: attach control mode parser to terminal
This causes `tmux -CC attach` to enter control mode and patch into the terminal, printing out parsed event messages. refs: #336
- Loading branch information
Showing
8 changed files
with
250 additions
and
10 deletions.
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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[workspace] | ||
members = ["wezterm-mux-server", "wezterm", "wezterm-gui", "strip-ansi-escapes", "tmux-cc"] | ||
members = ["wezterm-mux-server", "wezterm", "wezterm-gui", "strip-ansi-escapes"] | ||
|
||
[profile.release] | ||
opt-level = 3 |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use crate::domain::{alloc_domain_id, Domain, DomainId, DomainState}; | ||
use crate::pane::{Pane, PaneId}; | ||
use crate::tab::{SplitDirection, Tab, TabId}; | ||
use crate::window::WindowId; | ||
use async_trait::async_trait; | ||
use portable_pty::{CommandBuilder, PtySize}; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
use std::sync::Arc; | ||
|
||
pub(crate) struct TmuxDomainState { | ||
pane_id: PaneId, | ||
domain_id: DomainId, | ||
parser: RefCell<tmux_cc::Parser>, | ||
} | ||
|
||
pub struct TmuxDomain { | ||
pub(crate) inner: Arc<TmuxDomainState>, | ||
} | ||
|
||
impl TmuxDomainState { | ||
pub fn advance(&self, b: u8) { | ||
let mut parser = self.parser.borrow_mut(); | ||
if let Some(event) = parser.advance_byte(b) { | ||
log::error!("tmux: {:?}", event); | ||
} | ||
} | ||
} | ||
|
||
impl TmuxDomain { | ||
pub fn new(pane_id: PaneId) -> Self { | ||
let domain_id = alloc_domain_id(); | ||
let parser = RefCell::new(tmux_cc::Parser::new()); | ||
let inner = Arc::new(TmuxDomainState { | ||
domain_id, | ||
pane_id, | ||
parser, | ||
}); | ||
Self { inner } | ||
} | ||
} | ||
|
||
#[async_trait(?Send)] | ||
impl Domain for TmuxDomain { | ||
async fn spawn( | ||
&self, | ||
size: PtySize, | ||
command: Option<CommandBuilder>, | ||
command_dir: Option<String>, | ||
window: WindowId, | ||
) -> anyhow::Result<Rc<Tab>> { | ||
anyhow::bail!("Spawn not yet implemented for TmuxDomain"); | ||
} | ||
|
||
async fn split_pane( | ||
&self, | ||
command: Option<CommandBuilder>, | ||
command_dir: Option<String>, | ||
tab: TabId, | ||
pane_id: PaneId, | ||
direction: SplitDirection, | ||
) -> anyhow::Result<Rc<dyn Pane>> { | ||
anyhow::bail!("split_pane not yet implemented for TmuxDomain"); | ||
} | ||
|
||
fn domain_id(&self) -> DomainId { | ||
self.inner.domain_id | ||
} | ||
|
||
fn domain_name(&self) -> &str { | ||
"tmux" | ||
} | ||
|
||
async fn attach(&self) -> anyhow::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn detach(&self) -> anyhow::Result<()> { | ||
anyhow::bail!("detach not implemented for TmuxDomain"); | ||
} | ||
|
||
fn state(&self) -> DomainState { | ||
DomainState::Attached | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,30 +1,45 @@ | ||
number = { ASCII_DIGIT+ } | ||
any_text = { ANY* } | ||
word = { ASCII_ALPHANUMERIC+ } | ||
|
||
pane_id = { "%" ~ number } | ||
window_id = { "@" ~ number } | ||
session_id = { "$" ~ number } | ||
client_name = { word } | ||
|
||
begin = { "%begin " ~ number ~ " " ~ number ~ " " ~ number } | ||
end = { "%end " ~ number ~ " " ~ number ~ " " ~ number } | ||
error = { "%error " ~ number ~ " " ~ number ~ " " ~ number } | ||
|
||
client_session_changed = { "%client-session-changed " ~ client_name ~ " " ~ session_id ~ " " ~any_text } | ||
output = { "%output " ~ pane_id ~ " " ~ any_text } | ||
exit = { "%exit" } | ||
exit = { "%exit" ~ (" " ~ any_text)? } | ||
sessions_changed = { "%sessions-changed" } | ||
pane_mode_changed = { "%pane-mode-changed " ~ pane_id } | ||
window_add = { "%window-add " ~ window_id } | ||
window_close = { "%window-close " ~ window_id } | ||
window_pane_changed = { "%window-pane-changed " ~ window_id ~ " " ~ pane_id } | ||
window_renamed = { "%window-renamed " ~ window_id ~ " " ~ any_text } | ||
session_changed = { "%session-changed " ~ session_id ~ " " ~ any_text } | ||
session_renamed = { "%session-renamed " ~ any_text } | ||
session_window_changed = { "%session-window-changed " ~ session_id ~ " " ~ window_id } | ||
|
||
line = _{ ( | ||
client_session_changed | | ||
begin | | ||
end | | ||
error | | ||
exit | | ||
output | | ||
pane_mode_changed | | ||
session_changed | | ||
session_renamed | | ||
session_window_changed | | ||
sessions_changed | | ||
window_add | ||
window_add | | ||
window_close | | ||
window_pane_changed | | ||
window_renamed | ||
) } | ||
|
||
line_entire = _{ SOI ~ line ~ EOI } |