Skip to content

Commit af826de

Browse files
committed
cargo format
1 parent 1455c5e commit af826de

8 files changed

Lines changed: 34 additions & 37 deletions

File tree

src/config.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use clap::ValueEnum;
2-
use std::sync::{
3-
Arc, Mutex as StdMutex,
4-
atomic::AtomicBool,
5-
};
62
use std::io::BufWriter;
3+
use std::sync::{Arc, Mutex as StdMutex, atomic::AtomicBool};
74

85
/// Which line ending to send when you press Enter
96
#[derive(Copy, Clone, Debug, ValueEnum)]
@@ -27,7 +24,7 @@ impl LineEnding {
2724
LineEnding::Crlf => "CRLF (\\r\\n)",
2825
}
2926
}
30-
27+
3128
pub fn bytes(self) -> &'static [u8] {
3229
match self {
3330
LineEnding::None => b"",
@@ -43,4 +40,4 @@ pub struct UiConfig {
4340
pub line_ending: LineEnding,
4441
pub tx_log: Option<Arc<StdMutex<BufWriter<std::fs::File>>>>,
4542
pub log_ts: bool,
46-
}
43+
}

src/logging.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn create_log_writer(path: &PathBuf, log_type: &str) -> Result<LogWriter> {
1212
.append(true)
1313
.open(path)
1414
.with_context(|| format!("Failed to open {} log file: {}", log_type, path.display()))?;
15-
15+
1616
println!("Logging {} to: {}", log_type, path.display());
1717
Ok(Arc::new(Mutex::new(BufWriter::new(file))))
1818
}
@@ -29,4 +29,4 @@ pub fn create_tx_log_writer(path: Option<&PathBuf>) -> Result<Option<LogWriter>>
2929
Some(path) => Ok(Some(create_log_writer(path, "TX")?)),
3030
None => Ok(None),
3131
}
32-
}
32+
}

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use config::{LineEnding, UiConfig};
1010
use crossterm::terminal;
1111
use logging::{create_rx_log_writer, create_tx_log_writer};
1212
use port_discovery::{choose_port_interactive, get_available_ports, print_ports};
13-
use ratatui::{backend::CrosstermBackend, Terminal};
13+
use ratatui::{Terminal, backend::CrosstermBackend};
1414
use serial_io::{SerialData, SerialReader};
1515
use serialport::SerialPort;
1616
use std::io::Read;
@@ -20,8 +20,8 @@ use std::sync::{
2020
atomic::{AtomicBool, Ordering},
2121
};
2222
use std::time::Duration;
23-
use tokio::sync::{mpsc, Mutex};
24-
use ui::{run_ui, UiMessage};
23+
use tokio::sync::{Mutex, mpsc};
24+
use ui::{UiMessage, run_ui};
2525

2626
/// sermonizer — a tiny, friendly serial monitor
2727
#[derive(Parser, Debug)]
@@ -199,4 +199,4 @@ async fn main() -> Result<()> {
199199

200200
println!("\nDisconnected. Bye!");
201201
Ok(())
202-
}
202+
}

src/port_discovery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{bail, Context, Result};
1+
use anyhow::{Context, Result, bail};
22
use serialport::{SerialPortInfo, SerialPortType};
33
use std::io::{self, Write};
44

@@ -77,4 +77,4 @@ pub fn choose_port_interactive(ports: &[SerialPortInfo]) -> Result<String> {
7777
Ok(name)
7878
}
7979
}
80-
}
80+
}

src/serial_io.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use anyhow::Result;
2+
use chrono::Utc;
23
use serialport::SerialPort;
34
use std::sync::Arc;
45
use std::sync::atomic::{AtomicBool, Ordering};
5-
use tokio::sync::{mpsc, Mutex};
6-
use chrono::Utc;
6+
use tokio::sync::{Mutex, mpsc};
77

