Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use alternate screen #310

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ansi_escape.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! # ANSI Escape sequences

/// Clear from cursor to beginning of the screen
pub const CLEAR_SCREEN: &str = "\x1b[2J";
/// Switches to the main buffer.
pub(crate) const USE_MAIN_SCREEN: &str = "\x1b[?1049l";

/// Switches to a new alternate screen buffer.
pub(crate) const USE_ALTERNATE_SCREEN: &str = "\x1b[?1049h";

/// Reset the formatting
pub(crate) const RESET_FMT: &str = "\x1b[m";
Expand All @@ -10,7 +13,7 @@ pub(crate) const RESET_FMT: &str = "\x1b[m";
pub(crate) const REVERSE_VIDEO: &str = "\x1b[7m";

/// Move the cursor to 1:1
pub const MOVE_CURSOR_TO_START: &str = "\x1b[H";
pub(crate) const MOVE_CURSOR_TO_START: &str = "\x1b[H";

/// DECTCTEM: Make the cursor invisible
pub(crate) const HIDE_CURSOR: &str = "\x1b[?25l";
Expand Down
5 changes: 3 additions & 2 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ impl Editor {

// Enable raw mode and store the original (non-raw) terminal mode.
editor.orig_term_mode = Some(sys::enable_raw_mode()?);
editor.update_window_size()?;
print!("{USE_ALTERNATE_SCREEN}");

editor.update_window_size()?;
set_status!(editor, "{}", HELP_MESSAGE);

Ok(editor)
Expand Down Expand Up @@ -723,7 +724,7 @@ impl Drop for Editor {
sys::set_term_mode(&orig_term_mode).expect("Could not restore original terminal mode.");
}
if !thread::panicking() {
print!("{CLEAR_SCREEN}{MOVE_CURSOR_TO_START}");
print!("{USE_MAIN_SCREEN}");
io::stdout().flush().expect("Could not flush stdout");
}
}
Expand Down
Loading