summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/tab
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-10-05 07:44:00 +0200
committerGitHub <noreply@github.com>2022-10-05 07:44:00 +0200
commit79bf6ab868cbdab1f9a3827c9b70198f54548b44 (patch)
tree2d6fc4c1d8a79ebd727a1a5f8b6406617dd0de55 /zellij-server/src/tab
parent917e9b2ff0f583183c0155060d243afd295770b9 (diff)
feat(config): switch to kdl (#1759)
* chore(config): default kdl keybindings config * tests * work * refactor(config): move stuff around * work * tab merge layout * work * work * layouts working * work * layout tests * work * work * feat(parsing): kdl layouts without config * refactor(kdl): move stuff around * work * tests(layout): add cases and fix bugs * work * fix(kdl): various bugs * chore(layouts): move all layouts to kdl * feat(kdl): shared keybidns * fix(layout): do not count fixed panes toward percentile * fix(keybinds): missing keybinds and actions * fix(config): adjust default tips * refactor(config): move stuff around * fix(tests): make e2e tests pass * fix(kdl): add verbose parsing errors * fix(kdl): focused tab * fix(layout): corret default_tab_template behavior * style(code): fix compile warnings * feat(cli): send actions through the cli * fix(cli): exit only when action is done * fix(cli): open embedded pane from floating pane * fix(cli): send actions to other sessions * feat(cli): command alias * feat(converter): convert old config * feat(converter): convert old layout and theme files * feat(kdl): pretty errors * feat(client): convert old YAML files on startup * fix: various bugs and styling issues * fix: e2e tests * fix(screen): propagate errors after merge * style(clippy): lower clippy level * fix(tests): own session_name variable * style(fmt): rustfmt * fix(cli): various action fixes * style(fmt): rustfmt * fix(themes): loading of theme files * style(fmt): rustfmt * fix(tests): theme fixtures * fix(layouts): better errors on unknown nodes * fix(kdl): clarify valid node terminator error * fix(e2e): adjust close tab test * fix(e2e): adjust close tab test again * style(code): cleanup some comments
Diffstat (limited to 'zellij-server/src/tab')
-rw-r--r--zellij-server/src/tab/mod.rs22
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_basic_layout.snap26
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_nested_layout.snap26
-rw-r--r--zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_nested_uneven_layout.snap26
-rw-r--r--zellij-server/src/tab/unit/tab_integration_tests.rs173
-rw-r--r--zellij-server/src/tab/unit/tab_tests.rs17
6 files changed, 255 insertions, 35 deletions
diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs
index 31f3fa1c7..883caf0d1 100644
--- a/zellij-server/src/tab/mod.rs
+++ b/zellij-server/src/tab/mod.rs
@@ -40,7 +40,7 @@ use zellij_utils::{
data::{Event, InputMode, ModeInfo, Palette, PaletteColor, Style},
input::{
command::TerminalAction,
- layout::{Layout, Run},
+ layout::{PaneLayout, Run},
parse_keys,
},
pane_size::{Offset, PaneGeom, Size, SizeInPixels, Viewport},
@@ -454,7 +454,7 @@ impl Tab {
pub fn apply_layout(
&mut self,
- layout: Layout,
+ layout: PaneLayout,
new_pids: Vec<RawFd>,
tab_index: usize,
client_id: ClientId,
@@ -478,7 +478,7 @@ impl Tab {
let mut new_pids = new_pids.iter();
let mut focus_pane_id: Option<PaneId> = None;
- let mut set_focus_pane_id = |layout: &Layout, pane_id: PaneId| {
+ let mut set_focus_pane_id = |layout: &PaneLayout, pane_id: PaneId| {
if layout.focus.unwrap_or(false) && focus_pane_id.is_none() {
focus_pane_id = Some(pane_id);
}
@@ -498,7 +498,7 @@ impl Tab {
*position_and_size,
self.senders.to_plugin.as_ref().unwrap().clone(),
pane_title,
- layout.pane_name.clone().unwrap_or_default(),
+ layout.name.clone().unwrap_or_default(),
);
new_plugin.set_borderless(layout.borderless);
self.tiled_panes
@@ -513,7 +513,7 @@ impl Tab {
*position_and_size,
self.style,
next_terminal_position,
- layout.pane_name.clone().unwrap_or_default(),
+ layout.name.clone().unwrap_or_default(),
self.link_handler.clone(),
self.character_cell_size.clone(),
self.sixel_image_store.clone(),
@@ -734,6 +734,14 @@ impl Tab {
}
self.set_force_render();
}
+ pub fn show_floating_panes(&mut self) {
+ self.floating_panes.toggle_show_panes(true);
+ self.set_force_render();
+ }
+ pub fn hide_floating_panes(&mut self) {
+ self.floating_panes.toggle_show_panes(false);
+ self.set_force_render();
+ }
pub fn new_pane(&mut self, pid: PaneId, client_id: Option<ClientId>) {
self.close_down_to_max_terminals();
if self.floating_panes.panes_are_visible() {
@@ -2036,7 +2044,6 @@ impl Tab {
position_on_screen: &Position,
client_id: ClientId,
) -> bool {
- println!("mouse hold middle");
// return value indicates whether we should trigger a render
// determine if event is repeated to enable smooth scrolling
let is_repeated = if let Some(last_position) = self.last_mouse_hold_position {
@@ -2044,13 +2051,11 @@ impl Tab {
} else {
false
};
- println!("is repeated: {:?}", is_repeated);
self.last_mouse_hold_position = Some(*position_on_screen);
let active_pane = self.get_active_pane_or_floating_pane_mut(client_id);
if let Some(active_pane) = active_pane {
- println!("can have active pane");
let mut relative_position = active_pane.relative_position(position_on_screen);
if !is_repeated {
relative_position.change_column(
@@ -2066,7 +2071,6 @@ impl Tab {
);
if let Some(mouse_event) = active_pane.mouse_middle_click(&relative_position, true)
{
- log::info!("can have mouse event: {:?}", mouse_event);
self.write_to_active_terminal(mouse_event.into_bytes(), client_id);
return true; // we need to re-render in this case so the selection disappears
}
diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_basic_layout.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_basic_layout.snap
new file mode 100644
index 000000000..2a3dc369a
--- /dev/null
+++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_basic_layout.snap
@@ -0,0 +1,26 @@
+---
+source: zellij-server/src/tab/./unit/tab_integration_tests.rs
+assertion_line: 2130
+expression: snapshot
+---
+00 (C): ┌ Pane #1 ──────────────────────────────────────────────────┐┌ Pane #2 ─────────────────────────────────────────────────┐
+01 (C): │ ││ │
+02 (C): │ ││ │
+03 (C): │ ││ │
+04 (C): │ ││ │
+05 (C): │ ││ │
+06 (C): │ ││ │
+07 (C): │ ││ │
+08 (C): │ ││ │
+09 (C): │ │└──────────────────────────────────────────────────────────┘
+10 (C): │ │┌ Pane #3 ─────────────────────────────────────────────────┐
+11 (C): │ ││ │
+12 (C): │ ││ │
+13 (C): │ ││ │
+14 (C): │ ││ │
+15 (C): │ ││ │
+16 (C): │ ││ │
+17 (C): │ ││ │
+18 (C): │ ││ │
+19 (C): └───────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
+
diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_nested_layout.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_nested_layout.snap
new file mode 100644
index 000000000..2d185efe2
--- /dev/null
+++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_nested_layout.snap
@@ -0,0 +1,26 @@
+---
+source: zellij-server/src/tab/./unit/tab_integration_tests.rs
+assertion_line: 2170
+expression: snapshot
+---
+00 (C): ┌ Pane #1 ──────────────────────────────┐┌ Pane #2 ─────────────────────────────┐┌ Pane #6 ─────────────────────────────┐
+01 (C): │ ││ ││ │
+02 (C): │ ││ ││ │
+03 (C): │ ││ ││ │
+04 (C): │ ││ ││ │
+05 (C): │ ││ ││ │
+06 (C): │ ││ ││ │
+07 (C): │ ││ ││ │
+08 (C): │ ││ ││ │
+09 (C): │ │└──────────────────────────────────────┘│ │
+10 (C): │ │┌ Pane #3 ───┐┌ Pane #4 ──┐┌ Pane #5 ──┐│ │
+11 (C): │ ││ ││ ││ ││ │
+12 (C): │ ││ ││ ││ ││ │
+13 (C): │ ││ ││ ││ ││ │
+14 (C): │ ││ ││ ││ ││ │
+15 (C): │ ││ ││ ││ ││ │
+16 (C): │ ││ ││ ││ ││ │
+17 (C): │ ││ ││ ││ ││ │
+18 (C): │ ││ ││ ││ ││ │
+19 (C): └───────────────────────────────────────┘└────────────┘└───────────┘└───────────┘└──────────────────────────────────────┘
+
diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_nested_uneven_layout.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_nested_uneven_layout.snap
new file mode 100644
index 000000000..6ac556ba9
--- /dev/null
+++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__tab_with_nested_uneven_layout.snap
@@ -0,0 +1,26 @@
+---
+source: zellij-server/src/tab/./unit/tab_integration_tests.rs
+assertion_line: 2204
+expression: snapshot
+---
+00 (C): ┌ Pane #1 ──────────────────────────────────────────────────┐┌ Pane #2 ─────────────────────────────────────────────────┐
+01 (C): │ ││ │
+02 (C): │ ││ │
+03 (C): │ ││ │
+04 (C): │ │└──────────────────────────────────────────────────────────┘
+05 (C): │ │┌ Pane #3 ─────────────────────────────────────────────────┐
+06 (C): │ ││ │
+07 (C): │ ││ │
+08 (C): │ ││ │
+09 (C): └───────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
+10 (C): ┌ Pane #4 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
+11 (C): │ │
+12 (C): │ │
+13 (C): │ │
+14 (C): │ │
+15 (C): │ │
+16 (C): │ │
+17 (C): │ │
+18 (C): │ │
+19 (C): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
+
diff --git a/zellij-server/src/tab/unit/tab_integration_tests.rs b/zellij-server/src/tab/unit/tab_integration_tests.rs
index 14a9c9e17..3b26bc26e 100644
--- a/zellij-server/src/tab/unit/tab_integration_tests.rs
+++ b/zellij-server/src/tab/unit/tab_integration_tests.rs
@@ -9,12 +9,11 @@ use crate::{
thread_bus::ThreadSenders,
ClientId,
};
-use std::convert::TryInto;
use std::path::PathBuf;
use zellij_utils::channels::Receiver;
use zellij_utils::envs::set_session_name;
use zellij_utils::errors::ErrorContext;
-use zellij_utils::input::layout::LayoutTemplate;
+use zellij_utils::input::layout::{Layout, PaneLayout};
use zellij_utils::ipc::IpcReceiverWithContext;
use zellij_utils::pane_size::{Size, SizeInPixels};
use zellij_utils::position::Position;
@@ -213,12 +212,62 @@ fn create_new_tab(size: Size, default_mode: ModeInfo) -> Tab {
terminal_emulator_colors,
terminal_emulator_color_codes,
);
- tab.apply_layout(
- LayoutTemplate::default().try_into().unwrap(),
- vec![1],
+ tab.apply_layout(PaneLayout::default(), vec![1], index, client_id);
+ tab
+}
+
+fn create_new_tab_with_layout(size: Size, default_mode: ModeInfo, layout: &str) -> Tab {
+ set_session_name("test".into());
+ let index = 0;
+ let position = 0;
+ let name = String::new();
+ let os_api = Box::new(FakeInputOutput {
+ file_dumps: Arc::new(Mutex::new(HashMap::new())),
+ });
+ let senders = ThreadSenders::default().silently_fail_on_send();
+ let max_panes = None;
+ let mode_info = default_mode;
+ let style = Style::default();
+ let draw_pane_frames = true;
+ let client_id = 1;
+ let session_is_mirrored = true;
+ let mut connected_clients = HashSet::new();
+ connected_clients.insert(client_id);
+ let connected_clients = Rc::new(RefCell::new(connected_clients));
+ let character_cell_info = Rc::new(RefCell::new(None));
+ let terminal_emulator_colors = Rc::new(RefCell::new(Palette::default()));
+ let copy_options = CopyOptions::default();
+ let terminal_emulator_color_codes = Rc::new(RefCell::new(HashMap::new()));
+ let sixel_image_store = Rc::new(RefCell::new(SixelImageStore::default()));
+ let layout = Layout::from_str(layout, "layout_file_name".into()).unwrap();
+ let tab_layout = layout.new_tab();
+ let mut tab = Tab::new(
index,
+ position,
+ name,
+ size,
+ character_cell_info,
+ sixel_image_store,
+ os_api,
+ senders,
+ max_panes,
+ style,
+ mode_info,
+ draw_pane_frames,
+ connected_clients,
+ session_is_mirrored,
client_id,
+ copy_options,
+ terminal_emulator_colors,
+ terminal_emulator_color_codes,
);
+ let pane_ids = tab_layout
+ .extract_run_instructions()
+ .iter()
+ .enumerate()
+ .map(|(i, _)| i as i32)
+ .collect();
+ tab.apply_layout(tab_layout, pane_ids, index, client_id);
tab
}
@@ -271,7 +320,8 @@ fn create_new_tab_with_mock_pty_writer(
terminal_emulator_color_codes,
);
tab.apply_layout(
- LayoutTemplate::default().try_into().unwrap(),
+ // LayoutTemplate::default().try_into().unwrap(),
+ PaneLayout::default(),
vec![1],
index,
client_id,
@@ -329,12 +379,7 @@ fn create_new_tab_with_sixel_support(
terminal_emulator_colors,
terminal_emulator_color_codes,
);
- tab.apply_layout(
- LayoutTemplate::default().try_into().unwrap(),
- vec![1],
- index,
- client_id,
- );
+ tab.apply_layout(PaneLayout::default(), vec![1], index, client_id);
tab
}
@@ -2051,6 +2096,110 @@ fn pane_in_utf8_normal_event_tracking_mouse_mode() {
}
#[test]
+fn tab_with_basic_layout() {
+ let layout = r#"
+ layout {
+ pane split_direction="Vertical" {
+ pane
+ pane split_direction="Horizontal" {
+ pane
+ pane
+ }
+ }
+ }
+ "#;
+ let size = Size {
+ cols: 121,
+ rows: 20,
+ };
+ let client_id = 1;
+ let mut tab = create_new_tab_with_layout(size, ModeInfo::default(), layout);
+ let mut output = Output::default();
+ tab.render(&mut output, None);
+ let snapshot = take_snapshot(
+ output.serialize().get(&client_id).unwrap(),
+ size.rows,
+ size.cols,
+ Palette::default(),
+ );
+ assert_snapshot!(snapshot);
+}
+
+#[test]
+fn tab_with_nested_layout() {
+ let layout = r#"
+ layout {
+ pane_template name="top-and-vertical-sandwich" {
+ pane
+ vertical-sandwich {
+ pane
+ }
+ }
+ pane_template name="vertical-sandwich" split_direction="vertical" {
+ pane
+ children
+ pane
+ }
+ pane_template name="nested-vertical-sandwich" split_direction="vertical" {
+ pane
+ top-and-vertical-sandwich
+ pane
+ }
+ nested-vertical-sandwich
+ }
+ "#;
+ let size = Size {
+ cols: 121,
+ rows: 20,
+ };
+ let client_id = 1;
+ let mut tab = create_new_tab_with_layout(size, ModeInfo::default(), layout);
+ let mut output = Output::default();
+ tab.render(&mut output, None);
+ let snapshot = take_snapshot(
+ output.serialize().get(&client_id).unwrap(),
+ size.rows,
+ size.cols,
+ Palette::default(),
+ );
+ assert_snapshot!(snapshot);
+}
+
+#[test]
+fn tab_with_nested_uneven_layout() {
+ let layout = r#"
+ layout {
+ pane_template name="horizontal-with-vertical-top" {
+ pane split_direction="Vertical" {
+ pane
+ children
+ }
+ pane
+ }
+ horizontal-with-vertical-top name="my tab" {
+ pane
+ pane
+ }
+ }
+ "#;
+ let size = Size {
+ cols: 121,
+ rows: 20,
+ };
+ let client_id = 1;
+ let mut tab = create_new_tab_with_layout(size, ModeInfo::default(), layout);
+ let mut output = Output::default();
+ tab.render(&mut output, None);
+ let snapshot = take_snapshot(
+ output.serialize().get(&client_id).unwrap(),
+ size.rows,
+ size.cols,
+ Palette::default(),
+ );
+ assert_snapshot!(snapshot);
+}
+
+#[test]
fn pane_bracketed_paste_ignored_when_not_in_bracketed_paste_mode() {
// regression test for: https://github.com/zellij-org/zellij/issues/1687
let size = Size {
diff --git a/zellij-server/src/tab/unit/tab_tests.rs b/zellij-server/src/tab/unit/tab_tests.rs
index 8a3072500..60604b004 100644
--- a/zellij-server/src/tab/unit/tab_tests.rs
+++ b/zellij-server/src/tab/unit/tab_tests.rs
@@ -7,9 +7,8 @@ use crate::{
thread_bus::ThreadSenders,
ClientId,
};
-use std::convert::TryInto;
use std::path::PathBuf;
-use zellij_utils::input::layout::LayoutTemplate;
+use zellij_utils::input::layout::PaneLayout;
use zellij_utils::ipc::IpcReceiverWithContext;
use zellij_utils::pane_size::{Size, SizeInPixels};
@@ -132,12 +131,7 @@ fn create_new_tab(size: Size) -> Tab {
terminal_emulator_colors,
terminal_emulator_color_codes,
);
- tab.apply_layout(
- LayoutTemplate::default().try_into().unwrap(),
- vec![1],
- index,
- client_id,
- );
+ tab.apply_layout(PaneLayout::default(), vec![1], index, client_id);
tab
}
@@ -183,12 +177,7 @@ fn create_new_tab_with_cell_size(
terminal_emulator_colors,
terminal_emulator_color_codes,
);
- tab.apply_layout(
- LayoutTemplate::default().try_into().unwrap(),
- vec![1],
- index,
- client_id,
- );
+ tab.apply_layout(PaneLayout::default(), vec![1], index, client_id);
tab
}