Skip to content

Commit

Permalink
fix: remove tweet functionality if no browser available
Browse files Browse the repository at this point in the history
  • Loading branch information
coloradocolby committed Apr 27, 2022
1 parent dd5dcf0 commit ea78de7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "thokr"
description = "a sleek typing tui written in rust"
version = "0.1.1"
version = "0.1.2"
readme = "README.md"
repository = "https://github.com/coloradocolby/thokr.git"
homepage = "https://github.com/coloradocolby/thokr"
Expand All @@ -19,7 +19,7 @@ serde_json = "1.0.79"
rand = "0.8.5"
itertools = "0.10.3"
unicode-width = "0.1.9"
webbrowser = "0.6.0"
webbrowser = "0.7.1"
crossterm = "0.23.2"
strum_macros = "0.24.0"
include_dir = "0.7.2"
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use tui::{
backend::{Backend, CrosstermBackend},
Frame, Terminal,
};
use webbrowser::Browser;

/// a sleek typing tui written in rust
#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -182,8 +183,10 @@ fn start_tui<B: Backend>(
}
true => match key.code {
KeyCode::Char('t') => {
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))
if Browser::is_available() {
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))
.unwrap_or_default();
}
}
KeyCode::Char('r') => {
exit_type = ExitType::Restart;
Expand Down
7 changes: 6 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tui::{
widgets::{Axis, Chart, Dataset, GraphType, Paragraph, Widget, Wrap},
};
use unicode_width::UnicodeWidthStr;
use webbrowser::Browser;

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

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

let legend = Paragraph::new(Span::styled(
String::from("(r)etry / (n)ew / (t)weet / (esc)ape"),
String::from(if Browser::is_available() {
"(r)etry / (n)ew / (t)weet / (esc)ape"
} else {
"(r)etry / (n)ew / (esc)ape"
}),
italic_style,
));

Expand Down

0 comments on commit ea78de7

Please sign in to comment.