Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_tui/src/lib_tui/cfg/tbox.rs

2.8 KiB, 11 runs

created by r1870400018:1167, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use crate::lib_tui::{
2 cfg::style::StyleLibrary,
3 draw::{
4 tbox::{
5 TextBox,
6 TextBoxConfig,
7 },
8 },
9 text::nav::PositionCursor,
10 render::CursorStyle,
11 text::{
12 //highlight::{
13 // BuilderType,
14 // StyledHighlighter,
15 //},
16 nav::Navigator,
17 typ::{
18 ContentType,
19 TextViewType,
20 },
21 view::TextView,
22 },
23 style::{
24 Colour,
25 Style,
26 },
27};
28
29use oxedyne_fe2o3_core::prelude::*;
30use oxedyne_fe2o3_file::tree::FileTree;
31use oxedyne_fe2o3_text::{
32 access::AccessibleText,
33 lines::TextLines,
34};
35
36use std::{
37 rc::Rc,
38 sync::RwLock,
39};
40
41
42#[derive(Clone, Debug, Default)]
43pub struct TextBoxLibrary;
44
45impl StyleLibrary {
46
47 pub fn navigable_text_box(&self) -> TextBoxConfig {
48 TextBoxConfig {
49 cursor_style: Some(CursorStyle::BlinkingBlock),
50 cursor_position: PositionCursor::UserControlled,
51 scrollbars: Some(self.standard_scrollbars()),
52 empty_line: Some((Style::new(Some(Colour::Red), None, None), fmt!("~"))),
53 highlight_styles: self.basic_highlight_styles(),
54 }
55 }
56
57 pub fn menu_text_box(&self) -> TextBoxConfig {
58 TextBoxConfig {
59 cursor_style: None,
60 cursor_position: PositionCursor::UserControlled,
61 scrollbars: Some(self.standard_scrollbars()),
62 empty_line: None,
63 highlight_styles: self.basic_highlight_styles(),
64 }
65 }
66
67 pub fn passive_text_box(&self) -> TextBoxConfig {
68 TextBoxConfig {
69 cursor_style: None,
70 cursor_position: PositionCursor::LatestLine(false),
71 scrollbars: None,
72 empty_line: None,
73 highlight_styles: self.basic_highlight_styles(),
74 }
75 }
76
77 pub fn file_tree_text_box(&self) -> Outcome<TextBox> {
78 let cfg = TextBoxConfig {
79 cursor_style: None,
80 cursor_position: PositionCursor::UserControlled,
81 scrollbars: Some(self.standard_scrollbars()),
82 empty_line: None,
83 highlight_styles: self.basic_highlight_styles(),
84 };
85 let tree = res!(FileTree::new("."));
86 let lines = res!(tree.display(true));
87 let mut tlines = TextLines::new(Vec::new(), None);
88 for line in lines {
89 debug!("{}",line);
90 tlines.append_string(line);
91 }
92 TextBox::new(
93 cfg,
94 res!(TextView::new(
95 ContentType::Menu,
96 TextViewType::FileTree(Navigator::new(None)),
97 AccessibleText::Shared(Rc::new(RwLock::new(tlines))),
98 )),
99 )
100 }
101}