diff options
Diffstat (limited to 'zellij-server')
-rw-r--r-- | zellij-server/src/lib.rs | 10 | ||||
-rw-r--r-- | zellij-server/src/route.rs | 6 | ||||
-rw-r--r-- | zellij-server/src/screen.rs | 15 | ||||
-rw-r--r-- | zellij-server/src/tab/mod.rs | 2 | ||||
-rw-r--r-- | zellij-server/src/unit/screen_tests.rs | 36 | ||||
-rw-r--r-- | zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_query_tab_names_action.snap | 14 |
6 files changed, 81 insertions, 2 deletions
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 5dc728fb4..34c807f16 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -77,6 +77,7 @@ pub enum ServerInstruction { AttachClient(ClientAttributes, Options, ClientId), ConnStatus(ClientId), ActiveClients(ClientId), + Log(Vec<String>, ClientId), } impl From<&ServerInstruction> for ServerContext { @@ -93,6 +94,7 @@ impl From<&ServerInstruction> for ServerContext { ServerInstruction::AttachClient(..) => ServerContext::AttachClient, ServerInstruction::ConnStatus(..) => ServerContext::ConnStatus, ServerInstruction::ActiveClients(_) => ServerContext::ActiveClients, + ServerInstruction::Log(..) => ServerContext::Log, } } } @@ -623,6 +625,14 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) { session_state ); }, + ServerInstruction::Log(lines_to_log, client_id) => { + send_to_client!( + client_id, + os_input, + ServerToClientMsg::Log(lines_to_log), + session_state + ); + }, } } diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 53ccf964d..a4ab8dcf9 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -659,6 +659,12 @@ pub(crate) fn route_action( .send_to_screen(ScreenInstruction::NextSwapLayout(client_id)) .with_context(err_context)?; }, + Action::QueryTabNames => { + session + .senders + .send_to_screen(ScreenInstruction::QueryTabNames(client_id)) + .with_context(err_context)?; + }, } Ok(should_break) } diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 97acc0fdf..a5b8b8cd0 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -248,6 +248,7 @@ pub enum ScreenInstruction { ClearPaneFrameColorOverride(Vec<PaneId>), PreviousSwapLayout(ClientId), NextSwapLayout(ClientId), + QueryTabNames(ClientId), } impl From<&ScreenInstruction> for ScreenContext { @@ -390,6 +391,7 @@ impl From<&ScreenInstruction> for ScreenContext { }, ScreenInstruction::PreviousSwapLayout(..) => ScreenContext::PreviousSwapLayout, ScreenInstruction::NextSwapLayout(..) => ScreenContext::NextSwapLayout, + ScreenInstruction::QueryTabNames(..) => ScreenContext::QueryTabNames, } } } @@ -1171,7 +1173,7 @@ impl Screen { }, c => { // It only allows printable unicode - if buf.iter().all(|u| matches!(u, 0x20..=0x7E | 0x80..=0xFF)) { + if buf.iter().all(|u| matches!(u, 0x20..=0x7E | 0xA0..=0xFF)) { active_tab.name.push_str(c); } }, @@ -2360,6 +2362,17 @@ pub(crate) fn screen_thread_main( screen.update_tabs()?; screen.unblock_input()?; }, + ScreenInstruction::QueryTabNames(client_id) => { + let tab_names = screen + .get_tabs_mut() + .values() + .map(|tab| tab.name.clone()) + .collect::<Vec<String>>(); + screen + .bus + .senders + .send_to_server(ServerInstruction::Log(tab_names, client_id))?; + }, } } Ok(()) diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index 7cdef9619..d009a3714 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -3082,7 +3082,7 @@ impl Tab { // It only allows printable unicode, delete and backspace keys. let is_updatable = buf .iter() - .all(|u| matches!(u, 0x20..=0x7E | 0x80..=0xFF | 0x08 | 0x7F)); + .all(|u| matches!(u, 0x20..=0x7E | 0xA0..=0xFF | 0x08 | 0x7F)); if is_updatable { let s = str::from_utf8(&buf).with_context(err_context)?; active_terminal.update_name(s); diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs index 8383a2462..3cde1d818 100644 --- a/zellij-server/src/unit/screen_tests.rs +++ b/zellij-server/src/unit/screen_tests.rs @@ -2674,3 +2674,39 @@ pub fn send_cli_undo_rename_tab() { *received_plugin_instructions.lock().unwrap() )) } + +#[test] +pub fn send_cli_query_tab_names_action() { + let size = Size { cols: 80, rows: 10 }; + let client_id = 10; // fake client id should not appear in the screen's state + let mut mock_screen = MockScreen::new(size); + mock_screen.new_tab(TiledPaneLayout::default()); + let session_metadata = mock_screen.clone_session_metadata(); + let screen_thread = mock_screen.run(Some(TiledPaneLayout::default())); + let received_server_instructions = Arc::new(Mutex::new(vec![])); + let server_receiver = mock_screen.server_receiver.take().unwrap(); + let server_thread = log_actions_in_thread!( + received_server_instructions, + ServerInstruction::KillSession, + server_receiver + ); + let query_tab_names = CliAction::QueryTabNames; + send_cli_action_to_server( + &session_metadata, + query_tab_names, + &mut mock_screen, + client_id, + ); + std::thread::sleep(std::time::Duration::from_millis(100)); + mock_screen.teardown(vec![server_thread, screen_thread]); + let log_tab_names_instruction = received_server_instructions + .lock() + .unwrap() + .iter() + .find(|instruction| match instruction { + ServerInstruction::Log(..) => true, + _ => false, + }) + .cloned(); + assert_snapshot!(format!("{:#?}", log_tab_names_instruction)); +} diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_query_tab_names_action.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_query_tab_names_action.snap new file mode 100644 index 000000000..bdaf546fe --- /dev/null +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_query_tab_names_action.snap @@ -0,0 +1,14 @@ +--- +source: zellij-server/src/./unit/screen_tests.rs +assertion_line: 2713 +expression: "format!(\"{:#?}\", log_tab_names_action)" +--- +Some( + Log( + [ + "Tab #1", + "Tab #2", + ], + 10, + ), +) |