Skip to content

Commit

Permalink
fix: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuswhite committed Feb 9, 2024
1 parent 609a55e commit ecbc626
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 89 deletions.
38 changes: 1 addition & 37 deletions src/command_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rand::seq::SliceRandom;
use std::cmp::{max, min};
use std::collections::btree_map::BTreeMap;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::{Arc, Mutex};
use std::thread;
Expand Down Expand Up @@ -509,42 +509,6 @@ impl<B: Backend + Send + Sync + 'static> CommandBar<B> {

commands
}

#[allow(unused)]
fn load_file(&mut self, filepath: &Path) -> Result<String, ()> {
let Ok(file_read) = std::fs::read(filepath) else {
self.set_error_pop_up(format!("Cannot find {:?} filepath", filepath));
return Err(());
};

let Ok(file_str) = std::str::from_utf8(file_read.as_slice()) else {
self.set_error_pop_up(format!("The file {:?} has non UTF-8 characters", filepath));
return Err(());
};

Ok(file_str.to_string())
}

#[allow(unused)]
fn send_file(&mut self, filepath: &str, delay: Option<Duration>) {
if let Ok(str_send) = self.load_file(Path::new(filepath)) {
let str_send_splitted = str_send.split('\n');
let total = str_send_splitted.clone().collect::<Vec<_>>().len();
let interface = self.interface.lock().unwrap();
for (i, str_split) in str_send_splitted.enumerate() {
interface.send(UserTxData::File(
i,
total,
filepath.to_string(),
str_split.to_string(),
));

if let Some(delay) = delay {
sleep(delay);
}
}
}
}
}

enum InputEvent {
Expand Down
16 changes: 0 additions & 16 deletions src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pub enum UserTxData {
Command(String, String),
HexString(Vec<u8>),
PluginSerialTx(String, Vec<u8>),
#[allow(unused)]
File(usize, usize, String, String),
}

#[derive(Clone)]
Expand All @@ -18,14 +16,12 @@ pub enum SerialRxData {
ConfirmData(DateTime<Local>, String),
ConfirmCommand(DateTime<Local>, String, String),
ConfirmHexString(DateTime<Local>, Vec<u8>),
ConfirmFile(DateTime<Local>, usize, usize, String, String),
Plugin(DateTime<Local>, String, String),
ConfirmPluginSerialTx(DateTime<Local>, String, Vec<u8>),
FailPlugin(DateTime<Local>, String, String),
FailData(DateTime<Local>, String),
FailCommand(DateTime<Local>, String, String),
FailHexString(DateTime<Local>, Vec<u8>),
FailFile(DateTime<Local>, usize, usize, String, String),
FailPluginSerialTx(DateTime<Local>, String, Vec<u8>),
}

Expand Down Expand Up @@ -60,12 +56,6 @@ impl Into<ViewData> for SerialRxData {
Color::Black,
Color::Yellow,
),
SerialRxData::ConfirmFile(timestamp, idx, total, filename, content) => ViewData::new(
timestamp,
format!("{}[{}/{}]: <{}>", filename, idx, total, content),
Color::Black,
Color::LightMagenta,
),
SerialRxData::Plugin(timestamp, plugin_name, message) => ViewData::new(
timestamp,
format!(" [{plugin_name}] {message} "),
Expand Down Expand Up @@ -96,12 +86,6 @@ impl Into<ViewData> for SerialRxData {
Color::White,
Color::LightRed,
),
SerialRxData::FailFile(timestamp, idx, total, filename, content) => ViewData::new(
timestamp,
format!("Cannot send {}[{}/{}]: <{}>", filename, idx, total, content),
Color::White,
Color::LightRed,
),
SerialRxData::FailPlugin(timestamp, plugin_name, message) => ViewData::new(
timestamp,
format!(" [{plugin_name}] {message} "),
Expand Down
1 change: 0 additions & 1 deletion src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ impl Plugin {
self.name.as_str()
}

#[allow(unused)]
pub fn serial_rx_call(&self, msg: Vec<u8>) -> SerialRxCall {
let lua = Lua::new();
let code = self.code.as_str();
Expand Down
35 changes: 0 additions & 35 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ impl SerialIF {
format!("Serial {}:{}bps", self.port, self.baudrate)
}

#[allow(unused)]
pub fn set_port(&mut self, _port: String) {
self.port = _port;
}
#[allow(unused)]
pub fn set_baudrate(&mut self, _baudrate: u32) {
self.baudrate = _baudrate;
}

pub fn new(port: &str, baudrate: u32) -> Self {
let (serial_tx, serial_rx) = channel();
let (data_tx, data_rx) = channel();
Expand Down Expand Up @@ -191,32 +182,6 @@ impl SerialIF {
.expect("Cannot send hex string fail"),
}
}
UserTxData::File(idx, total, filename, content) => {
match serial.write(format!("{content}\n").as_bytes()) {
Ok(_) => {
data_tx
.send(SerialRxData::ConfirmFile(
Local::now(),
idx,
total,
filename,
content,
))
.expect("Cannot send file confirm");
}
Err(_) => {
data_tx
.send(SerialRxData::FailFile(
Local::now(),
idx,
total,
filename,
content,
))
.expect("Cannot send file fail");
}
}
}
}
}

Expand Down

0 comments on commit ecbc626

Please sign in to comment.