88
#[derive(Debug, Clone)]
99
pub enum SerialData {
@@ -82,34 +82,34 @@ impl SerialReader {
8282
fn format_hex_data(&mut self, bytes: &[u8]) -> String {
8383
let capacity = if self.log_ts { 32 } else { 0 } + bytes.len() * 3; // Estimate capacity
8484
let mut hex_str = String::with_capacity(capacity);
85-
85+
8686
if self.log_ts {
8787
hex_str.push_str("[");
8888
hex_str.push_str(&Utc::now().format("%Y-%m-%d %H:%M:%S%.3f").to_string());
8989
hex_str.push_str("] ");
9090
}
91-
91+
9292
// Optimize hex formatting with pre-allocated string
9393
for (i, b) in bytes.iter().enumerate() {
9494
if i > 0 {
9595
hex_str.push(' ');
9696
}
9797
hex_str.push_str(&format!("{:02X}", b));
9898
}
99-
99+
100100
hex_str
101101
}
102102

103103
fn format_text_data(&mut self, bytes: &[u8]) -> String {
104104
let capacity = if self.log_ts { 32 } else { 0 } + bytes.len();
105105
let mut text = String::with_capacity(capacity);
106-
106+
107107
if self.log_ts {
108108
text.push_str("[");
109109
text.push_str(&Utc::now().format("%Y-%m-%d %H:%M:%S%.3f").to_string());
110110
text.push_str("] ");
111111
}
112-
112+
113113
// Use from_utf8_lossy but avoid extra allocations where possible
114114
text.push_str(&String::from_utf8_lossy(bytes));
115115
text
@@ -119,11 +119,11 @@ impl SerialReader {
119119
if let Some(w) = &self.rx_log_writer {
120120
if let Ok(mut lw) = w.lock() {
121121
use std::io::Write;
122-
122+
123123
if self.log_ts {
124124
let _ = write!(lw, "[{}] ", Utc::now().format("%Y-%m-%d %H:%M:%S%.3f"));
125125
}
126-
126+
127127
if self.hex_mode {
128128
for (i, b) in bytes.iter().enumerate() {
129129
let separator = if i + 1 == bytes.len() { "" } else { " " };
@@ -133,7 +133,7 @@ impl SerialReader {
133133
} else {
134134
let _ = lw.write_all(bytes);
135135
}
136-
136+
137137
let _ = lw.flush();
138138
}
139139
}
@@ -148,4 +148,4 @@ pub async fn write_bytes_async(
148148
guard.write_all(bytes)?;
149149
guard.flush()?;
150150
Ok(())
151-
}
151+
}

src/ui/app_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl AppState {
5555
self.auto_scroll_state
5656
.select(Some(self.output_lines.len() - 1));
5757
}
58-
58+
5959
self.needs_render = true;
6060
}
6161
}
@@ -167,4 +167,4 @@ impl AppState {
167167
pub fn mark_rendered(&mut self) {
168168
self.needs_render = false;
169169
}
170-
}
170+
}

src/ui/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ pub use app_state::AppState;
55
pub use rendering::draw_ui;
66

77
use anyhow::Result;
8-
use crossterm::{
9-
event::{self, Event, KeyCode, KeyEventKind, KeyModifiers},
10-
};
11-
use ratatui::{backend::Backend, Terminal};
12-
use std::sync::atomic::Ordering;
8+
use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
9+
use ratatui::{Terminal, backend::Backend};
1310
use std::sync::Arc;
11+
use std::sync::atomic::Ordering;
1412
use std::time::Duration;
1513
use tokio::sync::mpsc;
1614

1715
use crate::config::UiConfig;
18-
use crate::serial_io::{write_bytes_async, SerialData};
16+
use crate::serial_io::{SerialData, write_bytes_async};
1917
use chrono::Utc;
2018

2119
#[derive(Debug)]
@@ -92,7 +90,9 @@ async fn handle_key_event(
9290
ui_config: &UiConfig,
9391
) -> Result<()> {
9492
match key.code {
95-
KeyCode::Char(c) if key.modifiers.contains(KeyModifiers::CONTROL) && (c == 'c' || c == 'd') => {
93+
KeyCode::Char(c)
94+
if key.modifiers.contains(KeyModifiers::CONTROL) && (c == 'c' || c == 'd') =>
95+
{
9696
app_state.quit();
9797
}
9898
KeyCode::Esc => {
@@ -173,4 +173,4 @@ async fn handle_enter_key(
173173
}
174174

175175
Ok(())
176-
}
176+
}

src/ui/rendering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use super::app_state::AppState;
12
use ratatui::{
23
Frame,
34
layout::{Constraint, Direction, Layout},
45
style::{Color, Style},
56
widgets::{Block, Borders, List, ListItem, Paragraph},
67
};
7-
use super::app_state::AppState;
88

99
pub fn draw_ui(f: &mut Frame, app_state: &mut AppState) {
1010
let chunks = Layout::default()
@@ -58,4 +58,4 @@ pub fn draw_ui(f: &mut Frame, app_state: &mut AppState) {
5858
chunks[1].x + app_state.input_line.len() as u16 + 1,
5959
chunks[1].y + 1,
6060
));
61-
}
61+
}

0 commit comments

Comments
 (0)