@@ -3,6 +3,7 @@ use std::{
33 fmt,
44} ;
55
6+ use compact_str:: CompactString ;
67use crokey:: KeyCombination ;
78use ratatui:: {
89 layout:: Constraint ,
@@ -15,13 +16,16 @@ use tui_input::Input;
1516use crate :: { keybinds:: Keybinds , tui:: single_line_selector:: SingleLineSelectorState } ;
1617
1718mod macro_ref;
19+ mod tui;
20+
1821pub use macro_ref:: MacroRef ;
22+ pub use tui:: MacroEditing ;
1923
20- #[ derive( Debug , PartialEq , Eq ) ]
24+ #[ derive( Debug ) ]
2125#[ repr( u8 ) ]
2226pub enum MacrosPrompt {
2327 None ,
24- Create ,
28+ AddEdit ( MacroEditing ) ,
2529 Delete ,
2630 Keybind ,
2731}
@@ -34,14 +38,17 @@ pub enum MacroCategorySelection<'a> {
3438 Category ( & ' a str ) ,
3539}
3640
41+ // TODO search when typing
42+
3743pub struct Macros {
3844 pub all : BTreeSet < Macro > ,
3945
4046 pub ui_state : MacrosPrompt ,
4147 // ["All Bytes", "All Strings", "All Macros", "OpenShock"]
4248 // Start here, at user's first category. ^
4349 pub categories_selector : SingleLineSelectorState ,
44- pub input : Input ,
50+ // TODO search
51+ pub search_input : Input ,
4552 // pub scrollbar_state: ScrollbarState,
4653 // // maybe just take from macros
4754 // pub categories: BTreeSet<String>,
@@ -84,7 +91,7 @@ impl Macros {
8491 all : test_macros,
8592 // tx_queue: Vec::new(),
8693 ui_state : MacrosPrompt :: None ,
87- input : Input :: default ( ) ,
94+ search_input : Input :: default ( ) ,
8895 categories_selector : SingleLineSelectorState :: new ( ) . with_selected ( 2 ) ,
8996 // categories: BTreeSet::new(),
9097 }
@@ -240,12 +247,19 @@ impl Macros {
240247 // let macro_binding = self.all.iter().find(|d| macro_ref.eq_macro(d)).unwrap();
241248 // self.all.remove(macro_binding);
242249 }
250+ // pub fn begin_editing(&mut self, macro_ref: &MacroRef) {
251+ // self.ui_state = MacrosPrompt::AddEdit(MacroEditing {
252+ // inner_ref: Some(macro_ref.clone()),
253+ // ..Default::default()
254+ // });
255+
256+ // }
243257}
244258
245- #[ derive( Debug , PartialEq , Eq , PartialOrd , Ord ) ]
259+ #[ derive( Debug , Default , PartialEq , Eq , PartialOrd , Ord ) ]
246260pub struct Macro {
247- pub title : String ,
248- pub category : Option < String > ,
261+ pub title : CompactString ,
262+ pub category : Option < CompactString > ,
249263 // pub keybinding: Option<KeyCombination>,
250264 pub content : MacroContent ,
251265 // preview_hidden: bool,
@@ -287,11 +301,15 @@ impl fmt::Display for Macro {
287301// }
288302// }
289303
290- #[ derive( Debug , PartialEq , Eq , PartialOrd , Ord ) ]
304+ #[ derive( Debug , Default , PartialEq , Eq , PartialOrd , Ord ) ]
291305pub enum MacroContent {
306+ #[ default]
292307 Empty ,
293308 Text ( String ) ,
294- Bytes { content : Vec < u8 > , preview : String } ,
309+ Bytes {
310+ content : Vec < u8 > ,
311+ preview : String ,
312+ } ,
295313}
296314
297315impl MacroContent {
0 commit comments