Skip to content

Commit

Permalink
Fix TUI channel panics (#63)
Browse files Browse the repository at this point in the history
Fix panics when sending to the TUI channel.

Because failing to send just means the other end hung up, we don't
really need to do anything special. It's totally expected that the other
side will hang up eventually. It's best for us to just break out of the
loop.

This also updates nushell to a revision I have right now that fixes
local socket, but this should probably be changed on release.

---------

Co-authored-by: amtoine <[email protected]>
  • Loading branch information
devyn and amtoine authored May 1, 2024
1 parent cf8c76a commit 15d8701
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 38 deletions.
73 changes: 46 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name = "nu_plugin_explore"
[dependencies]
anyhow = "1.0.73"
crossterm = "0.27.0"
nuon = { git = "https://github.com/nushell/nushell", rev = "2595f31541554c6d8602ebebc9dffbc4dd29dd89", package = "nuon" }
nu-plugin = { git = "https://github.com/nushell/nushell", rev = "2595f31541554c6d8602ebebc9dffbc4dd29dd89", package = "nu-plugin" }
nu-protocol = { git = "https://github.com/nushell/nushell", rev = "2595f31541554c6d8602ebebc9dffbc4dd29dd89", package = "nu-protocol", features = ["plugin"] }
nuon = { git = "https://github.com/nushell/nushell", tag = "0.93.0", package = "nuon" }
nu-plugin = { git = "https://github.com/nushell/nushell", tag = "0.93.0", package = "nu-plugin" }
nu-protocol = { git = "https://github.com/nushell/nushell", tag = "0.93.0", package = "nu-protocol", features = ["plugin"] }
ratatui = "0.26.1"
url = "2.4.0"

Expand All @@ -20,4 +20,4 @@ bench = false
[package]
edition = "2021"
name = "nu_plugin_explore"
version = "0.92.3-2595f31541554c6d8602ebebc9dffbc4dd29dd89"
version = "0.93.0"
2 changes: 1 addition & 1 deletion nupm.nuon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
name: nu_plugin_explore,
version: "0.92.3-2595f31541554c6d8602ebebc9dffbc4dd29dd89"
version: "0.93.0",
description: "A fast structured data explorer for Nushell.",
license: LICENSE,
type: custom
Expand Down
8 changes: 5 additions & 3 deletions src/nu/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ pub(crate) fn is_table(value: &Value) -> Table {
let mut rows = Vec::new();
for (i, val) in vals.iter().enumerate() {
match val.get_type() {
Type::Record(fields) => {
rows.push(fields.into_iter().collect::<HashMap<String, Type>>())
}
Type::Record(fields) => rows.push(
Vec::from(fields)
.into_iter()
.collect::<HashMap<String, Type>>(),
),
t => return Table::RowNotARecord(i, t),
};
}
Expand Down
10 changes: 7 additions & 3 deletions src/tui/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ impl EventHandler {
.unwrap_or(tick_rate);

if event::poll(timeout).expect("no events available") {
match event::read().expect("unable to read event") {
let result = match event::read().expect("unable to read event") {
CrosstermEvent::Key(e) => sender.send(Event::Key(e)),
CrosstermEvent::Mouse(e) => sender.send(Event::Mouse(e)),
CrosstermEvent::Resize(w, h) => sender.send(Event::Resize(w, h)),
_ => Ok(()),
};
if result.is_err() {
break;
}
.expect("failed to send terminal event")
}

if last_tick.elapsed() >= tick_rate {
sender.send(Event::Tick).expect("failed to send tick event");
if sender.send(Event::Tick).is_err() {
break;
}
last_tick = Instant::now();
}
}
Expand Down

0 comments on commit 15d8701

Please sign in to comment.