Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action QueryPaneNames to list pane names #2602

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions zellij-server/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,11 @@ pub(crate) fn route_action(
.send_to_screen(ScreenInstruction::QueryTabNames(client_id))
.with_context(err_context)?;
},
Action::QueryPaneNames => {
senders
.send_to_screen(ScreenInstruction::QueryPaneNames(client_id))
.with_context(err_context)?;
},
Action::NewTiledPluginPane(run_plugin, name) => {
senders
.send_to_screen(ScreenInstruction::NewTiledPluginPane(
Expand Down
18 changes: 18 additions & 0 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ pub enum ScreenInstruction {
PreviousSwapLayout(ClientId),
NextSwapLayout(ClientId),
QueryTabNames(ClientId),
QueryPaneNames(ClientId),
NewTiledPluginPane(RunPluginLocation, Option<String>, ClientId), // Option<String> is
// optional pane title
NewFloatingPluginPane(RunPluginLocation, Option<String>, ClientId), // Option<String> is an
Expand Down Expand Up @@ -422,6 +423,7 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenInstruction::PreviousSwapLayout(..) => ScreenContext::PreviousSwapLayout,
ScreenInstruction::NextSwapLayout(..) => ScreenContext::NextSwapLayout,
ScreenInstruction::QueryTabNames(..) => ScreenContext::QueryTabNames,
ScreenInstruction::QueryPaneNames(..) => ScreenContext::QueryPaneNames,
ScreenInstruction::NewTiledPluginPane(..) => ScreenContext::NewTiledPluginPane,
ScreenInstruction::NewFloatingPluginPane(..) => ScreenContext::NewFloatingPluginPane,
ScreenInstruction::StartOrReloadPluginPane(..) => {
Expand Down Expand Up @@ -2627,6 +2629,22 @@ pub(crate) fn screen_thread_main(
.senders
.send_to_server(ServerInstruction::Log(tab_names, client_id))?;
},
ScreenInstruction::QueryPaneNames(client_id) => {
let active_tab_id = screen.active_tab_indices.values().next().unwrap_or(&1);
let pane_names = screen
.get_indexed_tab_mut(*active_tab_id)
.map(|tab| {
tab.pane_infos()
.into_iter()
.map(|pane| format!("{}: {}", pane.id, pane.title))
.collect::<Vec<String>>()
})
.unwrap_or_else(Vec::new);
screen
.bus
.senders
.send_to_server(ServerInstruction::Log(pane_names, client_id))?;
},
ScreenInstruction::NewTiledPluginPane(run_plugin_location, pane_title, client_id) => {
let tab_index = screen.active_tab_indices.values().next().unwrap_or(&1);
let size = Size::default();
Expand Down
30 changes: 30 additions & 0 deletions zellij-server/src/unit/screen_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2530,6 +2530,36 @@ pub fn send_cli_query_tab_names_action() {
assert_snapshot!(format!("{:#?}", log_tab_names_instruction));
}

#[test]
pub fn send_cli_query_pane_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);
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_pane_names = CliAction::QueryPaneNames;
send_cli_action_to_server(&session_metadata, query_pane_names, client_id);
std::thread::sleep(std::time::Duration::from_millis(100));
mock_screen.teardown(vec![server_thread, screen_thread]);
let log_pane_names_instruction = received_server_instructions
.lock()
.unwrap()
.iter()
.find(|instruction| match instruction {
ServerInstruction::Log(..) => true,
_ => false,
})
.cloned();
assert_snapshot!(format!("{:#?}", log_pane_names_instruction));
}

#[test]
pub fn send_cli_launch_or_focus_plugin_action() {
let size = Size {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 2561
expression: "format!(\"{:#?}\", log_tab_names_instruction)"
---
Some(
Log(
[
"0: Pane #1",
],
10,
),
)
2 changes: 2 additions & 0 deletions zellij-utils/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ pub enum CliAction {
NextSwapLayout,
/// Query all tab names
QueryTabNames,
/// Query all pane names
QueryPaneNames,
StartOrReloadPlugin {
url: String,
},
Expand Down
1 change: 1 addition & 0 deletions zellij-utils/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ pub enum ScreenContext {
PreviousSwapLayout,
NextSwapLayout,
QueryTabNames,
QueryPaneNames,
NewTiledPluginPane,
StartOrReloadPluginPane,
NewFloatingPluginPane,
Expand Down
3 changes: 3 additions & 0 deletions zellij-utils/src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ pub enum Action {
NextSwapLayout,
/// Query all tab names
QueryTabNames,
/// Query all pane names
QueryPaneNames,
/// Open a new tiled (embedded, non-floating) plugin pane
NewTiledPluginPane(RunPluginLocation, Option<String>), // String is an optional name
NewFloatingPluginPane(RunPluginLocation, Option<String>), // String is an optional name
Expand Down Expand Up @@ -480,6 +482,7 @@ impl Action {
CliAction::PreviousSwapLayout => Ok(vec![Action::PreviousSwapLayout]),
CliAction::NextSwapLayout => Ok(vec![Action::NextSwapLayout]),
CliAction::QueryTabNames => Ok(vec![Action::QueryTabNames]),
CliAction::QueryPaneNames => Ok(vec![Action::QueryPaneNames]),
CliAction::StartOrReloadPlugin { url } => {
let current_dir = get_current_dir();
let run_plugin_location = RunPluginLocation::parse(&url, Some(current_dir))
Expand Down