diff --git a/src/key_bind.rs b/src/key_bind.rs index 04cff75..c2a234e 100644 --- a/src/key_bind.rs +++ b/src/key_bind.rs @@ -23,6 +23,7 @@ pub fn key_binds() -> HashMap { // Standard key bindings bind!([Ctrl, Shift], Key::Character("A".into()), SelectAll); bind!([Ctrl, Shift], Key::Character("C".into()), Copy); + bind!([Ctrl], Key::Character("c".into()), CopyOrSigint); bind!([Ctrl, Shift], Key::Character("F".into()), Find); bind!([Ctrl, Shift], Key::Character("N".into()), WindowNew); bind!([Ctrl, Shift], Key::Character("Q".into()), WindowClose); diff --git a/src/main.rs b/src/main.rs index f8a36e0..c34acd6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,6 +168,7 @@ pub enum Action { About, ColorSchemes(ColorSchemeKind), Copy, + CopyOrSigint, CopyPrimary, Find, PaneFocusDown, @@ -214,6 +215,7 @@ impl MenuAction for Action { Message::ToggleContextPage(ContextPage::ColorSchemes(*color_scheme_kind)) } Self::Copy => Message::Copy(entity_opt), + Self::CopyOrSigint => Message::CopyOrSigint(entity_opt), Self::CopyPrimary => Message::CopyPrimary(entity_opt), Self::Find => Message::Find(true), Self::PaneFocusDown => Message::PaneFocusAdjacent(pane_grid::Direction::Down), @@ -268,6 +270,7 @@ pub enum Message { ColorSchemeTabActivate(widget::segmented_button::Entity), Config(Config), Copy(Option), + CopyOrSigint(Option), CopyPrimary(Option), DefaultBoldFontWeight(usize), DefaultDimFontWeight(usize), @@ -1676,6 +1679,26 @@ impl Application for App { } return self.update_focus(); } + Message::CopyOrSigint(entity_opt) => { + if let Some(tab_model) = self.pane_model.active() { + let entity = entity_opt.unwrap_or_else(|| tab_model.active()); + if let Some(terminal) = tab_model.data::>(entity) { + let terminal = terminal.lock().unwrap(); + let term = terminal.term.lock(); + if let Some(text) = term.selection_to_string() { + return Command::batch([clipboard::write(text), self.update_focus()]); + } else { + // Drop the lock for term so that input_scroll doesn't block forever + drop(term); + // 0x03 is ^C + terminal.input_scroll(&[0x03]); + } + } + } else { + log::warn!("Failed to get focused pane"); + } + return self.update_focus(); + } Message::CopyPrimary(entity_opt) => { if let Some(tab_model) = self.pane_model.active() { let entity = entity_opt.unwrap_or_else(|| tab_model.active());