Skip to content

Commit

Permalink
fix: fixes plugin serial tx presentation, richtext highlight backgrou…
Browse files Browse the repository at this point in the history
…nd and the presentation of user data and command
  • Loading branch information
matheuswhite committed Feb 21, 2024
1 parent 65cea97 commit d4add34
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
7 changes: 5 additions & 2 deletions src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,18 @@ impl Into<ViewData> 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,
)
.highlight_invisible()
.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,
)
Expand Down
6 changes: 3 additions & 3 deletions src/rich_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]),
Expand All @@ -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)])
Expand All @@ -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)])
Expand Down
50 changes: 28 additions & 22 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit d4add34

Please sign in to comment.