Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeheonji committed Sep 28, 2021
2 parents 106532a + 9227ff0 commit 90b9ab9
Show file tree
Hide file tree
Showing 25 changed files with 870 additions and 323 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* Feature: Add ability to solely specify the tab name in the `tabs` section (https://github.com/zellij-org/zellij/pull/722)
* Feature: Plugins can be configured and the groundwork for "Headless" plugins has been laid (https://github.com/zellij-org/zellij/pull/660)
* Automatically update `example/default.yaml` on release (https://github.com/zellij-org/zellij/pull/736)
* Feature: allow mirroring sessions in multiple terminal windows (https://github.com/zellij-org/zellij/pull/740)
* Feature: display a message when the current pane is in full-screen (https://github.com/zellij-org/zellij/pull/450)

## [0.17.0] - 2021-09-15
* New panes/tabs now open in CWD of focused pane (https://github.com/zellij-org/zellij/pull/691)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ args = ["build", "--verbose", "--release", "--target", "${CARGO_MAKE_TASK_ARGS}"
workspace = false
dependencies = ["build-plugins", "build-dev-data-dir"]
command = "cargo"
args = ["build", "--verbose", "--target", "x86_64-unknown-linux-musl"]
args = ["build", "--verbose", "--release", "--target", "x86_64-unknown-linux-musl"]

# Run e2e tests - we mark the e2e tests as "ignored" so they will not be run with the normal ones
[tasks.e2e-test]
Expand Down
62 changes: 56 additions & 6 deletions default-plugins/status-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ use zellij_tile::prelude::*;
use zellij_tile_utils::style;

use first_line::{ctrl_keys, superkey};
use second_line::{keybinds, text_copied_hint};
use second_line::{
fullscreen_panes_to_hide, keybinds, locked_fullscreen_panes_to_hide, text_copied_hint,
};

// for more of these, copy paste from: https://en.wikipedia.org/wiki/Box-drawing_character
static ARROW_SEPARATOR: &str = "";
static MORE_MSG: &str = " ... ";

#[derive(Default)]
struct State {
tabs: Vec<TabInfo>,
mode_info: ModeInfo,
diplay_text_copied_hint: bool,
}
Expand Down Expand Up @@ -137,6 +140,7 @@ impl ZellijPlugin for State {
set_selectable(false);
subscribe(&[
EventType::ModeUpdate,
EventType::TabUpdate,
EventType::CopyToClipboard,
EventType::InputReceived,
]);
Expand All @@ -147,6 +151,9 @@ impl ZellijPlugin for State {
Event::ModeUpdate(mode_info) => {
self.mode_info = mode_info;
}
Event::TabUpdate(tabs) => {
self.tabs = tabs;
}
Event::CopyToClipboard => {
self.diplay_text_copied_hint = true;
}
Expand All @@ -173,11 +180,54 @@ impl ZellijPlugin for State {
);

let first_line = format!("{}{}", superkey, ctrl_keys);
let second_line = if self.diplay_text_copied_hint {
text_copied_hint(&self.mode_info.palette)
} else {
keybinds(&self.mode_info, cols)
};

let mut second_line = LinePart::default();
for t in self.tabs.iter_mut() {
if t.active {
match self.mode_info.mode {
InputMode::Normal => {
if t.is_fullscreen_active {
second_line = if self.diplay_text_copied_hint {
text_copied_hint(&self.mode_info.palette)
} else {
fullscreen_panes_to_hide(&self.mode_info.palette, t.panes_to_hide)
}
} else {
second_line = if self.diplay_text_copied_hint {
text_copied_hint(&self.mode_info.palette)
} else {
keybinds(&self.mode_info, cols)
}
}
}
InputMode::Locked => {
if t.is_fullscreen_active {
second_line = if self.diplay_text_copied_hint {
text_copied_hint(&self.mode_info.palette)
} else {
locked_fullscreen_panes_to_hide(
&self.mode_info.palette,
t.panes_to_hide,
)
}
} else {
second_line = if self.diplay_text_copied_hint {
text_copied_hint(&self.mode_info.palette)
} else {
keybinds(&self.mode_info, cols)
}
}
}
_ => {
second_line = if self.diplay_text_copied_hint {
text_copied_hint(&self.mode_info.palette)
} else {
keybinds(&self.mode_info, cols)
}
}
}
}
}

// [48;5;238m is gray background, [0K is so that it fills the rest of the line
// [m is background reset, [0K is so that it clears the rest of the line
Expand Down
79 changes: 79 additions & 0 deletions default-plugins/status-bar/src/second_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,82 @@ pub fn text_copied_hint(palette: &Palette) -> LinePart {
len: hint.len(),
}
}

pub fn fullscreen_panes_to_hide(palette: &Palette, panes_to_hide: usize) -> LinePart {
let white_color = match palette.white {
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
PaletteColor::EightBit(color) => Fixed(color),
};
let green_color = match palette.green {
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
PaletteColor::EightBit(color) => Fixed(color),
};
let orange_color = match palette.orange {
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
PaletteColor::EightBit(color) => Fixed(color),
};
let shortcut_left_separator = Style::new().fg(white_color).bold().paint(" (");
let shortcut_right_separator = Style::new().fg(white_color).bold().paint("): ");
let fullscreen = "FULLSCREEN";
let puls = "+ ";
let panes = panes_to_hide.to_string();
let hide = " hidden panes";
let len = fullscreen.chars().count()
+ puls.chars().count()
+ panes.chars().count()
+ hide.chars().count()
+ 5; // 3 for ():'s around shortcut, 2 for the space
LinePart {
part: format!(
"{}{}{}{}{}{}",
shortcut_left_separator,
Style::new().fg(orange_color).bold().paint(fullscreen),
shortcut_right_separator,
Style::new().fg(white_color).bold().paint(puls),
Style::new().fg(green_color).bold().paint(panes),
Style::new().fg(white_color).bold().paint(hide)
),
len,
}
}

pub fn locked_fullscreen_panes_to_hide(palette: &Palette, panes_to_hide: usize) -> LinePart {
let white_color = match palette.white {
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
PaletteColor::EightBit(color) => Fixed(color),
};
let green_color = match palette.green {
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
PaletteColor::EightBit(color) => Fixed(color),
};
let orange_color = match palette.orange {
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
PaletteColor::EightBit(color) => Fixed(color),
};
let locked_text = " -- INTERFACE LOCKED -- ";
let shortcut_left_separator = Style::new().fg(white_color).bold().paint(" (");
let shortcut_right_separator = Style::new().fg(white_color).bold().paint("): ");
let fullscreen = "FULLSCREEN";
let puls = "+ ";
let panes = panes_to_hide.to_string();
let hide = " hidden panes";
let len = locked_text.chars().count()
+ fullscreen.chars().count()
+ puls.chars().count()
+ panes.chars().count()
+ hide.chars().count()
+ 5; // 3 for ():'s around shortcut, 2 for the space
LinePart {
part: format!(
"{}{}{}{}{}{}{}",
Style::new().fg(white_color).bold().paint(locked_text),
shortcut_left_separator,
Style::new().fg(orange_color).bold().paint(fullscreen),
shortcut_right_separator,
Style::new().fg(white_color).bold().paint(puls),
Style::new().fg(green_color).bold().paint(panes),
Style::new().fg(white_color).bold().paint(hide)
),
len,
}
}
15 changes: 3 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub fn main() {
};
if let Some(Command::Sessions(Sessions::Attach {
session_name,
force,
create,
options,
})) = opts.command.clone()
Expand All @@ -108,22 +107,14 @@ pub fn main() {
(ClientInfo::New(session_name.unwrap()), layout)
} else {
(
ClientInfo::Attach(
session_name.unwrap(),
force,
config_options.clone(),
),
ClientInfo::Attach(session_name.unwrap(), config_options.clone()),
None,
)
}
} else {
assert_session(session);
(
ClientInfo::Attach(
session_name.unwrap(),
force,
config_options.clone(),
),
ClientInfo::Attach(session_name.unwrap(), config_options.clone()),
None,
)
}
Expand All @@ -141,7 +132,7 @@ pub fn main() {
}
}
ActiveSession::One(session_name) => (
ClientInfo::Attach(session_name, force, config_options.clone()),
ClientInfo::Attach(session_name, config_options.clone()),
None,
),
ActiveSession::Many => {
Expand Down
96 changes: 85 additions & 11 deletions src/tests/e2e/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,12 @@ pub fn cannot_split_terminals_vertically_when_active_terminal_is_too_small() {
},
})
.add_step(Step {
name: "Send text to terminal",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
// this is just normal input that should be sent into the one terminal so that we can make
// sure we silently failed to split in the previous step
remote_terminal.send_key("Hi!".as_bytes());
true
},
})
.add_step(Step {
name: "Wait for text to appear",
name: "Make sure only one pane appears",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(6, 2) && remote_terminal.snapshot_contains("Hi!")
if remote_terminal.cursor_position_is(3, 2) && remote_terminal.snapshot_contains("...")
{
// ... is the truncated tip line
step_is_complete = true;
}
step_is_complete
Expand Down Expand Up @@ -917,3 +909,85 @@ pub fn start_without_pane_frames() {
.run_all_steps();
assert_snapshot!(last_snapshot);
}

#[test]
#[ignore]
pub fn mirrored_sessions() {
let fake_win_size = Size {
cols: 120,
rows: 24,
};
let mut test_attempts = 10;
let session_name = "mirrored_sessions";
let mut last_snapshot = None;
loop {
// we run this test in a loop because there are some edge cases (especially in the CI)
// where the second runner times out and then we also need to restart the first runner
// if no test timed out, we break the loop and assert the snapshot
let mut first_runner =
RemoteRunner::new_with_session_name("mirrored_sessions", fake_win_size, session_name)
.add_step(Step {
name: "Split pane to the right",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.status_bar_appears()
&& remote_terminal.cursor_position_is(3, 2)
{
remote_terminal.send_key(&PANE_MODE);
remote_terminal.send_key(&SPLIT_RIGHT_IN_PANE_MODE);
// back to normal mode after split
remote_terminal.send_key(&ENTER);
step_is_complete = true;
}
step_is_complete
},
})
.add_step(Step {
name: "Wait for new pane to open",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(63, 2)
&& remote_terminal.tip_appears()
{
// cursor is in the newly opened second pane
step_is_complete = true;
}
step_is_complete
},
});
first_runner.run_all_steps();

let mut second_runner =
RemoteRunner::new_existing_session("mirrored_sessions", fake_win_size, session_name)
.add_step(Step {
name: "Make sure session appears correctly",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(63, 2)
&& remote_terminal.tip_appears()
{
// cursor is in the newly opened second pane
step_is_complete = true;
}
step_is_complete
},
});
let last_test_snapshot = second_runner.run_all_steps();

if (first_runner.test_timed_out || second_runner.test_timed_out) && test_attempts >= 0 {
test_attempts -= 1;
continue;
} else {
last_snapshot = Some(last_test_snapshot);
break;
}
}
match last_snapshot {
Some(last_snapshot) => {
assert_snapshot!(last_snapshot);
}
None => {
panic!("test timed out before completing");
}
}
}
Loading

0 comments on commit 90b9ab9

Please sign in to comment.