Skip to content

Commit b6dd72e

Browse files
committed
Skeleton of Macro editor, tweaks to notifications
1 parent 63e39b2 commit b6dd72e

7 files changed

Lines changed: 470 additions & 93 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ strum = { version = "0.27", features = ["derive"] }
4646
takeable = "0.2.2"
4747
textwrap = "0.16.2"
4848
thiserror = "2.0.12"
49+
tinyvec = { version = "1.9.0", features = ["std"] }
4950
toml = "0.8.21"
5051
tracing = { version = "0.1.41", features = ["log"] }
5152
tracing-appender = "0.2.3"

src/app.rs

Lines changed: 98 additions & 53 deletions
Large diffs are not rendered by default.

src/macros/macro_ref.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::fmt;
22

3+
use compact_str::{CompactString, ToCompactString, format_compact};
34
use serde::{Deserialize, Deserializer, Serialize, Serializer};
45

56
use super::Macro;
67

78
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
89
pub struct MacroRef {
9-
pub category: Option<String>,
10-
pub title: String,
10+
pub category: Option<CompactString>,
11+
pub title: CompactString,
1112
}
1213

1314
impl From<&Macro> for MacroRef {
@@ -63,11 +64,11 @@ impl<'de> Deserialize<'de> for MacroRef {
6364

6465
let (category, title) = match parts.len() {
6566
2 => (
66-
Some(parts[0].trim().to_string()),
67-
parts[1].trim().to_string(),
67+
Some(parts[0].trim().to_compact_string()),
68+
parts[1].trim().to_compact_string(),
6869
),
69-
1 => (None, parts[0].trim().to_string()),
70-
_ => (None, String::new()),
70+
1 => (None, parts[0].trim().to_compact_string()),
71+
_ => return Err(serde::de::Error::custom("invalid format for MacroRef")),
7172
};
7273

7374
Ok(MacroRef { category, title })
@@ -80,7 +81,7 @@ impl Serialize for MacroRef {
8081
S: Serializer,
8182
{
8283
let s = if let Some(ref cat) = self.category {
83-
format!("{}|{}", cat, self.title)
84+
format_compact!("{}|{}", cat, self.title)
8485
} else {
8586
self.title.clone()
8687
};

src/macros/mod.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{
33
fmt,
44
};
55

6+
use compact_str::CompactString;
67
use crokey::KeyCombination;
78
use ratatui::{
89
layout::Constraint,
@@ -15,13 +16,16 @@ use tui_input::Input;
1516
use crate::{keybinds::Keybinds, tui::single_line_selector::SingleLineSelectorState};
1617

1718
mod macro_ref;
19+
mod tui;
20+
1821
pub use macro_ref::MacroRef;
22+
pub use tui::MacroEditing;
1923

20-
#[derive(Debug, PartialEq, Eq)]
24+
#[derive(Debug)]
2125
#[repr(u8)]
2226
pub 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+
3743
pub 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)]
246260
pub 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)]
291305
pub 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

297315
impl MacroContent {

0 commit comments

Comments
 (0)