Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,088 changes: 1,088 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ lazy_static = "1.5.0"
anyhow = "1.0.95"
chrono = { version = "0.4", features = ["serde"] }
comfy-table = "7.1.4"
reqwest = { version = "0.12.12", features = ["blocking"] }
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ word and asks you to type it as fast as possible. The game tracks your typing sp
different game modes, such as uppercase and punctuation, to help you improve your typing skills in different areas.

## Installation
To install Typy on Linux, you can use the following command:
To install Typy, you can use the [Cargo] package manager:

[Cargo]: https://doc.rust-lang.org/cargo/

```bash
curl -sSL https://raw.githubusercontent.com/Pazl27/typy-cli/master/scripts/install.sh | bash
cargo install --git "https://github.com/Pazl27/typy-cli.git" --tag "v0.8.0"
```

This command downloads and runs the installation script from the Typy GitHub repository. The script will handle the installation process for you, ensuring that Typy is set up correctly on your system.

If you prefer to get the newest version and compile it yourself, follow these steps:

1. Clone the Typy repository:
Expand Down Expand Up @@ -144,5 +144,5 @@ If you want to provide a new language to the Typy repository, feel free to creat

## Uninstall
```bash
curl -sSL https://raw.githubusercontent.com/Pazl27/typy-cli/master/scripts/uninstall.sh | bash
cargo uninstall typy-cli
```
41 changes: 0 additions & 41 deletions scripts/install.sh

This file was deleted.

33 changes: 0 additions & 33 deletions scripts/uninstall.sh

This file was deleted.

21 changes: 11 additions & 10 deletions src/config/config_tables/cursor_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ use crate::config::toml_parser::get_config;
use crate::config::toml_parser::CursorTable;

pub struct CursorKind {
pub style: SetCursorStyle
pub style: SetCursorStyle,
}

