1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use ratatui::{buffer::Buffer, layout::Rect, style::Style};
use super::state::InteractiveState;
impl<'a> InteractiveState<'a> {
/// Write text to buffer at position
pub(super) fn write_text(
&self,
buf: &mut Buffer,
row: u16,
col: u16,
text: &str,
area: Rect,
style: Style,
) {
if row < self.viewport.scroll_offset || row >= self.viewport.scroll_offset + area.height {
return; // Outside visible area
}
let screen_row = row - self.viewport.scroll_offset;
let mut current_col = col;
for ch in text.chars() {
if current_col >= area.width {
break; // Past right edge
}
// Handle tabs: replace with spaces to avoid column counting mismatches
// Tabs display as multiple spaces in terminals but count as 1 character
if ch == '\t' {
// Write 4 spaces for each tab (Rust convention)
for _ in 0..4 {
if current_col >= area.width {
break;
}
if let Some(cell) = buf.cell_mut((current_col, screen_row)) {
cell.set_char(' ');
cell.set_style(style);
}
current_col += 1;
}
} else {
if let Some(cell) = buf.cell_mut((current_col, screen_row)) {
cell.set_char(ch);
cell.set_style(style);
}
current_col += 1;
}
}
}
}