fix input truncation: cols-3, remove scroll-past-end condition, drop min(cols-1) clamp

This commit is contained in:
Niko Marmeladkov 2026-07-15 23:13:20 +03:00
parent b6f1850a24
commit 2ce7c3688c
Signed by untrusted user who does not match committer: Niko
GPG key ID: E3B955F9442D44E3

View file

@ -128,12 +128,11 @@ fn byte_at(s: &str, char_idx: usize) -> usize {
s.char_indices().nth(char_idx).map(|(i, _)| i).unwrap_or(s.len())
}
fn adjust_scroll(input: &str, cursor: usize, scroll: &mut usize, cols: usize) {
let max_visible = cols.saturating_sub(2);
fn adjust_scroll(_input: &str, cursor: usize, scroll: &mut usize, cols: usize) {
let max_visible = cols.saturating_sub(3);
if max_visible == 0 {
return;
}
let nchars = input.chars().count();
if cursor >= *scroll + max_visible {
*scroll = cursor + 1 - max_visible;
@ -141,9 +140,6 @@ fn adjust_scroll(input: &str, cursor: usize, scroll: &mut usize, cols: usize) {
if cursor < *scroll {
*scroll = cursor;
}
if *scroll + max_visible > nchars {
*scroll = nchars.saturating_sub(max_visible);
}
}
#[allow(clippy::too_many_arguments)]
@ -181,7 +177,7 @@ fn draw_all(
}
let prompt = "> ";
let max_visible = cols.saturating_sub(prompt.len());
let max_visible = cols.saturating_sub(prompt.len() + 1);
let visible: String = input.chars().skip(scroll).take(max_visible).collect();
out.push_str(&format!("\x1b[{};1H", rows));
@ -191,7 +187,7 @@ fn draw_all(
out.push_str("\x1b[K");
out.push_str(RESET);
let cursor_col = (prompt.len() + cursor.saturating_sub(scroll)).min(cols - 1);
let cursor_col = prompt.len() + cursor.saturating_sub(scroll);
out.push_str(&format!("\x1b[{};{}H", rows, cursor_col + 1));
let _ = stdout.write_all(out.as_bytes());
@ -388,7 +384,7 @@ pub fn run_attach(name: &str, full: bool, stream: UnixStream) {
if let Some(idx) = history_idx {
input = history[idx].clone();
cursor = input.chars().count();
scroll = input.chars().count().saturating_sub(cols.saturating_sub(2));
scroll = input.chars().count().saturating_sub(cols.saturating_sub(3));
}
adjust_scroll(&input, cursor, &mut scroll, cols);
}