impl CursorKind {
pub fn new() -> Self {

let cursor_table: CursorTable = get_config().lock().unwrap().get_cursor().unwrap_or(CursorTable {
style: Some("DefaultUserShape".to_owned())
});
let cursor_table: CursorTable =
get_config()
.lock()
.unwrap()
.get_cursor()
.unwrap_or(CursorTable {
style: Some("DefaultUserShape".to_owned()),
});

let cursor_kind = match cursor_table.style.as_deref() {
Some("DefaultUserShape") => SetCursorStyle::DefaultUserShape,
Expand All @@ -25,17 +29,14 @@ impl CursorKind {
_ => SetCursorStyle::DefaultUserShape,
};

CursorKind {
style: cursor_kind,
}
CursorKind { style: cursor_kind }
}
}

impl Default for CursorKind {
fn default() -> Self {
CursorKind {
style: SetCursorStyle::DefaultUserShape
style: SetCursorStyle::DefaultUserShape,
}
}
}

1 change: 0 additions & 1 deletion src/config/config_tables/graph_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub struct Graph {

impl Graph {
pub fn new() -> Self {

let theme_colors: Graph = match get_config().lock().unwrap().get_graph() {
Some(colors) => {
let data = colors
Expand Down
9 changes: 7 additions & 2 deletions src/config/config_tables/mode_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ impl ModeSettings {
let default_modes = settings
.default_mode
.map(|m| {
let modes: Vec<ModeType> = m.split(',')
let modes: Vec<ModeType> = m
.split(',')
.filter_map(|mode| ModeType::from_str(mode.trim()).ok())
.collect();
if modes.contains(&ModeType::Normal) {
Expand All @@ -37,7 +38,11 @@ impl ModeSettings {
.map(|c| c.clamp(0.0, 1.0))
.unwrap_or(0.2);

ModeSettings { default_modes, uppercase_chance, punctuation_chance }
ModeSettings {
default_modes,
uppercase_chance,
punctuation_chance,
}
}
None => ModeSettings::default(),
};
Expand Down
44 changes: 36 additions & 8 deletions src/config/config_tables/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct ThemeColors {

impl ThemeColors {
pub fn new() -> Self {

let theme_colors: ThemeColors = match get_config().lock().unwrap().get_theme() {
Some(colors) => {
let fg = colors
Expand Down Expand Up @@ -67,20 +66,49 @@ fn hex_to_rgb(hex: &str) -> Option<Color> {
}
}


#[cfg(test)]
mod theme_tests {
use super::*;

#[test]
fn test_hex_to_rgb() {
assert_eq!(hex_to_rgb("#ffffff"), Some(Color::Rgb { r: 255, g: 255, b: 255 }));
assert_eq!(
hex_to_rgb("#ffffff"),
Some(Color::Rgb {
r: 255,
g: 255,
b: 255
})
);
assert_eq!(hex_to_rgb("#000000"), Some(Color::Rgb { r: 0, g: 0, b: 0 }));
assert_eq!(hex_to_rgb("#ff0000"), Some(Color::Rgb { r: 255, g: 0, b: 0 }));
assert_eq!(hex_to_rgb("#00ff00"), Some(Color::Rgb { r: 0, g: 255, b: 0 }));
assert_eq!(hex_to_rgb("#0000ff"), Some(Color::Rgb { r: 0, g: 0, b: 255 }));
assert_eq!(hex_to_rgb("#123456"), Some(Color::Rgb { r: 18, g: 52, b: 86 }));
assert_eq!(hex_to_rgb("#abcdef"), Some(Color::Rgb { r: 171, g: 205, b: 239 }));
assert_eq!(
hex_to_rgb("#ff0000"),
Some(Color::Rgb { r: 255, g: 0, b: 0 })
);
assert_eq!(
hex_to_rgb("#00ff00"),
Some(Color::Rgb { r: 0, g: 255, b: 0 })
);
assert_eq!(
hex_to_rgb("#0000ff"),
Some(Color::Rgb { r: 0, g: 0, b: 255 })
);
assert_eq!(
hex_to_rgb("#123456"),
Some(Color::Rgb {
r: 18,
g: 52,
b: 86
})
);
assert_eq!(
hex_to_rgb("#abcdef"),
Some(Color::Rgb {
r: 171,
g: 205,
b: 239
})
);
assert_eq!(hex_to_rgb("#12345"), None);
assert_eq!(hex_to_rgb("#1234567"), None);
assert_eq!(hex_to_rgb("123456"), None);
Expand Down
40 changes: 11 additions & 29 deletions src/config/toml_parser.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
use std::fs;
use toml;
use serde::{Deserialize, Serialize};
use dirs::home_dir;
use std::path::PathBuf;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use std::sync::Mutex;
use toml;

#[derive(Serialize, Deserialize)]
#[derive(Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct ThemeTable {
pub fg: Option<String>,
pub missing: Option<String>,
pub error: Option<String>,
pub accent: Option<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct GraphTable {
pub data: Option<String>,
pub title: Option<String>,
pub axis: Option<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct CursorTable {
pub style: Option<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct ModesTable {
pub default_mode: Option<String>,
pub uppercase_chance: Option<String>,
pub punctuation_chance: Option<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct LanguageTable {
pub lang: Option<String>
pub lang: Option<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Default)]
pub struct ConfigToml {
theme: Option<ThemeTable>,
graph: Option<GraphTable>,
Expand Down Expand Up @@ -96,18 +91,6 @@ impl ConfigToml {
}
}

impl Default for ConfigToml {
fn default() -> Self {
ConfigToml {
theme: None,
graph: None,
cursor: None,
modes: None,
language: None,
}
}
}

// Declare the static instance of ConfigToml using lazy_static
lazy_static! {
static ref CONFIG: Mutex<ConfigToml> = Mutex::new(ConfigToml::new());
Expand All @@ -117,4 +100,3 @@ lazy_static! {
pub fn get_config() -> &'static Mutex<ConfigToml> {
&CONFIG
}

15 changes: 9 additions & 6 deletions src/mode/mode_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,21 @@ impl Mode {
modes.push(ModeType::Normal);
});

Ok(Mode { modes, duration: 0, settings })
Ok(Mode {
modes,
duration: 0,
settings,
})
}

pub fn add_duration(mut self, duration: u64) -> Self {
self.duration = duration;
self
}

pub fn transform(&self, list: &mut Vec<Vec<String>>) {
pub fn transform(&self, list: &mut [Vec<String>]) {
let mut rng = rand::rng();
let punctuations = vec![".", ",", "!", "?", ";", ":", "-"];
let punctuations = [".", ",", "!", "?", ";", ":", "-"];

for mode in &self.modes {
match mode {
Expand All @@ -90,11 +94,11 @@ impl Mode {
for sublist in list.iter_mut() {
let len = sublist.len();
if len > 1 {
for i in 0..len - 1 {
for item in sublist.iter_mut().take(len - 1) {
if rng.random_bool(self.settings.punctuation_chance.into()) {
let punctuation =
punctuations[rng.random_range(0..punctuations.len())];
sublist[i].push_str(punctuation);
item.push_str(punctuation);
}
}
}
Expand Down Expand Up @@ -155,4 +159,3 @@ mod mode_tests {
assert_eq!(list[0].len(), 2);
}
}

Loading