oxedyne/fe2o3/fe2o3_tui/src/lib_tui/text/typ.rs
3.9 KiB, 19 runs
created by r1870400018:1213, 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
| 1 | use crate::lib_tui::{ |
| 2 | action::Action, |
| 3 | draw::window::WindowId, |
| 4 | style::Symbol, |
| 5 | text::{ |
| 6 | edit::Editor, |
| 7 | //highlight::StyledHighlighter, |
| 8 | nav::Navigator, |
| 9 | }, |
| 10 | }; |
| 11 | |
| 12 | use oxedyne_fe2o3_geom::dim::Coord; |
| 13 | use oxedyne_fe2o3_text::Text; |
| 14 | |
| 15 | use std::{ |
| 16 | path::PathBuf, |
| 17 | }; |
| 18 | |
| 19 | |
| 20 | #[derive(Clone, Debug, Default)] |
| 21 | pub enum HighlightType { |
| 22 | #[default] |
| 23 | Plain, |
| 24 | File(PathBuf), |
| 25 | Menu(Action), |
| 26 | Window(WindowId), |
| 27 | } |
| 28 | |
| 29 | #[derive(Clone, Debug, Default)] |
| 30 | pub enum TextType { |
| 31 | #[default] |
| 32 | Plain, |
| 33 | MenuItem, |
| 34 | MenuHeading, |
| 35 | } |
| 36 | |
| 37 | impl TextType { |
| 38 | pub fn new_menu_item<S: Into<String>>(s: S) -> Text<Self> { |
| 39 | Text::new(s, Some(Self::MenuItem)) |
| 40 | } |
| 41 | pub fn new_menu_heading<S: Into<String>>(s: S) -> Text<Self> { |
| 42 | Text::new(s, Some(Self::MenuHeading)) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | #[derive(Clone, Debug, Default)] |
| 47 | pub enum ContentType { |
| 48 | Buffer, |
| 49 | Database, |
| 50 | File, |
| 51 | FileTree, |
| 52 | Log, |
| 53 | Menu, |
| 54 | Shell, |
| 55 | #[default] |
| 56 | Text, |
| 57 | } |
| 58 | |
| 59 | impl ContentType { |
| 60 | |
| 61 | pub fn symbol(&self) -> Option<Symbol> { |
| 62 | match self { |
| 63 | Self::Buffer => Some(Symbol::Buffer), |
| 64 | Self::Database => Some(Symbol::Database), |
| 65 | Self::File => Some(Symbol::File), |
| 66 | Self::FileTree => Some(Symbol::FileTree), |
| 67 | Self::Log => None, |
| 68 | Self::Menu => Some(Symbol::Menu), |
| 69 | Self::Shell => Some(Symbol::Shell), |
| 70 | Self::Text => Some(Symbol::Text), |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | pub fn label(&self) -> &str { |
| 75 | match self { |
| 76 | Self::Buffer => "Buffer", |
| 77 | Self::Database => "Database", |
| 78 | Self::File => "File", |
| 79 | Self::FileTree => "File Tree", |
| 80 | Self::Log => "Log", |
| 81 | Self::Menu => "Menu", |
| 82 | Self::Shell => "Shell", |
| 83 | Self::Text => "Text", |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | #[derive(Clone, Debug)] |
| 89 | pub enum TextViewType { |
| 90 | Editable(Editor), |
| 91 | Static(Navigator), |
| 92 | Menu(Navigator), |
| 93 | WindowList(Navigator), |
| 94 | FileTree(Navigator), |
| 95 | } |
| 96 | |
| 97 | impl Default for TextViewType { |
| 98 | fn default() -> Self { |
| 99 | Self::Static(Navigator::default()) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | impl TextViewType { |
| 104 | |
| 105 | pub fn get_cursor(&self) -> Option<&Coord> { |
| 106 | Some(match self { |
| 107 | Self::Editable(editor) => &editor.nav.cursor, |
| 108 | Self::Static(nav) | |
| 109 | Self::Menu(nav) | |
| 110 | Self::FileTree(nav) | |
| 111 | Self::WindowList(nav) => &nav.cursor, |
| 112 | }) |
| 113 | } |
| 114 | |
| 115 | pub fn get_cursor_mut(&mut self) -> Option<&mut Coord> { |
| 116 | Some(match self { |
| 117 | Self::Editable(editor) => &mut editor.nav.cursor, |
| 118 | Self::Static(nav) | |
| 119 | Self::Menu(nav) | |
| 120 | Self::FileTree(nav) | |
| 121 | Self::WindowList(nav) => &mut nav.cursor, |
| 122 | }) |
| 123 | } |
| 124 | |
| 125 | pub fn get_editor(&self) -> Option<&Editor> { |
| 126 | match self { |
| 127 | Self::Editable(editor) => Some(editor), |
| 128 | _ => None, |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | pub fn get_editor_mut(&mut self) -> Option<&mut Editor> { |
| 133 | match self { |
| 134 | Self::Editable(editor) => Some(editor), |
| 135 | _ => None, |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | //pub fn get_highlighter(&self) -> Option<&StyledHighlighter> { |
| 140 | // match self { |
| 141 | // Self::Editable(editor) => editor.nav.highlighter.as_ref(), |
| 142 | // Self::Static(nav) | |
| 143 | // Self::Menu(nav) | |
| 144 | // Self::FileTree(_, nav) | |
| 145 | // Self::WindowList(nav) => nav.highlighter.as_ref(), |
| 146 | // } |
| 147 | //} |
| 148 | |
| 149 | //pub fn get_highlighter_mut(&mut self) -> Option<&mut StyledHighlighter> { |
| 150 | // match self { |
| 151 | // Self::Editable(editor) => editor.nav.highlighter.as_mut(), |
| 152 | // Self::Static(nav) | |
| 153 | // Self::Menu(nav) | |
| 154 | // Self::FileTree(_, nav) | |
| 155 | // Self::WindowList(nav) => nav.highlighter.as_mut(), |
| 156 | // } |
| 157 | //} |
| 158 | } |