Skip to content

Commit a062ec8

Browse files
fix: remove tweet functionality if no browser available
2 parents dd5dcf0 + ea78de7 commit a062ec8

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "thokr"
33
description = "a sleek typing tui written in rust"
4-
version = "0.1.1"
4+
version = "0.1.2"
55
readme = "README.md"
66
repository = "https://github.com/coloradocolby/thokr.git"
77
homepage = "https://github.com/coloradocolby/thokr"
@@ -19,7 +19,7 @@ serde_json = "1.0.79"
1919
rand = "0.8.5"
2020
itertools = "0.10.3"
2121
unicode-width = "0.1.9"
22-
webbrowser = "0.6.0"
22+
webbrowser = "0.7.1"
2323
crossterm = "0.23.2"
2424
strum_macros = "0.24.0"
2525
include_dir = "0.7.2"

src/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use tui::{
2222
backend::{Backend, CrosstermBackend},
2323
Frame, Terminal,
2424
};
25+
use webbrowser::Browser;
2526

2627
/// a sleek typing tui written in rust
2728
#[derive(Parser, Debug, Clone)]
@@ -182,8 +183,10 @@ fn start_tui<B: Backend>(
182183
}
183184
true => match key.code {
184185
KeyCode::Char('t') => {
185-
webbrowser::open(&format!("https://twitter.com/intent/tweet?text={}%20wpm%20%2F%20{}%25%20acc%20%2F%20{:.2}%20sd%0A%0Ahttps%3A%2F%2Fgithub.com%2Fcoloradocolby%2Fthokr", app.thok.wpm, app.thok.accuracy, app.thok.std_dev))
186+
if Browser::is_available() {
187+
webbrowser::open(&format!("https://twitter.com/intent/tweet?text={}%20wpm%20%2F%20{}%25%20acc%20%2F%20{:.2}%20sd%0A%0Ahttps%3A%2F%2Fgithub.com%2Fcoloradocolby%2Fthokr", app.thok.wpm, app.thok.accuracy, app.thok.std_dev))
186188
.unwrap_or_default();
189+
}
187190
}
188191
KeyCode::Char('r') => {
189192
exit_type = ExitType::Restart;

src/ui.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use tui::{
66
widgets::{Axis, Chart, Dataset, GraphType, Paragraph, Widget, Wrap},
77
};
88
use unicode_width::UnicodeWidthStr;
9+
use webbrowser::Browser;
910

1011
use crate::thok::{Outcome, Thok};
1112

@@ -184,7 +185,11 @@ impl Widget for &Thok {
184185
stats.render(chunks[1], buf);
185186

186187
let legend = Paragraph::new(Span::styled(
187-
String::from("(r)etry / (n)ew / (t)weet / (esc)ape"),
188+
String::from(if Browser::is_available() {
189+
"(r)etry / (n)ew / (t)weet / (esc)ape"
190+
} else {
191+
"(r)etry / (n)ew / (esc)ape"
192+
}),
188193
italic_style,
189194
));
190195

0 commit comments

Comments
 (0)