curses: terminfo numeric capabilities are unsigned

This commit is contained in:
Johannes Altmanninger
2023-12-01 10:08:12 +01:00
parent 18654b1872
commit 5f1499cd67
2 changed files with 6 additions and 6 deletions

View File

@@ -121,7 +121,7 @@ pub struct Term {
pub set_title: Option<CString>,
// Number capabilities
pub max_colors: Option<i32>,
pub max_colors: Option<usize>,
// Flag/boolean capabilities
pub eat_newline_glitch: bool,
@@ -241,11 +241,11 @@ fn get_str_cap(code: &str) -> Option<CString> {
/// Return a number capability from termcap, or None if missing.
/// Panics if the given code string does not contain exactly two bytes.
fn get_num_cap(code: &str) -> Option<i32> {
fn get_num_cap(code: &str) -> Option<usize> {
let code = to_cstr_code(code);
match unsafe { sys::tgetnum(code.as_ptr()) } {
-1 => None,
n => Some(n),
n => Some(usize::try_from(n).unwrap()),
}
}

View File

@@ -35,10 +35,10 @@ extern "C" fn output_set_color_support(val: u8) {
}
/// Returns true if we think tparm can handle outputting a color index.
fn term_supports_color_natively(term: &Term, c: i32) -> bool {
fn term_supports_color_natively(term: &Term, c: u8) -> bool {
#[allow(clippy::int_plus_one)]
if let Some(max_colors) = term.max_colors {
max_colors >= c + 1
max_colors >= usize::try_from(c).unwrap() + 1
} else {
false
}
@@ -61,7 +61,7 @@ fn index_for_color(c: RgbColor) -> u8 {
}
fn write_color_escape(outp: &mut Outputter, term: &Term, todo: &CStr, mut idx: u8, is_fg: bool) {
if term_supports_color_natively(term, idx.into()) {
if term_supports_color_natively(term, idx) {
// Use tparm to emit color escape.
outp.tputs_if_some(&tparm1(todo, idx.into()));
} else {