Skip to content

Commit

Permalink
feat(panes): Add an option to press <ESC> and drop to shell in comman…
Browse files Browse the repository at this point in the history
…d panes (#2872)

* feat(panes): ESC to drop to default shell on command panes

* style(fmt): rustfmt
  • Loading branch information
imsnif authored Oct 17, 2023
1 parent 8378f14 commit 69eb904
Show file tree
Hide file tree
Showing 21 changed files with 194 additions and 82 deletions.
8 changes: 4 additions & 4 deletions src/tests/e2e/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ pub fn send_command_through_the_cli() {
// so when we press "Enter", it will run again and we'll see two "foo"s one after the other,
// that's how we know the whole flow is working
let fake_win_size = Size {
cols: 120,
cols: 150,
rows: 24,
};
let mut test_attempts = 10;
Expand Down Expand Up @@ -2118,7 +2118,7 @@ pub fn send_command_through_the_cli() {
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.snapshot_contains("<Ctrl-c>")
&& remote_terminal.cursor_position_is(61, 3)
&& remote_terminal.cursor_position_is(76, 3)
{
remote_terminal.send_key(&SPACE); // re-run script - here we use SPACE
// instead of the default ENTER because
Expand All @@ -2135,7 +2135,7 @@ pub fn send_command_through_the_cli() {
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.snapshot_contains("<Ctrl-c>")
&& remote_terminal.cursor_position_is(61, 4)
&& remote_terminal.cursor_position_is(76, 4)
{
step_is_complete = true
}
Expand All @@ -2149,7 +2149,7 @@ pub fn send_command_through_the_cli() {
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.snapshot_contains("foo")
&& remote_terminal.cursor_position_is(61, 4)
&& remote_terminal.cursor_position_is(76, 4)
{
step_is_complete = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ expression: last_snapshot
│ │ │ │ │────────────────────────────┘
│ │ │ Waiting to run: top │ │────────────────────────────┐
│ │ │ │ │ │
│ │ │ <ENTER> to run, <Ctrl-c> to exit │ │ │
│ │ │ <ENTER> run, <ESC> drop to shell, <Ctrl-c> exit │ │ │
│ └─│ │ │ │
│ │ │ │ │
│ └─ <ENTER> to run, <Ctrl-c> to exit ─────────────────────┘ │ │
│ └─ <ENTER> run, <ESC> drop to shell, <Ctrl-c> exit ──────┘ │ │
│ │ │ │
│ └────────────────────────────────────────────────────────┘ │
│ ││ │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ expression: last_snapshot
│ │ │ │ │────────────────────────────┘
│ │ │ Waiting to run: top │ │────────────────────────────┐
│ │ │ │ │ │
│ │ │ <ENTER> to run, <Ctrl-c> to exit │ │ │
│ │ │ <ENTER> run, <ESC> drop to shell, <Ctrl-c> exit │ │ │
│ └─│ │ │ │
│ │ │ │ │
│ └─ <ENTER> to run, <Ctrl-c> to exit ─────────────────────┘ │ │
│ └─ <ENTER> run, <ESC> drop to shell, <Ctrl-c> exit ──────┘ │ │
│ │ │ │
│ └────────────────────────────────────────────────────────┘ │
│ ││ │
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 2031
assertion_line: 2175
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1
Pane #1 ─────────────────────────────────────────────────┐┌ /usr/src/zellij/fixtures/append-echo-script.sh ──────────┐
$ /usr/src/zellij/x86_64-unknown-linux-musl/release/zellij││foo
run -s -- "/usr/src/zellij/fixtures/append-echo-script.sh││foo
" ││█
$ ││
││
││
││
││
││
││
││
││
││
││
││
││
││
││
││
└──────────────────────────────────────────────────────────┘└ [ EXIT CODE: 0 ] <ENTER> to re-run, <Ctrl-c> to exit ────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
Tip: Alt + <n> => new pane. Alt + <←↓↑→> or Alt + <hjkl> => navigate. Alt + <+|-> => resize pane.
Pane #1 ────────────────────────────────────────────────────────────────┐┌ /usr/src/zellij/fixtures/append-echo-script.sh ─────────────────────────┐
$ /usr/src/zellij/x86_64-unknown-linux-musl/release/zellij run -s -- "/us││foo
r/src/zellij/fixtures/append-echo-script.sh" ││foo
$ ││█
││
││
││
││
││
││
││
││
││
││
││
││
││
││
││
││
└─────────────────────────────────────────────────────────────────────────┘└ [ EXIT CODE: 0 ] <ENTER> re-run, <ESC> drop to shell, <Ctrl-c> exit ────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT  Alt + <[]>  VERTICAL 
Tip: Alt + <n> => open new pane. Alt + <←↓↑→> or Alt + <hjkl> => navigate between panes. Alt + <+|-> => increase/decrease pane size.
22 changes: 5 additions & 17 deletions zellij-server/src/os_input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use zellij_utils::{
};

use std::{
collections::{BTreeMap, HashMap, HashSet},
collections::{BTreeMap, BTreeSet, HashMap},
env,
fs::File,
io::Write,
Expand Down Expand Up @@ -581,21 +581,15 @@ impl ServerOsApi for ServerOsInputOutput {
.with_context(err_context)?;
let mut terminal_id = None;
{
let current_ids: HashSet<u32> = self
let current_ids: BTreeSet<u32> = self
.terminal_id_to_raw_fd
.lock()
.to_anyhow()
.with_context(err_context)?
.keys()
.copied()
.collect();
for i in 0..u32::MAX {
let i = i as u32;
if !current_ids.contains(&i) {
terminal_id = Some(i);
break;
}
}
terminal_id = current_ids.last().map(|l| l + 1).or(Some(0));
}
match terminal_id {
Some(terminal_id) => {
Expand Down Expand Up @@ -628,21 +622,15 @@ impl ServerOsApi for ServerOsInputOutput {

let mut terminal_id = None;
{
let current_ids: HashSet<u32> = self
let current_ids: BTreeSet<u32> = self
.terminal_id_to_raw_fd
.lock()
.to_anyhow()
.with_context(err_context)?
.keys()
.copied()
.collect();
for i in 0..u32::MAX {
let i = i as u32;
if !current_ids.contains(&i) {
terminal_id = Some(i);
break;
}
}
terminal_id = current_ids.last().map(|l| l + 1).or(Some(0));
}
match terminal_id {
Some(terminal_id) => {
Expand Down
32 changes: 24 additions & 8 deletions zellij-server/src/panes/terminal_character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,21 +773,25 @@ pub fn render_first_run_banner(

let controls_bare_text_first_part = "<";
let enter_bare_text = "ENTER";
let controls_bare_text_second_part = "> to run, <";
let controls_bare_text_second_part = "> run, <";
let esc_bare_text = "ESC";
let controls_bare_text_third_part = "> drop to shell, <";
let ctrl_c_bare_text = "Ctrl-c";
let controls_bare_text_third_part = "> to exit";
let controls_bare_text_fourth_part = "> exit";
let controls_color = RESET_STYLES
.foreground(Some(AnsiCode::from(style.colors.orange)))
.bold(Some(AnsiCode::On));
let controls_line_length = controls_bare_text_first_part.len()
+ enter_bare_text.len()
+ controls_bare_text_second_part.len()
+ esc_bare_text.len()
+ controls_bare_text_third_part.len()
+ ctrl_c_bare_text.len()
+ controls_bare_text_third_part.len();
+ controls_bare_text_fourth_part.len();
let controls_column_start_position =
middle_column.saturating_sub(controls_line_length / 2);
let controls_line = format!(
"\u{1b}[{};{}H{}<{}{}{}{}> to run, <{}{}{}{}> to exit",
"\u{1b}[{};{}H{}<{}{}{}{}> run, <{}{}{}{}> drop to shell, <{}{}{}{}> exit",
middle_row + 2,
controls_column_start_position,
bold_text,
Expand All @@ -796,6 +800,10 @@ pub fn render_first_run_banner(
RESET_STYLES,
bold_text,
controls_color,
esc_bare_text,
RESET_STYLES,
bold_text,
controls_color,
ctrl_c_bare_text,
RESET_STYLES,
bold_text
Expand All @@ -817,21 +825,25 @@ pub fn render_first_run_banner(

let controls_bare_text_first_part = "<";
let enter_bare_text = "ENTER";
let controls_bare_text_second_part = "> to run, <";
let controls_bare_text_second_part = "> run, <";
let esc_bare_text = "ESC";
let controls_bare_text_third_part = "> drop to shell, <";
let ctrl_c_bare_text = "Ctrl-c";
let controls_bare_text_third_part = "> to exit";
let controls_bare_text_fourth_part = "> exit";
let controls_color = RESET_STYLES
.foreground(Some(AnsiCode::from(style.colors.orange)))
.bold(Some(AnsiCode::On));
let controls_line_length = controls_bare_text_first_part.len()
+ enter_bare_text.len()
+ controls_bare_text_second_part.len()
+ esc_bare_text.len()
+ controls_bare_text_third_part.len()
+ ctrl_c_bare_text.len()
+ controls_bare_text_third_part.len();
+ controls_bare_text_fourth_part.len();
let controls_column_start_position =
middle_column.saturating_sub(controls_line_length / 2);
let controls_line = format!(
"\u{1b}[{};{}H{}<{}{}{}{}> to run, <{}{}{}{}> to exit",
"\u{1b}[{};{}H{}<{}{}{}{}> run, <{}{}{}{}> drop to shell, <{}{}{}{}> exit",
middle_row + 2,
controls_column_start_position,
bold_text,
Expand All @@ -840,6 +852,10 @@ pub fn render_first_run_banner(
RESET_STYLES,
bold_text,
controls_color,
esc_bare_text,
RESET_STYLES,
bold_text,
controls_color,
ctrl_c_bare_text,
RESET_STYLES,
bold_text
Expand Down
8 changes: 8 additions & 0 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const END_KEY: &[u8] = &[27, 91, 70];
const BRACKETED_PASTE_BEGIN: &[u8] = &[27, 91, 50, 48, 48, 126];
const BRACKETED_PASTE_END: &[u8] = &[27, 91, 50, 48, 49, 126];
const ENTER_NEWLINE: &[u8] = &[10];
const ESC: &[u8] = &[27];
const ENTER_CARRIAGE_RETURN: &[u8] = &[13];
const SPACE: &[u8] = &[32];
const CTRL_C: &[u8] = &[3]; // TODO: check this to be sure it fits all types of CTRL_C (with mac, etc)
Expand Down Expand Up @@ -192,6 +193,13 @@ impl Pane for TerminalPane {
self.remove_banner();
Some(AdjustedInput::ReRunCommandInThisPane(run_command))
},
ESC => {
self.is_held = None;
self.grid.reset_terminal_state();
self.set_should_render(true);
self.remove_banner();
Some(AdjustedInput::DropToShellInThisPane)
},
CTRL_C => Some(AdjustedInput::CloseThisPane),
_ => None,
}
Expand Down
Loading

0 comments on commit 69eb904

Please sign in to comment.