Skip to content

Commit

Permalink
fix(reconnect): do not clear terminal state when entering alternate s…
Browse files Browse the repository at this point in the history
…creen (#2750)

* debug

* refactor(reconnect): articular reconnection logic
  • Loading branch information
imsnif authored Aug 30, 2023
1 parent 90875b0 commit 2081a2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub(crate) fn start_client(opts: CliArgs) {
let layout = layout.clone();
let mut config_options = config_options.clone();
let mut opts = opts.clone();
let mut is_a_reconnect = false;

if let Some(reconnect_to_session) = &reconnect_to_session {
// this is integration code to make session reconnects work with this existing,
Expand All @@ -358,6 +359,7 @@ pub(crate) fn start_client(opts: CliArgs) {
opts.session = None;
config_options.attach_to_session = None;
}
is_a_reconnect = true;
}

let start_client_plan = |session_name: std::string::String| {
Expand Down Expand Up @@ -417,6 +419,7 @@ pub(crate) fn start_client(opts: CliArgs) {
attach_layout,
tab_position_to_focus,
pane_id_to_focus,
is_a_reconnect,
);
} else {
if let Some(session_name) = opts.session.clone() {
Expand All @@ -430,6 +433,7 @@ pub(crate) fn start_client(opts: CliArgs) {
Some(layout),
None,
None,
is_a_reconnect,
);
} else {
if let Some(session_name) = config_options.session_name.as_ref() {
Expand Down Expand Up @@ -466,6 +470,7 @@ pub(crate) fn start_client(opts: CliArgs) {
attach_layout,
None,
None,
is_a_reconnect,
);
},
_ => {
Expand All @@ -479,6 +484,7 @@ pub(crate) fn start_client(opts: CliArgs) {
Some(layout),
None,
None,
is_a_reconnect,
);
},
}
Expand All @@ -501,6 +507,7 @@ pub(crate) fn start_client(opts: CliArgs) {
Some(layout),
None,
None,
is_a_reconnect,
);
}
}
Expand Down
25 changes: 16 additions & 9 deletions zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub fn start_client(
layout: Option<Layout>,
tab_position_to_focus: Option<usize>,
pane_id_to_focus: Option<(u32, bool)>, // (pane_id, is_plugin)
is_a_reconnect: bool,
) -> Option<ConnectToSession> {
info!("Starting Zellij client!");

Expand All @@ -156,14 +157,19 @@ pub fn start_client(
let bracketed_paste = "\u{1b}[?2004h";
os_input.unset_raw_mode(0).unwrap();

let _ = os_input
.get_stdout_writer()
.write(take_snapshot.as_bytes())
.unwrap();
let _ = os_input
.get_stdout_writer()
.write(clear_client_terminal_attributes.as_bytes())
.unwrap();
if !is_a_reconnect {
// we don't do this for a reconnect because our controlling terminal already has the
// attributes we want from it, and some terminals don't treat these atomically (looking at
// your Windows Terminal...)
let _ = os_input
.get_stdout_writer()
.write(take_snapshot.as_bytes())
.unwrap();
let _ = os_input
.get_stdout_writer()
.write(clear_client_terminal_attributes.as_bytes())
.unwrap();
}
envs::set_zellij("0".to_string());
config.env.set_vars();

Expand All @@ -172,6 +178,7 @@ pub fn start_client(
.unwrap_or_else(|| os_input.load_palette());

let full_screen_ws = os_input.get_terminal_size_using_fd(0);
log::info!("full_screen_ws: {:?}", full_screen_ws);
let client_attributes = ClientAttributes {
size: full_screen_ws,
style: Style {
Expand Down Expand Up @@ -375,7 +382,7 @@ pub fn start_client(

let mut stdout = os_input.get_stdout_writer();
stdout
.write_all("\u{1b}[1mLoading Zellij\u{1b}[m\n\r".as_bytes())
.write_all("\u{1b}[1m\u{1b}[HLoading Zellij\u{1b}[m\n\r".as_bytes())
.expect("cannot write to stdout");
stdout.flush().expect("could not flush");

Expand Down

0 comments on commit 2081a2e

Please sign in to comment.