Skip to content

Commit 51f5e68

Browse files
committed
Working out macro add/edit prompt, and a macro format
1 parent b49c02b commit 51f5e68

9 files changed

Lines changed: 606 additions & 121 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ansi-to-tui = { git = "https://github.com/nullstalgia/ansi-to-tui", branch = "lo
1515
arboard = "3.4.1"
1616
arc-swap = "1.7.1"
1717
better-panic = "0.3.0"
18+
bstr = "1.12.0"
1819
chrono = "0.4.39"
1920
color-eyre = "0.6.3"
2021
compact_str = "0.9.0"
@@ -25,6 +26,7 @@ enum-rotate = "0.1.1"
2526
# enum_rotate = { path = "../enum-rotate" }
2627
espflash = { version = "3.3.0", optional = true, features = ["serialport"] }
2728
fs-err = "3.1.0"
29+
hex = "0.4.3"
2830
human-panic = "2.0.2"
2931
# int-enum = { git = "https://github.com/nullstalgia/int-enum-rs", branch = "feat/colors-and-discriminators" }
3032
int-enum = "1.2.0"

src/app.rs

Lines changed: 229 additions & 30 deletions
Large diffs are not rendered by default.

src/logging/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// pub struct LoggingHandle {
2+
// tx,
3+
// }
4+
5+
// struct LoggingWorker {
6+
// rx,
7+
// path: PathBuf,
8+
// }

src/macros/mod.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
borrow::Cow,
23
collections::{BTreeSet, HashMap},
34
fmt,
45
};
@@ -19,15 +20,14 @@ mod macro_ref;
1920
mod tui;
2021

2122
pub use macro_ref::MacroRef;
22-
pub use tui::MacroEditing;
23+
pub use tui::{MacroEditSelected, MacroEditing};
2324

2425
#[derive(Debug)]
2526
#[repr(u8)]
2627
pub enum MacrosPrompt {
2728
None,
28-
AddEdit(MacroEditing),
2929
Delete,
30-
Keybind,
30+
AddEdit(MacroEditing),
3131
}
3232

3333
pub enum MacroCategorySelection<'a> {
@@ -256,7 +256,7 @@ impl Macros {
256256
// }
257257
}
258258

259-
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
259+
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
260260
pub struct Macro {
261261
pub title: CompactString,
262262
pub category: Option<CompactString>,
@@ -265,6 +265,26 @@ pub struct Macro {
265265
// preview_hidden: bool,
266266
}
267267

268+
impl Macro {
269+
pub fn as_str(&self) -> Option<Cow<'_, str>> {
270+
match &self.content {
271+
MacroContent::Empty => None,
272+
MacroContent::Text(text) => Some(Cow::Borrowed(text.as_str())),
273+
MacroContent::Bytes { content, .. } => match std::str::from_utf8(content) {
274+
Ok(s) => Some(Cow::Borrowed(s)),
275+
Err(_) => None,
276+
},
277+
}
278+
}
279+
pub fn as_bytes(&self) -> Option<&[u8]> {
280+
match &self.content {
281+
MacroContent::Empty => None,
282+
MacroContent::Bytes { content, .. } => Some(&content),
283+
MacroContent::Text(text) => Some(text.as_bytes()),
284+
}
285+
}
286+
}
287+
268288
impl fmt::Display for Macro {
269289
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
270290
match &self.category {
@@ -301,7 +321,7 @@ impl fmt::Display for Macro {
301321
// }
302322
// }
303323

304-
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
324+
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
305325
pub enum MacroContent {
306326
#[default]
307327
Empty,
@@ -316,9 +336,9 @@ impl MacroContent {
316336
fn new_bytes(content: Vec<u8>) -> Self {
317337
let hex_string = content
318338
.iter()
319-
.map(|b| format!("0x{:02X}", b))
339+
.map(|b| format!("\\x{:02X}", b))
320340
.collect::<Vec<_>>()
321-
.join(" ");
341+
.join("");
322342
Self::Bytes {
323343
content,
324344
preview: hex_string,

0 commit comments

Comments
 (0)