Add open in browser
This commit is contained in:
parent
2ee61a933a
commit
1664d98dbc
37
Cargo.lock
generated
37
Cargo.lock
generated
@ -788,6 +788,25 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-docker"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-wsl"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
|
||||
dependencies = [
|
||||
"is-docker",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
@ -950,6 +969,17 @@ version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "open"
|
||||
version = "5.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2483562e62ea94312f3576a7aca397306df7990b8d89033e18766744377ef95"
|
||||
dependencies = [
|
||||
"is-wsl",
|
||||
"libc",
|
||||
"pathdiff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.73"
|
||||
@ -1023,6 +1053,12 @@ version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "pathdiff"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
@ -1680,6 +1716,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"argh",
|
||||
"crossterm 0.29.0",
|
||||
"open",
|
||||
"ratatui",
|
||||
"reqwest",
|
||||
"rusqlite",
|
||||
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
argh = "0.1.13"
|
||||
crossterm = "0.29.0"
|
||||
open = "5.3.2"
|
||||
ratatui = "0.29.0"
|
||||
reqwest = { version = "0.12.20", features = ["blocking"] }
|
||||
rusqlite = { version = "0.36.0", features = ["bundled", "time"] }
|
||||
|
16
src/ui.rs
16
src/ui.rs
@ -41,6 +41,7 @@ enum TrsEvent {
|
||||
FocusArticles,
|
||||
FocusChannels,
|
||||
ToggleDebug,
|
||||
OpenArticle,
|
||||
Exit,
|
||||
}
|
||||
|
||||
@ -161,6 +162,20 @@ fn handle_events(state: &mut AppState) -> Result<()> {
|
||||
TrsEvent::Exit => state.exit = true,
|
||||
TrsEvent::FocusArticles => state.focussed = FocussedPane::Articles,
|
||||
TrsEvent::FocusChannels => state.focussed = FocussedPane::Channels,
|
||||
TrsEvent::OpenArticle => {
|
||||
if let Some(channel_idx) = state.highlighted_channel {
|
||||
if let Some(article_idx) = state.highlighted_article {
|
||||
if let Some(channel) = state.channels.get(channel_idx) {
|
||||
if let Some(article) = channel.articles.get(article_idx) {
|
||||
let open_res = open::that(&article.link);
|
||||
if let Err(e) = open_res {
|
||||
eprintln!("Failed to open article: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
@ -180,6 +195,7 @@ fn parse_trs_event(state: &AppState, raw_event: Event) -> TrsEvent {
|
||||
},
|
||||
KeyCode::Char('k') => TrsEvent::FocusEntryUp,
|
||||
KeyCode::Char('d') if state.debug_enabled => return TrsEvent::ToggleDebug,
|
||||
KeyCode::Enter => return TrsEvent::OpenArticle,
|
||||
_ => TrsEvent::None,
|
||||
},
|
||||
_ => TrsEvent::None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user