Implement OSC 52 escape code events

This commit is contained in:
Jeremy Soller 2024-03-13 09:12:07 -06:00
parent 032804fbff
commit e24826e970
No known key found for this signature in database
GPG key ID: D02FD439211AF56F

View file

@ -1,9 +1,7 @@
// Copyright 2023 System76 <info@system76.com> // Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use alacritty_terminal::{ use alacritty_terminal::{event::Event as TermEvent, term, term::color::Colors as TermColors, tty};
event::Event as TermEvent, term::color::Colors as TermColors, term::Config as TermConfig, tty,
};
use cosmic::{ use cosmic::{
app::{message, Command, Core, Settings}, app::{message, Command, Core, Settings},
cosmic_config::{self, ConfigSet, CosmicConfigEntry}, cosmic_config::{self, ConfigSet, CosmicConfigEntry},
@ -133,7 +131,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
None None
}; };
let term_config = TermConfig::default(); let term_config = term::Config::default();
// Set up environmental variables for terminal // Set up environmental variables for terminal
tty::setup_env(); tty::setup_env();
// Override TERM for better compatibility // Override TERM for better compatibility
@ -166,7 +164,7 @@ pub struct Flags {
config_handler: Option<cosmic_config::Config>, config_handler: Option<cosmic_config::Config>,
config: Config, config: Config,
startup_options: Option<tty::Options>, startup_options: Option<tty::Options>,
term_config: TermConfig, term_config: term::Config,
} }
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
@ -379,7 +377,7 @@ pub struct App {
find_search_value: String, find_search_value: String,
term_event_tx_opt: Option<mpsc::Sender<(pane_grid::Pane, segmented_button::Entity, TermEvent)>>, term_event_tx_opt: Option<mpsc::Sender<(pane_grid::Pane, segmented_button::Entity, TermEvent)>>,
startup_options: Option<tty::Options>, startup_options: Option<tty::Options>,
term_config: TermConfig, term_config: term::Config,
color_scheme_errors: Vec<String>, color_scheme_errors: Vec<String>,
color_scheme_expanded: Option<(ColorSchemeKind, ColorSchemeId)>, color_scheme_expanded: Option<(ColorSchemeKind, ColorSchemeId)>,
color_scheme_renaming: Option<(ColorSchemeKind, ColorSchemeId, String)>, color_scheme_renaming: Option<(ColorSchemeKind, ColorSchemeId, String)>,
@ -2136,6 +2134,31 @@ impl Application for App {
TermEvent::Bell => { TermEvent::Bell => {
//TODO: audible or visible bell options? //TODO: audible or visible bell options?
} }
TermEvent::ClipboardLoad(kind, callback) => {
match kind {
term::ClipboardType::Clipboard => {
log::info!("clipboard load");
return clipboard::read(move |data_opt| {
//TODO: what to do when data_opt is None?
callback(&data_opt.unwrap_or_default());
// We don't need to do anything else
message::none()
});
}
term::ClipboardType::Selection => {
log::info!("TODO: load selection");
}
}
}
TermEvent::ClipboardStore(kind, data) => match kind {
term::ClipboardType::Clipboard => {
log::info!("clipboard store");
return clipboard::write(data);
}
term::ClipboardType::Selection => {
log::info!("TODO: store selection");
}
},
TermEvent::ColorRequest(index, f) => { TermEvent::ColorRequest(index, f) => {
if let Some(tab_model) = self.pane_model.panes.get(pane) { if let Some(tab_model) = self.pane_model.panes.get(pane) {
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) { if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
@ -2146,6 +2169,9 @@ impl Application for App {
} }
} }
} }
TermEvent::CursorBlinkingChange => {
//TODO: should we blink the cursor?
}
TermEvent::Exit => { TermEvent::Exit => {
return self.update(Message::TabClose(Some(entity))); return self.update(Message::TabClose(Some(entity)));
} }
@ -2205,9 +2231,6 @@ impl Application for App {
} }
} }
} }
_ => {
log::warn!("TODO: {:?}", event);
}
} }
} }
Message::TermEventTx(term_event_tx) => { Message::TermEventTx(term_event_tx) => {