Skip to content

Commit

Permalink
fix(#2040): session exit cleanup now works with --background flag
Browse files Browse the repository at this point in the history
  • Loading branch information
y-mx-b committed Jan 13, 2023
1 parent 70f224f commit ca00839
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub(crate) enum InputInstruction {
DoneParsing,
}

// TODO: figure out how to fix odd screen clearing/restoring issues
pub fn start_client(
mut os_input: Box<dyn ClientOsApi>,
opts: CliArgs,
Expand Down Expand Up @@ -344,8 +343,14 @@ pub fn start_client(
std::process::exit(1);
};

// for cleanup
let mut exit_msg = String::new();
let reset_style = "\u{1b}[m";
let show_cursor = "\u{1b}[?25h";
let restore_snapshot = "\u{1b}[?1049l";
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1);

if !open_in_background {
let exit_msg: String;
let mut loading = true;
let mut pending_instructions = vec![];

Expand Down Expand Up @@ -426,22 +431,18 @@ pub fn start_client(

router_thread.join().unwrap();

// cleanup();
let reset_style = "\u{1b}[m";
let show_cursor = "\u{1b}[?25h";
let restore_snapshot = "\u{1b}[?1049l";
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1);
let goodbye_message = format!(
"{}\n{}{}{}{}\n",
goto_start_of_last_line, restore_snapshot, reset_style, show_cursor, exit_msg
);

info!("{}", exit_msg);
let mut stdout = os_input.get_stdout_writer();
let _ = stdout.write(goodbye_message.as_bytes()).unwrap();
stdout.flush().unwrap();
}

// cleanup
let goodbye_message = format!(
"{}\n{}{}{}{}\n",
goto_start_of_last_line, restore_snapshot, reset_style, show_cursor, exit_msg
);
let mut stdout = os_input.get_stdout_writer();
let _ = stdout.write(goodbye_message.as_bytes()).unwrap();
stdout.flush().unwrap();

os_input.disable_mouse().non_fatal();
os_input.unset_raw_mode(0).unwrap();
}
Expand Down

0 comments on commit ca00839

Please sign in to comment.