Skip to content

Commit

Permalink
avoid cnorm on certain terminals
Browse files Browse the repository at this point in the history
using a terminfo's cnorm doesn't reset the cursor for many terminals,
see issue: #10089
  • Loading branch information
cjbayliss committed May 15, 2024
1 parent e76020d commit d667907
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@ use std::{
fmt,
io::{self, Write},
};
use termini::TermInfo;

fn term_program() -> Option<String> {
std::env::var("TERM_PROGRAM").ok()
// Some terminals don't set $TERM_PROGRAM
match std::env::var("TERM_PROGRAM") {
Err(_) => std::env::var("TERM").ok(),
Ok(term_program) => Some(term_program),
}
}
fn vte_version() -> Option<usize> {
std::env::var("VTE_VERSION").ok()?.parse().ok()
}
fn reset_cursor_approach(terminfo: TermInfo) -> String {
let default = "\x1B[0 q";
match term_program().as_deref() {
// TODO: add more terminals that don't support cnorm
Some("alacritty") => default.to_string(),
Some("tmux") => default.to_string(),
_ => terminfo
.utf8_string_cap(termini::StringCapability::CursorNormal)
.unwrap_or(default)
.to_string(),
}
}

/// Describes terminal capabilities like extended underline, truecolor, etc.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -69,10 +86,7 @@ impl Capabilities {
|| t.extended_cap("Su").is_some()
|| vte_version() >= Some(5102)
|| matches!(term_program().as_deref(), Some("WezTerm")),
reset_cursor_command: t
.utf8_string_cap(termini::StringCapability::CursorNormal)
.unwrap_or("\x1B[0 q")
.to_string(),
reset_cursor_command: reset_cursor_approach(t),
},
}
}
Expand Down

0 comments on commit d667907

Please sign in to comment.