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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typy-cli"
version = "0.1.0"
version = "0.7.0"
edition = "2021"

[dependencies]
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ If you prefer to get the newest version and compile it yourself, follow these st
sudo mv target/release/typy /usr/local/bin/
```

4. Ensure the `words.txt` file is in the correct location:
4. Ensure the `english.txt` file is in the correct location:
```bash
mkdir -p ~/.local/share/typy
cp resources/words.txt ~/.local/share/typy/
cp resources/english.txt ~/.local/share/typy/
```

## Flags
Expand Down Expand Up @@ -105,6 +105,9 @@ style = "SteadyBar" # possible options are: DefaultUserShape, BlinkingBlock, Ste
default_mode = "normal" # possible modes are "normal"|"uppercase"|"punctuation", combinations of modes is also possible e.g: "uppercase, punctuation"
uppercase_chance = "3" # possible are values between 0 and 1, if value is too high it gets clamped to 1, if too low it gets clamped to 0
punctuation_chance = "0.5" # possible are values between 0 and 1, if value is too high it gets clamped to 1, if too low it gets clamped to 0

[language]
lang = "english" # select your desired language
```

To apply the configuration, you can either edit the `config.toml` file directly or use the `typy -c` command to to open the file in your preferred editor:
Expand All @@ -127,6 +130,18 @@ This will display the stats of the last 10 games and looks something like this:
![Stats](./docs/assets/snapshot_2025-02-24_00-28-16.png)
To close this view press `Ctrl + c` or `esc`.

## Language
The language files are located at `~/.local/share/typy/`. The default language is `english`. You can change the language by editing the `config.toml` file or by using the
`typy -c` command. If you want to add a new language you can create a new file in the `~/.local/share/typy/` directory and add the words in the following format:
```txt
word1
word2
...
```
The language file should be named after the language you want to add. For example, if you want to add a German language file, you would create a file named `german.txt` and add the German words to it.
If you want to use the new language you need to change the `lang` field in the `config.toml` file to the name of the language file without the `.txt` extension.
If you want to provide a new language to the Typy repository, feel free to create a pull request. Atm I only have the `english.txt` file in the repository.

## Uninstall
```bash
curl -sSL https://raw.githubusercontent.com/Pazl27/typy-cli/master/scripts/uninstall.sh | bash
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Define paths
BIN_NAME="typy"
LOCAL_DIR="$HOME/.local/share"
CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/words.txt"
CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/english.txt"
INSTALL_DIR="$HOME/your-repo"
GIT_TAG="v0.7.0"

Expand Down Expand Up @@ -36,6 +36,6 @@ move_binary

# Move any required files to the ~/.local folder (e.g., configuration files)
echo "Setting up configuration files..."
curl -L https://github.com/Pazl27/typy-cli/releases/download/$GIT_TAG/words.txt -o "$CONFIG_PATH"
curl -L https://github.com/Pazl27/typy-cli/releases/download/$GIT_TAG/english.txt -o "$CONFIG_PATH"

echo "Installation complete! You can now run the CLI tool by typing '$BIN_NAME' in your terminal."
2 changes: 1 addition & 1 deletion scripts/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
BIN_NAME="typy"
LOCAL_DIR="$HOME/.local/share"
BIN_PATH="/usr/bin/$BIN_NAME"
CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/words.txt"
CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/english.txt"
CONFIG_DIR="$LOCAL_DIR/$BIN_NAME"

# Function to remove the binary with appropriate privileges
Expand Down
27 changes: 27 additions & 0 deletions src/config/config_tables/language.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::config::toml_parser::get_config;

pub struct Language {
pub lang: String,
}

impl Language {
pub fn new() -> Self {
let theme_colors: Language = match get_config().lock().unwrap().get_language() {
Some(language) => {
let lang = language.lang.unwrap_or("english".to_string());

Language { lang }
}
None => Language::default(),
};
theme_colors
}
}

impl Default for Language {
fn default() -> Self {
Language {
lang: "english".to_string(),
}
}
}
1 change: 1 addition & 0 deletions src/config/config_tables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod cursor_style;
pub mod graph_colors;
pub mod mode_settings;
pub mod theme;
pub mod language;
12 changes: 12 additions & 0 deletions src/config/toml_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ pub struct ModesTable {
pub punctuation_chance: Option<String>,
}

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

#[derive(Serialize, Deserialize)]
pub struct ConfigToml {
theme: Option<ThemeTable>,
graph: Option<GraphTable>,
cursor: Option<CursorTable>,
modes: Option<ModesTable>,
language: Option<LanguageTable>,
}

impl ConfigToml {
Expand Down Expand Up @@ -83,6 +90,10 @@ impl ConfigToml {
pub fn get_modes(&self) -> Option<ModesTable> {
self.modes.clone()
}

pub fn get_language(&self) -> Option<LanguageTable> {
self.language.clone()
}
}

impl Default for ConfigToml {
Expand All @@ -92,6 +103,7 @@ impl Default for ConfigToml {
graph: None,
cursor: None,
modes: None,
language: None,
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/terminal/game.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::keyboard::{handle_input, InputAction};
use anyhow::{Context, Result};
use crossterm::cursor::{self, SetCursorStyle};
use crossterm::event::poll;
Expand All @@ -8,7 +9,6 @@ use crossterm::{
terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType},
ExecutableCommand,
};
use super::keyboard::{handle_input, InputAction};
use std::io::stdout;
use std::io::Write;
use std::sync::atomic::{AtomicBool, Ordering};
Expand All @@ -17,6 +17,7 @@ use std::thread;
use std::time::{Duration, Instant};

use crate::config::cursor_style::CursorKind;
use crate::config::language;
use crate::config::theme::ThemeColors;
use crate::mode::Mode;
use crate::scores::finish_overview;
Expand Down Expand Up @@ -65,10 +66,10 @@ impl Game {
pub fn run(mode: Mode, theme: ThemeColors) -> Result<()> {
let mut stdout = stdout();

let mut game = Game::new(
word_provider::get_words(".local/share/typy/words.txt")
.context("Failed to get words from file")?,
);
let language = language::Language::new();
let file_name = format!(".local/share/typy/{}.txt", language.lang);
let mut game =
Game::new(word_provider::get_words(&file_name).context("Failed to get words from file")?);

mode.transform(&mut game.list);

Expand Down Expand Up @@ -159,7 +160,6 @@ pub fn run(mode: Mode, theme: ThemeColors) -> Result<()> {
}

if !game.quit {

stdout.execute(cursor::Hide)?;
let score = Score::new(
stats.wpm() as u32,
Expand Down Expand Up @@ -243,4 +243,3 @@ fn start_timer(

Ok(())
}

2 changes: 1 addition & 1 deletion src/word_provider/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod finder_tests {

#[test]
fn test_read_file() {
let words = read_file("./resources/words.txt").unwrap();
let words = read_file("./resources/english.txt").unwrap();
assert_eq!(words.len(), 7776);
}

Expand Down
2 changes: 1 addition & 1 deletion src/word_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod word_provider_tests {

#[test]
fn test_get_words() {
let words = get_words("resources/words.txt");
let words = get_words("resources/english.txt");

for word in &words.unwrap() {
let mut length = 0;
Expand Down