File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,30 @@ use ansi_to_tui::IntoText;
3
3
use ratatui:: text:: Line ;
4
4
use ratatui:: text:: Text ;
5
5
6
+ // Expand tabs in a best-effort way for transcript rendering.
7
+ // Tabs can interact poorly with left-gutter prefixes in our TUI and CLI
8
+ // transcript views (e.g., `nl` separates line numbers from content with a tab).
9
+ // Replacing tabs with spaces avoids odd visual artifacts without changing
10
+ // semantics for our use cases.
11
+ fn expand_tabs ( s : & str ) -> std:: borrow:: Cow < ' _ , str > {
12
+ if s. contains ( '\t' ) {
13
+ // Keep it simple: replace each tab with 4 spaces.
14
+ // We do not try to align to tab stops since most usages (like `nl`)
15
+ // look acceptable with a fixed substitution and this avoids stateful math
16
+ // across spans.
17
+ std:: borrow:: Cow :: Owned ( s. replace ( '\t' , " " ) )
18
+ } else {
19
+ std:: borrow:: Cow :: Borrowed ( s)
20
+ }
21
+ }
22
+
6
23
/// This function should be used when the contents of `s` are expected to match
7
24
/// a single line. If multiple lines are found, a warning is logged and only the
8
25
/// first line is returned.
9
26
pub fn ansi_escape_line ( s : & str ) -> Line < ' static > {
10
- let text = ansi_escape ( s) ;
27
+ // Normalize tabs to spaces to avoid odd gutter collisions in transcript mode.
28
+ let s = expand_tabs ( s) ;
29
+ let text = ansi_escape ( & s) ;
11
30
match text. lines . as_slice ( ) {
12
31
[ ] => "" . into ( ) ,
13
32
[ only] => only. clone ( ) ,
You can’t perform that action at this time.
0 commit comments