diff options
author | Aram Drevekenin <aram@poor.dev> | 2021-05-17 18:13:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-17 18:13:05 +0200 |
commit | a3f42b19a98c00b90fdd60a0486275a5f1829226 (patch) | |
tree | 1b57c80b8e6814851cf7c47fcf0bf9e5f00fadc6 /zellij-server | |
parent | 84911619b27fec7aa5d13f4d60db2e8625dc3a04 (diff) |
Osc implementation (#517)
* fix(compatibility): implement most osc methods
* style(fmt): rustfmt
* style(fmt): remove cargo warnings
* style(fmt): make clippy happy
* style(fmt): fix formatting after my clippy fixes broke it again ;P
* fix(grid): fix tests
Diffstat (limited to 'zellij-server')
-rw-r--r-- | zellij-server/src/lib.rs | 13 | ||||
-rw-r--r-- | zellij-server/src/panes/grid.rs | 161 | ||||
-rw-r--r-- | zellij-server/src/panes/terminal_pane.rs | 7 | ||||
-rw-r--r-- | zellij-server/src/panes/unit/grid_tests.rs | 65 | ||||
-rw-r--r-- | zellij-server/src/route.rs | 7 | ||||
-rw-r--r-- | zellij-server/src/screen.rs | 24 | ||||
-rw-r--r-- | zellij-server/src/tab.rs | 18 |
7 files changed, 228 insertions, 67 deletions
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 7e883ddc7..6fa87e481 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -29,15 +29,14 @@ use zellij_utils::{ cli::CliArgs, errors::{ContextType, ErrorInstruction, ServerContext}, input::options::Options, - ipc::{ClientToServerMsg, ServerToClientMsg}, - pane_size::PositionAndSize, + ipc::{ClientAttributes, ClientToServerMsg, ServerToClientMsg}, setup::{get_default_data_dir, install::populate_data_dir}, }; /// Instructions related to server-side application #[derive(Debug, Clone)] pub(crate) enum ServerInstruction { - NewClient(PositionAndSize, CliArgs, Options), + NewClient(ClientAttributes, CliArgs, Options), Render(Option<String>), UnblockInputThread, ClientExit, @@ -173,13 +172,13 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) { let (instruction, mut err_ctx) = server_receiver.recv().unwrap(); err_ctx.add_call(ContextType::IPCServer((&instruction).into())); match instruction { - ServerInstruction::NewClient(full_screen_ws, opts, config_options) => { + ServerInstruction::NewClient(client_attributes, opts, config_options) => { let session_data = init_session( os_input.clone(), opts, config_options, to_server.clone(), - full_screen_ws, + client_attributes, ); *sessions.write().unwrap() = Some(session_data); sessions @@ -217,7 +216,7 @@ fn init_session( opts: CliArgs, config_options: Options, to_server: SenderWithContext<ServerInstruction>, - full_screen_ws: PositionAndSize, + client_attributes: ClientAttributes, ) -> SessionMetaData { let (to_screen, screen_receiver): ChannelWithContext<ScreenInstruction> = mpsc::channel(); let to_screen = SenderWithContext::new(SenderType::Sender(to_screen)); @@ -280,7 +279,7 @@ fn init_session( let max_panes = opts.max_panes; move || { - screen_thread_main(screen_bus, max_panes, full_screen_ws, config_options); + screen_thread_main(screen_bus, max_panes, client_attributes, config_options); } }) .unwrap(); diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs index 83e8c70f6..d9cef5def 100644 --- a/zellij-server/src/panes/grid.rs +++ b/zellij-server/src/panes/grid.rs @@ -2,6 +2,7 @@ use std::{ cmp::Ordering, collections::{BTreeSet, VecDeque}, fmt::{self, Debug, Formatter}, + str, }; use vte::{Params, Perform}; @@ -9,6 +10,7 @@ use vte::{Params, Perform}; const TABSTOP_WIDTH: usize = 8; // TODO: is this always right? const SCROLL_BACK: usize = 10_000; +use zellij_tile::data::{Palette, PaletteColor}; use zellij_utils::{consts::VERSION, logging::debug_log_to_file, shared::version_number}; use crate::panes::terminal_character::{ @@ -16,6 +18,26 @@ use crate::panes::terminal_character::{ EMPTY_TERMINAL_CHARACTER, }; +// this was copied verbatim from alacritty +fn parse_number(input: &[u8]) -> Option<u8> { + if input.is_empty() { + return None; + } + let mut num: u8 = 0; + for c in input { + let c = *c as char; + if let Some(digit) = c.to_digit(10) { + num = match num.checked_mul(10).and_then(|v| v.checked_add(digit as u8)) { + Some(v) => v, + None => return None, + } + } else { + return None; + } + } + Some(num) +} + fn get_top_non_canonical_rows(rows: &mut Vec<Row>) -> Vec<Row> { let mut index_of_last_non_canonical_row = None; for (i, row) in rows.iter().enumerate() { @@ -178,6 +200,7 @@ pub struct Grid { scroll_region: Option<(usize, usize)>, active_charset: CharsetIndex, preceding_char: Option<TerminalCharacter>, + colors: Palette, pub should_render: bool, pub cursor_key_mode: bool, // DECCKM - when set, cursor keys should send ANSI direction codes (eg. "OD") instead of the arrow keys (eg. "[D") pub erasure_mode: bool, // ERM @@ -203,7 +226,7 @@ impl Debug for Grid { } impl Grid { - pub fn new(rows: usize, columns: usize) -> Self { + pub fn new(rows: usize, columns: usize, colors: Palette) -> Self { Grid { lines_above: VecDeque::with_capacity(SCROLL_BACK), viewport: vec![Row::new().canonical()], @@ -224,6 +247,7 @@ impl Grid { clear_viewport_before_rendering: false, active_charset: Default::default(), pending_messages_to_pty: vec![], + colors, } } pub fn contains_widechar(&self) -> bool { @@ -1011,8 +1035,139 @@ impl Perform for Grid { // TBD } - fn osc_dispatch(&mut self, _params: &[&[u8]], _bell_terminated: bool) { - // TBD + fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) { + let terminator = if bell_terminated { "\x07" } else { "\x1b\\" }; + + if params.is_empty() || params[0].is_empty() { + return; + } + + match params[0] { + // Set window title. + b"0" | b"2" => { + if params.len() >= 2 { + let _title = params[1..] + .iter() + .flat_map(|x| str::from_utf8(x)) + .collect::<Vec<&str>>() + .join(";") + .trim() + .to_owned(); + // TBD: do something with title? + } + } + + // Set color index. + b"4" => { + // TBD: set color index - currently unsupported + // + // this changes a terminal color index to something else + // meaning anything set to that index will be changed + // during rendering + } + + // Get/set Foreground, Background, Cursor colors. + b"10" | b"11" | b"12" => { + if params.len() >= 2 { + if let Some(mut dynamic_code) = parse_number(params[0]) { + for param in ¶ms[1..] { + // currently only getting the color sequence is supported, + // setting still isn't + if param == b"?" { + let color_response_message = match self.colors.bg { + PaletteColor::Rgb((r, g, b)) => { + format!( + "\u{1b}]{};rgb:{1:02x}{1:02x}/{2:02x}{2:02x}/{3:02x}{3:02x}{4}", + // dynamic_code, color.r, color.g, color.b, terminator + dynamic_code, r, g, b, terminator + ) + } + _ => { + format!( + "\u{1b}]{};rgb:{1:02x}{1:02x}/{2:02x}{2:02x}/{3:02x}{3:02x}{4}", + // dynamic_code, color.r, color.g, color.b, terminator + dynamic_code, 0, 0, 0, terminator + ) + } + }; + self.pending_messages_to_pty + .push(color_response_message.as_bytes().to_vec()); + } + dynamic_code += 1; + } + return; + } + } + } + + // Set cursor style. + b"50" => { + if params.len() >= 2 + && params[1].len() >= 13 + && params[1][0..12] == *b"CursorShape=" + { + let shape = match params[1][12] as char { + '0' => Some(CursorShape::Block), + '1' => Some(CursorShape::Beam), + '2' => Some(CursorShape::Underline), + _ => None, + }; + if let Some(cursor_shape) = shape { + self.cursor.change_shape(cursor_shape); + } + } + } + + // Set clipboard. + b"52" => { + if params.len() < 3 { + return; + } + + let _clipboard = params[1].get(0).unwrap_or(&b'c'); + match params[2] { + b"?" => { + // TBD: paste from own clipboard - currently unsupported + } + _base64 => { + // TBD: copy to own clipboard - currently unsupported + } + } + } + + // Reset color index. + b"104" => { + // Reset all color indexes when no parameters are given. + if params.len() == 1 { + // TBD - reset all color changes - currently unsupported + return; + } + + // Reset color indexes given as parameters. + for param in ¶ms[1..] { + if let Some(_index) = parse_number(param) { + // TBD - reset color index - currently unimplemented + } + } + } + + // Reset foreground color. + b"110" => { + // TBD - reset foreground color - currently unimplemented + } + + // Reset background color. + b"111" => { + // TBD - reset background color - currently unimplemented + } + + // Reset text cursor color. + b"112" => { + // TBD - reset text cursor color - currently unimplemented + } + + _ => {} + } } fn csi_dispatch(&mut self, params: &Params, intermediates: &[u8], _ignore: bool, c: char) { diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs index 25834c35d..eaeb00264 100644 --- a/zellij-server/src/panes/terminal_pane.rs +++ b/zellij-server/src/panes/terminal_pane.rs @@ -1,6 +1,7 @@ use std::fmt::Debug; use std::os::unix::io::RawFd; use std::time::Instant; +use zellij_tile::data::Palette; use zellij_utils::pane_size::PositionAndSize; use crate::panes::{ @@ -27,6 +28,7 @@ pub struct TerminalPane { pub max_height: Option<usize>, pub max_width: Option<usize>, pub active_at: Instant, + pub colors: Palette, vte_parser: vte::Parser, } @@ -285,8 +287,8 @@ impl Pane for TerminalPane { } impl TerminalPane { - pub fn new(pid: RawFd, position_and_size: PositionAndSize) -> TerminalPane { - let grid = Grid::new(position_and_size.rows, position_and_size.columns); + pub fn new(pid: RawFd, position_and_size: PositionAndSize, palette: Palette) -> TerminalPane { + let grid = Grid::new(position_and_size.rows, position_and_size.columns, palette); TerminalPane { pid, grid, @@ -297,6 +299,7 @@ impl TerminalPane { max_width: None, vte_parser: vte::Parser::new(), active_at: Instant::now(), + colors: palette, } } pub fn get_x(&self) -> usize { diff --git a/zellij-server/src/panes/unit/grid_tests.rs b/zellij-server/src/panes/unit/grid_tests.rs index 1cd623b6e..7612a05d1 100644 --- a/zellij-server/src/panes/unit/grid_tests.rs +++ b/zellij-server/src/panes/unit/grid_tests.rs @@ -1,5 +1,6 @@ use super::super::Grid; use ::insta::assert_snapshot; +use zellij_tile::data::Palette; fn read_fixture(fixture_name: &str) -> Vec<u8> { let mut path_to_file = std::path::PathBuf::new(); @@ -15,7 +16,7 @@ fn read_fixture(fixture_name: &str) -> Vec<u8> { #[test] fn vttest1_0() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest1-0"; let content = read_fixture(fixture_name); for byte in content { @@ -27,7 +28,7 @@ fn vttest1_0() { #[test] fn vttest1_1() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest1-1"; let content = read_fixture(fixture_name); for byte in content { @@ -39,7 +40,7 @@ fn vttest1_1() { #[test] fn vttest1_2() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest1-2"; let content = read_fixture(fixture_name); for byte in content { @@ -51,7 +52,7 @@ fn vttest1_2() { #[test] fn vttest1_3() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest1-3"; let content = read_fixture(fixture_name); for byte in content { @@ -63,7 +64,7 @@ fn vttest1_3() { #[test] fn vttest1_4() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest1-4"; let content = read_fixture(fixture_name); for byte in content { @@ -75,7 +76,7 @@ fn vttest1_4() { #[test] fn vttest1_5() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest1-5"; let content = read_fixture(fixture_name); for byte in content { @@ -87,7 +88,7 @@ fn vttest1_5() { #[test] fn vttest2_0() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-0"; let content = read_fixture(fixture_name); for byte in content { @@ -99,7 +100,7 @@ fn vttest2_0() { #[test] fn vttest2_1() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-1"; let content = read_fixture(fixture_name); for byte in content { @@ -111,7 +112,7 @@ fn vttest2_1() { #[test] fn vttest2_2() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-2"; let content = read_fixture(fixture_name); for byte in content { @@ -123,7 +124,7 @@ fn vttest2_2() { #[test] fn vttest2_3() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-3"; let content = read_fixture(fixture_name); for byte in content { @@ -135,7 +136,7 @@ fn vttest2_3() { #[test] fn vttest2_4() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-4"; let content = read_fixture(fixture_name); for byte in content { @@ -147,7 +148,7 @@ fn vttest2_4() { #[test] fn vttest2_5() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-5"; let content = read_fixture(fixture_name); for byte in content { @@ -159,7 +160,7 @@ fn vttest2_5() { #[test] fn vttest2_6() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-6"; let content = read_fixture(fixture_name); for byte in content { @@ -171,7 +172,7 @@ fn vttest2_6() { #[test] fn vttest2_7() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-7"; let content = read_fixture(fixture_name); for byte in content { @@ -183,7 +184,7 @@ fn vttest2_7() { #[test] fn vttest2_8() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-8"; let content = read_fixture(fixture_name); for byte in content { @@ -195,7 +196,7 @@ fn vttest2_8() { #[test] fn vttest2_9() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-9"; let content = read_fixture(fixture_name); for byte in content { @@ -207,7 +208,7 @@ fn vttest2_9() { #[test] fn vttest2_10() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-10"; let content = read_fixture(fixture_name); for byte in content { @@ -219,7 +220,7 @@ fn vttest2_10() { #[test] fn vttest2_11() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-11"; let content = read_fixture(fixture_name); for byte in content { @@ -231,7 +232,7 @@ fn vttest2_11() { #[test] fn vttest2_12() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-12"; let content = read_fixture(fixture_name); for byte in content { @@ -243,7 +244,7 @@ fn vttest2_12() { #[test] fn vttest2_13() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-13"; let content = read_fixture(fixture_name); for byte in content { @@ -255,7 +256,7 @@ fn vttest2_13() { #[test] fn vttest2_14() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest2-14"; let content = read_fixture(fixture_name); for byte in content { @@ -267,7 +268,7 @@ fn vttest2_14() { #[test] fn vttest3_0() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(41, 110); + let mut grid = Grid::new(41, 110, Palette::default()); let fixture_name = "vttest3-0"; let content = read_fixture(fixture_name); for byte in content { @@ -279,7 +280,7 @@ fn vttest3_0() { #[test] fn vttest8_0() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "vttest8-0"; let content = read_fixture(fixture_name); for byte in content { @@ -291,7 +292,7 @@ fn vttest8_0() { #[test] fn vttest8_1() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "vttest8-1"; let content = read_fixture(fixture_name); for byte in content { @@ -303,7 +304,7 @@ fn vttest8_1() { #[test] fn vttest8_2() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "vttest8-2"; let content = read_fixture(fixture_name); for byte in content { @@ -315,7 +316,7 @@ fn vttest8_2() { #[test] fn vttest8_3() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "vttest8-3"; let content = read_fixture(fixture_name); for byte in content { @@ -327,7 +328,7 @@ fn vttest8_3() { #[test] fn vttest8_4() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "vttest8-4"; let content = read_fixture(fixture_name); for byte in content { @@ -339,7 +340,7 @@ fn vttest8_4() { #[test] fn vttest8_5() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "vttest8-5"; let content = read_fixture(fixture_name); for byte in content { @@ -351,7 +352,7 @@ fn vttest8_5() { #[test] fn csi_b() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "csi-b"; let content = read_fixture(fixture_name); for byte in content { @@ -363,7 +364,7 @@ fn csi_b() { #[test] fn csi_capital_i() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "csi-capital-i"; let content = read_fixture(fixture_name); for byte in content { @@ -375,7 +376,7 @@ fn csi_capital_i() { #[test] fn csi_capital_z() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "csi-capital-z"; let content = read_fixture(fixture_name); for byte in content { @@ -387,7 +388,7 @@ fn csi_capital_z() { #[test] fn terminal_reports() { let mut vte_parser = vte::Parser::new(); - let mut grid = Grid::new(51, 97); + let mut grid = Grid::new(51, 97, Palette::default()); let fixture_name = "terminal_reports"; let content = read_fixture(fixture_name); for byte in content { diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 1d25ae77c..e8ff33762 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -29,6 +29,9 @@ fn route_action(action: Action, session: &SessionMetaData, os_input: &dyn Server } Action::SwitchToMode(mode) => { let palette = os_input.load_palette(); + // TODO: use the palette from the client and remove it from the server os api + // this is left here as a stop gap measure until we shift some code around + // to allow for this session .senders .send_to_plugin(PluginInstruction::Update( @@ -199,7 +202,9 @@ pub(crate) fn route_thread_main( break; } ClientToServerMsg::Action(action) => { - route_action(action, rlocked_sessions.as_ref().unwrap(), &*os_input); + if let Some(rlocked_sessions) = rlocked_sessions.as_ref() { + route_action(action, rlocked_sessions, &*os_input); + } } ClientToServerMsg::TerminalResize(new_size) => { rlocked_sessions diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 91619c57c..178fd58e9 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -17,6 +17,7 @@ use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, PluginCapabilities, use zellij_utils::{ errors::{ContextType, ScreenContext}, input::options::Options, + ipc::ClientAttributes, pane_size::PositionAndSize, }; @@ -128,7 +129,7 @@ pub(crate) struct Screen { /// A map between this [`Screen`]'s tabs and their ID/key. tabs: BTreeMap<usize, Tab>, /// The full size of this [`Screen`]. - full_screen_ws: PositionAndSize, + position_and_size: PositionAndSize, /// The index of this [`Screen`]'s active [`Tab`]. active_tab_index: Option<usize>, mode_info: ModeInfo, @@ -140,21 +141,20 @@ impl Screen { /// Creates and returns a new [`Screen`]. pub fn new( bus: Bus<ScreenInstruction>, - full_screen_ws: &PositionAndSize, + client_attributes: &ClientAttributes, max_panes: Option<usize>, mode |