diff --git a/src/messages.rs b/src/messages.rs index 7d6be1f..e0143e2 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -167,7 +167,7 @@ impl Into for SerialRxData { } => { if is_successful { RichText::from_string( - format!(" [{plugin_name}] => {:02x?} ", content), + format!(" [{plugin_name}] => {} ", String::from_utf8_lossy(&content)), Color::Black, Color::White, ) @@ -175,7 +175,10 @@ impl Into for SerialRxData { .into_view_data(timestamp) } else { RichText::from_string( - format!(" [{plugin_name}] => Fail to send {:02x?} ", content), + format!( + " [{plugin_name}] => Fail to send {} ", + String::from_utf8_lossy(&content) + ), Color::White, Color::Red, ) diff --git a/src/rich_string.rs b/src/rich_string.rs index 3f3ad46..fcdb094 100644 --- a/src/rich_string.rs +++ b/src/rich_string.rs @@ -72,7 +72,7 @@ impl RichTextWithInvisible { } let (fg, bg) = (rich_text.fg, rich_text.bg); - let (hl_fg, hl_bg) = Self::get_colors(rich_text.fg, rich_text.fg, true); + let (hl_fg, hl_bg) = Self::get_colors(rich_text.fg, rich_text.bg, true); let (buffer, state, acc) = rich_text.content.into_iter().fold( (vec![], State::None, vec![]), @@ -93,7 +93,7 @@ impl RichTextWithInvisible { ) } else { ( - vec![], + vec![byte], State::Invisible, acc.into_iter() .chain([RichText::new(buffer, rich_text.fg, rich_text.bg)]) @@ -104,7 +104,7 @@ impl RichTextWithInvisible { State::Invisible => { if Self::is_visible(byte) { ( - vec![], + vec![byte], State::Visible, acc.into_iter() .chain([RichText::new(Self::bytes_to_rich(buffer), hl_fg, hl_bg)]) diff --git a/src/serial.rs b/src/serial.rs index 626713a..0c7be97 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -118,7 +118,9 @@ impl SerialIF { match data_to_send { UserTxData::Exit => break 'task, UserTxData::Data { content } => { - match serial.write(format!("{content}\r\n").as_bytes()) { + let content = format!("{content}\r\n"); + + match serial.write(content.as_bytes()) { Ok(_) => { data_tx .send(SerialRxData::TxData { @@ -142,28 +144,32 @@ impl SerialIF { UserTxData::Command { command_name, content, - } => match serial.write(format!("{content}\r\n").as_bytes()) { - Ok(_) => { - data_tx - .send(SerialRxData::Command { - timestamp: Local::now(), - command_name, - content, - is_successful: true, - }) - .expect("Cannot send command confirm"); - } - Err(_) => { - data_tx - .send(SerialRxData::Command { - timestamp: Local::now(), - command_name, - content, - is_successful: false, - }) - .expect("Cannot send command fail"); + } => { + let content = format!("{content}\r\n"); + + match serial.write(content.as_bytes()) { + Ok(_) => { + data_tx + .send(SerialRxData::Command { + timestamp: Local::now(), + command_name, + content, + is_successful: true, + }) + .expect("Cannot send command confirm"); + } + Err(_) => { + data_tx + .send(SerialRxData::Command { + timestamp: Local::now(), + command_name, + content, + is_successful: false, + }) + .expect("Cannot send command fail"); + } } - }, + } UserTxData::HexString { content } => match serial.write(&content) { Ok(_) => data_tx .send(SerialRxData::HexString {