Skip to content

Commit 8a0db1a

Browse files
committed
Rendering Settings menu
1 parent 8aede30 commit 8a0db1a

8 files changed

Lines changed: 516 additions & 298 deletions

File tree

src/app.rs

Lines changed: 157 additions & 84 deletions
Large diffs are not rendered by default.

src/keybinds.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ pub mod methods {
99
pub const TOGGLE_DTR: &str = "toggle-dtr";
1010
pub const TOGGLE_RTS: &str = "toggle-rts";
1111
pub const TOGGLE_TIMESTAMPS: &str = "toggle-timestamps";
12+
pub const TOGGLE_INDICES: &str = "toggle-indices";
1213
pub const SHOW_MACROS: &str = "show-macros";
1314
pub const SHOW_PORTSETTINGS: &str = "show-portsettings";
1415
pub const SHOW_BEHAVIOR: &str = "show-behavior";
15-
16-
#[cfg(debug_assertions)]
17-
pub const DEBUG_LINES: &str = "debug-lines";
16+
pub const SHOW_RENDERING: &str = "show-rendering";
1817
}
1918

2019
static CONFIG_TOML: &str = r#"
@@ -27,7 +26,7 @@ ctrl-t = "toggle-timestamps"
2726
ctrl-m = "show-macros"
2827
ctrl-b = "show-behavior"
2928
'ctrl-.' = "show-portsettings"
30-
ctrl-d = "debug-lines"
29+
ctrl-d = "toggle-indices"
3130
3231
[macros]
3332
F19 = ["Restart"]

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::{
44
net::TcpStream,
5-
sync::{mpsc, Mutex},
5+
sync::{Mutex, mpsc},
66
};
77

88
use app::{App, CrosstermEvent};
@@ -15,9 +15,9 @@ use ratatui::crossterm::{
1515
};
1616

1717
use serialport::{SerialPortInfo, SerialPortType};
18-
use tracing::{debug, error, info, level_filters::LevelFilter, Level};
18+
use tracing::{Level, debug, error, info, level_filters::LevelFilter};
1919
use tracing_appender::non_blocking::WorkerGuard;
20-
use tui::buffer::line_ending_iter;
20+
use tui::buffer::line_ending_iter_inner;
2121

2222
mod app;
2323
mod errors;

