Skip to content

Commit 00d0467

Browse files
committed
fix: malformed hexyl display for specific width
1 parent 4260f3d commit 00d0467

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/tui/connection_view.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub struct ConnectionView {
2323
ctx: Arc<Ctx>,
2424
float_numbers: bool,
2525
unsigned_numbers: bool,
26-
highlight_copy_char_stack: u8,
27-
highlight_copy_service_stack: u8,
26+
highlight_copy_char_renders_delay_stack: u8,
27+
highlight_copy_service_renders_delay_stack: u8,
2828
clipboard: Option<ClipboardContext>,
2929
}
3030

@@ -61,8 +61,8 @@ impl AppRoute for ConnectionView {
6161
ctx,
6262
float_numbers: false,
6363
unsigned_numbers: false,
64-
highlight_copy_char_stack: 0,
65-
highlight_copy_service_stack: 0,
64+
highlight_copy_char_renders_delay_stack: 0,
65+
highlight_copy_service_renders_delay_stack: 0,
6666
clipboard: ClipboardContext::new().ok(),
6767
}
6868
}
@@ -86,11 +86,11 @@ impl AppRoute for ConnectionView {
8686
(Route::CharacteristicView { characteristic, .. }, Some(clipboard)) => match key.code {
8787
KeyCode::Char('c') => {
8888
let _ = clipboard.set_contents(characteristic.uuid.to_string());
89-
self.highlight_copy_char_stack = 4;
89+
self.highlight_copy_char_renders_delay_stack = 4;
9090
}
9191
KeyCode::Char('s') => {
9292
let _ = clipboard.set_contents(characteristic.service_uuid.to_string());
93-
self.highlight_copy_service_stack = 4;
93+
self.highlight_copy_service_renders_delay_stack = 4;
9494
}
9595
_ => (),
9696
},
@@ -173,16 +173,22 @@ impl AppRoute for ConnectionView {
173173
let mut writer = std::io::Cursor::new(&mut hexyl_output_buf);
174174
let mut printer = hexyl::PrinterBuilder::new(&mut writer)
175175
.show_color(true)
176-
.num_panels(if area.width > 60 { 2 } else { 1 })
176+
.num_panels(if area.width > 70 { 2 } else { 1 })
177177
.with_border_style(hexyl::BorderStyle::Unicode)
178178
.build();
179179

180180
printer.print_all(&value.data[..]).unwrap();
181181
}
182182

183183
use ansi_to_tui::IntoText;
184-
let a = hexyl_output_buf.into_text().unwrap().into_iter();
185-
text.extend(a);
184+
if let Ok(output) = hexyl_output_buf.into_text() {
185+
text.extend(output.into_iter());
186+
} else {
187+
tracing::error!(
188+
?hexyl_output_buf,
189+
"Failed to parse and display hexyl output"
190+
);
191+
}
186192
} else {
187193
text.push(Line::from("No value received yet"));
188194
}
@@ -223,27 +229,27 @@ impl AppRoute for ConnectionView {
223229
(
224230
"c",
225231
"Copy characteristic UUID",
226-
self.highlight_copy_char_stack > 0,
232+
self.highlight_copy_char_renders_delay_stack > 0,
227233
)
228234
}),
229235
self.clipboard.as_ref().map(|_| {
230236
(
231237
"s",
232238
"Copy services UUID",
233-
self.highlight_copy_service_stack > 0,
239+
self.highlight_copy_service_renders_delay_stack > 0,
234240
)
235241
}),
236242
]),
237243
chunks[1],
238244
);
239245
}
240246

241-
if self.highlight_copy_char_stack > 0 {
242-
self.highlight_copy_char_stack -= 1;
247+
if self.highlight_copy_char_renders_delay_stack > 0 {
248+
self.highlight_copy_char_renders_delay_stack -= 1;
243249
}
244250

245-
if self.highlight_copy_service_stack > 0 {
246-
self.highlight_copy_service_stack -= 1;
251+
if self.highlight_copy_service_renders_delay_stack > 0 {
252+
self.highlight_copy_service_renders_delay_stack -= 1;
247253
}
248254

249255
Ok(())

0 commit comments

Comments
 (0)