control_chars/
control_chars.rs1use txtview::{TxtView, TxtViewConfig};
2
3fn main() -> std::io::Result<()> {
4 let doc = vec![
5 "Control character & tab handling demo".to_string(),
6 "".to_string(),
7 "Tabs are measured and wrapped at their 8-column terminal stop:".to_string(),
8 "\tone tab of indentation".to_string(),
9 "\t\ttwo tabs".to_string(),
10 "\t\t\tthree tabs".to_string(),
11 "no\tgap\tor\twider".to_string(),
12 "".to_string(),
13 "Mixed tab and space indentation:".to_string(),
14 " four spaces then\tone tab".to_string(),
15 "\tone tab then four spaces".to_string(),
16 "".to_string(),
17 "Control bytes are shown as caret notation instead of being executed:".to_string(),
18 "backspace \x08 BEL \x07 CR \r DEL \x7f end".to_string(),
19 "solo control bytes: ^not caret, actual: \x01 \x02 \x03 \x04".to_string(),
20 "field separators: US \x1f RS \x1e GS \x1d FS \x1c".to_string(),
21 "".to_string(),
22 "SGR and OSC8 hyperlinks pass through; other escapes show as text:".to_string(),
23 "cursor moves and clears never execute: \x1b[2A \x1b[2J \x1b[K".to_string(),
24 "OSC8 hyperlink stays live and is never split: \x1b]8;;https://example.com/about\x07example.com\x1b]8;;\x07".to_string(),
25 "an OSC title is escaped text, never a live title: \x1b]0;window title\x07".to_string(),
26 "two-byte escapes too: \x1b7 saved cursor \x1b8 restore".to_string(),
27 "".to_string(),
28 "An empty line and a tab-only line both occupy a row:".to_string(),
29 "".to_string(),
30 "\t".to_string(),
31 "".to_string(),
32 "Long content so wrapping kicks in, note how tabs keep 8-column alignment:".to_string(),
33 "\tLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.".to_string(),
34 "a shorter line\t\t\twith long tab gaps and trailing spaces".to_string(),
35 "".to_string(),
36 "A very long unbroken\t\t\ttoken-heavy line that wraps several times across the viewport width to exercise the wrap-with-tab path:".to_string(),
37 "".to_string(),
38 ];
39
40 let text = doc.join("\n");
41
42 let config = TxtViewConfig {
43 show_line_numbers: true,
44 show_scrollbar: true,
45 show_help_bar: true,
46 ..TxtViewConfig::default()
47 };
48
49 let mut viewer = TxtView::new(&text).with_config(config);
50 viewer.run()
51}