src/serial.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,15 @@ impl SerialHandle {
367367
.map_err(|_| YapError::NoSerialWorker)
368368
}
369369
/// Sends the supplied bytes through the connected Serial device.
370-
pub fn send_bytes(&self, mut input: Vec<u8>, line_ending: Option<&str>) -> YapResult<()> {
371-
if let Some(ending) = line_ending.map(str::as_bytes) {
370+
pub fn send_bytes(&self, mut input: Vec<u8>, line_ending: Option<&[u8]>) -> YapResult<()> {
371+
if let Some(ending) = line_ending {
372372
input.extend(ending.iter());
373373
}
374374
self.command_tx
375375
.send(SerialCommand::TxBuffer(input))
376376
.map_err(|_| YapError::NoSerialWorker)
377377
}
378-
pub fn send_str(&self, input: &str, line_ending: &str) -> YapResult<()> {
378+
pub fn send_str(&self, input: &str, line_ending: &[u8]) -> YapResult<()> {
379379
// debug!("Outputting to serial: {input}");
380380
let buffer = input.as_bytes().to_owned();
381381
self.send_bytes(buffer, Some(line_ending))

src/settings/mod.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ use crate::{serial::PortSettings, tui::buffer::UserEcho};
2828
pub mod ser;
2929

3030
#[serde_inline_default]
31-
#[derive(Debug, Serialize, Deserialize, Derivative)]
31+
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
3232
#[derivative(Default)]
3333
pub struct Settings {
3434
#[serde(skip)]
3535
pub path: PathBuf,
3636
#[serde(default)]
37+
pub rendering: Rendering,
38+
#[serde(default)]
3739
pub behavior: Behavior,
3840
#[serde(default)]
3941
pub misc: Misc,
@@ -42,27 +44,24 @@ pub struct Settings {
4244
}
4345

4446
#[serde_inline_default]
45-
#[derive(Debug, Serialize, Deserialize, Derivative)]
47+
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
4648
#[derivative(Default)]
4749
pub struct Misc {
4850
#[serde_inline_default(String::from("debug"))]
4951
#[derivative(Default(value = "String::from(\"debug\")"))]
5052
pub log_level: String,
5153
}
5254

55+
// TODO allow setting nicknames to devices?????
56+
57+
// TODO add Reset to Defaults somewhere in the UI
58+
59+
// TODO have flattened buffer behavior struct that gets sent to it on each change.
60+
5361
#[serde_inline_default]
5462
#[derive(Debug, Clone, Serialize, Deserialize, StructTable, Derivative)]
5563
#[derivative(Default)]
56-
pub struct Behavior {
57-
#[serde_inline_default(true)]
58-
#[derivative(Default(value = "true"))]
59-
/// Use text box to type in before sending, with history. If disabled, sends keyboard inputs directly (TODO).
60-
pub fake_shell: bool,
61-
62-
#[serde(default)]
63-
/// Persist Fake Shell's command history across sessions (TODO).
64-
pub retain_history: bool,
65-
64+
pub struct Rendering {
6665
#[serde_inline_default(UserEcho::All)]
6766
#[derivative(Default(value = "UserEcho::All"))]
6867
#[table(values = [UserEcho::None, UserEcho::All, UserEcho::NoBytes, UserEcho::NoMacros, UserEcho::NoMacrosOrBytes])]
@@ -73,9 +72,27 @@ pub struct Behavior {
7372
/// Show timestamps next to each incoming line.
7473
pub timestamps: bool,
7574

75+
#[serde(default)]
76+
/// Show buffer index and length next to line.
77+
pub show_indices: bool,
78+
7679
#[serde(default)]
7780
/// Wrap text longer than the screen.
7881
pub wrap_text: bool,
82+
}
83+
84+
#[serde_inline_default]
85+
#[derive(Debug, Clone, Serialize, Deserialize, StructTable, Derivative)]
86+
#[derivative(Default)]
87+
pub struct Behavior {
88+
#[serde_inline_default(true)]
89+
#[derivative(Default(value = "true"))]
90+
/// Use text box to type in before sending, with history. If disabled, sends keyboard inputs directly (TODO).
91+
pub fake_shell: bool,
92+
93+
#[serde(default)]
94+
/// Persist Fake Shell's command history across sessions (TODO).
95+
pub retain_history: bool,
7996

8097
#[serde_inline_default(true)]
8198
#[derivative(Default(value = "true"))]

src/traits.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use ratatui::{
77
text::{Line, Span},
88
};
99

10+
use crate::tui::buffer::LineEnding;
11+
1012
/// Trait that provides simple methods to get the last valid index of a collection or slice.
1113
pub trait LastIndex {
1214
/// Returns `true` if the given index matches the index of the last element in the collection.
@@ -63,6 +65,10 @@ pub trait ByteSuffixCheck {
6365
///
6466
/// Returns `false` if there's any mismatch, or if the checked collection is shorter than the suffix.
6567
fn has_byte_suffix(&self, expected: &[u8]) -> bool;
68+
/// Returns `true` if the collection ends with the supplied line ending.
69+
///
70+
/// Returns `false` if there's any mismatch, if the checked collection is shorter than the suffix, or if the line ending is None.
71+
fn has_line_ending(&self, line_ending: &LineEnding) -> bool;
6672
}
6773
impl ByteSuffixCheck for [u8] {
6874
fn has_byte_suffix(&self, expected: &[u8]) -> bool {
@@ -74,6 +80,14 @@ impl ByteSuffixCheck for [u8] {
7480
&self[start..] == expected
7581
}
7682
}
83+
fn has_line_ending(&self, line_ending: &LineEnding) -> bool {
84+
match line_ending {
85+
LineEnding::None => false,
86+
LineEnding::MultiByte(cs, _) | LineEnding::Byte(cs) => {
87+
self.has_byte_suffix(cs.as_bytes())
88+
}
89+
}
90+
}
7791
}
7892

7993
/// Trait that provides a single method to get the first `N` "Unicode Scalar Values" from a string slice.

0 commit comments

Comments
 (0)