From 66fcd7ba871616665ad0efb5ef1f6786bf8f1629 Mon Sep 17 00:00:00 2001 From: kxxt Date: Thu, 2 May 2024 22:08:39 +0800 Subject: [PATCH] fix: render cells that has no content but styles Fix #181 --- ..._tests__simple_ls_no_style_from_block.snap | 49 +++++++++++++++---- src/state.rs | 6 +-- src/vt100_imp.rs | 7 ++- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/snapshots/tui_term__widget__tests__simple_ls_no_style_from_block.snap b/src/snapshots/tui_term__widget__tests__simple_ls_no_style_from_block.snap index ca6d72e..cf37c2a 100644 --- a/src/snapshots/tui_term__widget__tests__simple_ls_no_style_from_block.snap +++ b/src/snapshots/tui_term__widget__tests__simple_ls_no_style_from_block.snap @@ -36,22 +36,24 @@ Buffer { x: 18, y: 1, fg: Indexed(4), bg: Reset, underline: Reset, modifier: BOLD, x: 24, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 55, y: 1, fg: Indexed(4), bg: Reset, underline: Reset, modifier: BOLD, - x: 61, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 61, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, x: 1, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 18, y: 2, fg: Indexed(4), bg: Reset, underline: Reset, modifier: BOLD, x: 28, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 67, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 81, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, x: 1, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 55, y: 3, fg: Indexed(4), bg: Reset, underline: Reset, modifier: BOLD, - x: 64, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 64, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, x: 1, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 32, y: 4, fg: Indexed(4), bg: Reset, underline: Reset, modifier: BOLD, x: 37, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 55, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 81, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, x: 1, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 33, y: 5, fg: Indexed(4), bg: Reset, underline: Reset, modifier: BOLD, x: 41, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 56, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 81, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, x: 1, y: 6, fg: Indexed(6), bg: Reset, underline: Reset, modifier: BOLD, x: 9, y: 6, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 13, y: 6, fg: Indexed(5), bg: Reset, underline: Reset, modifier: BOLD, @@ -60,11 +62,40 @@ Buffer { x: 25, y: 6, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 30, y: 6, fg: Indexed(4), bg: Reset, underline: Reset, modifier: BOLD, x: 51, y: 6, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 52, y: 6, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 81, y: 6, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, x: 1, y: 7, fg: Indexed(2), bg: Reset, underline: Reset, modifier: BOLD, x: 2, y: 7, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 3, y: 7, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, - x: 1, y: 9, fg: Gray, bg: Reset, underline: Reset, modifier: BOLD, - x: 2, y: 9, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 81, y: 7, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 8, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 8, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 9, fg: Gray, bg: Reset, underline: Reset, modifier: NONE, + x: 2, y: 9, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 9, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 10, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 10, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 11, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 11, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 12, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 12, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 13, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 13, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 14, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 14, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 15, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 15, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 16, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 16, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 17, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 17, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 18, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 18, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 19, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 19, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 20, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 20, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 21, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 21, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, + x: 1, y: 22, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 81, y: 22, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD, ] } diff --git a/src/state.rs b/src/state.rs index 67def41..d54939f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -25,10 +25,8 @@ pub fn handle(term: &PseudoTerminal, area: Rect, buf: &mut Buffer) } if let Some(screen_cell) = screen.cell(row, col) { - if screen_cell.has_contents() { - let cell = buf.get_mut(buf_col, buf_row); - screen_cell.apply(cell); - } + let cell = buf.get_mut(buf_col, buf_row); + screen_cell.apply(cell); } } } diff --git a/src/vt100_imp.rs b/src/vt100_imp.rs index c63c3c2..a8aeb45 100644 --- a/src/vt100_imp.rs +++ b/src/vt100_imp.rs @@ -37,8 +37,11 @@ impl Cell for vt100::Cell { fn fill_buf_cell(screen_cell: &vt100::Cell, buf_cell: &mut ratatui::buffer::Cell) { let fg = screen_cell.fgcolor(); let bg = screen_cell.bgcolor(); - - buf_cell.set_symbol(&screen_cell.contents()); + if screen_cell.has_contents() { + buf_cell.set_symbol(&screen_cell.contents()); + } else { + buf_cell.set_symbol(" "); + } let fg: Color = fg.into(); let bg: Color = bg.into(); let mut style = Style::reset();