Skip to content

Commit be11777

Browse files
authored
Merge pull request #50 from Pazl27/44-new-language
44 new language
2 parents 1a81c77 + c11e1a8 commit be11777

File tree

12 files changed

+70
-16
lines changed

12 files changed

+70
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "typy-cli"
3-
version = "0.1.0"
3+
version = "0.7.0"
44
edition = "2021"
55

66
[dependencies]

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ If you prefer to get the newest version and compile it yourself, follow these st
5353
sudo mv target/release/typy /usr/local/bin/
5454
```
5555

56-
4. Ensure the `words.txt` file is in the correct location:
56+
4. Ensure the `english.txt` file is in the correct location:
5757
```bash
5858
mkdir -p ~/.local/share/typy
59-
cp resources/words.txt ~/.local/share/typy/
59+
cp resources/english.txt ~/.local/share/typy/
6060
```
6161

6262
## Flags
@@ -105,6 +105,9 @@ style = "SteadyBar" # possible options are: DefaultUserShape, BlinkingBlock, Ste
105105
default_mode = "normal" # possible modes are "normal"|"uppercase"|"punctuation", combinations of modes is also possible e.g: "uppercase, punctuation"
106106
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
107107
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
108+
109+
[language]
110+
lang = "english" # select your desired language
108111
```
109112
110113
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:
@@ -127,6 +130,18 @@ This will display the stats of the last 10 games and looks something like this:
127130
![Stats](./docs/assets/snapshot_2025-02-24_00-28-16.png)
128131
To close this view press `Ctrl + c` or `esc`.
129132
133+
## Language
134+
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
135+
`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:
136+
```txt
137+
word1
138+
word2
139+
...
140+
```
141+
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.
142+
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.
143+
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.
144+
130145
## Uninstall
131146
```bash
132147
curl -sSL https://raw.githubusercontent.com/Pazl27/typy-cli/master/scripts/uninstall.sh | bash
File renamed without changes.

scripts/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Define paths
44
BIN_NAME="typy"
55
LOCAL_DIR="$HOME/.local/share"
6-
CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/words.txt"
6+
CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/english.txt"
77
INSTALL_DIR="$HOME/your-repo"
88
GIT_TAG="v0.7.0"
99

@@ -36,6 +36,6 @@ move_binary
3636

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

4141
echo "Installation complete! You can now run the CLI tool by typing '$BIN_NAME' in your terminal."

scripts/uninstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
BIN_NAME="typy"
55
LOCAL_DIR="$HOME/.local/share"
66
BIN_PATH="/usr/bin/$BIN_NAME"
7-
CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/words.txt"
7+
CONFIG_PATH="$LOCAL_DIR/$BIN_NAME/english.txt"
88
CONFIG_DIR="$LOCAL_DIR/$BIN_NAME"
99

1010
# Function to remove the binary with appropriate privileges

src/config/config_tables/language.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::config::toml_parser::get_config;
2+
3+
pub struct Language {
4+
pub lang: String,
5+
}
6+
7+
impl Language {
8+
pub fn new() -> Self {
9+
let theme_colors: Language = match get_config().lock().unwrap().get_language() {
10+
Some(language) => {
11+
let lang = language.lang.unwrap_or("english".to_string());
12+
13+
Language { lang }
14+
}
15+
None => Language::default(),
16+
};
17+
theme_colors
18+
}
19+
}
20+
21+
impl Default for Language {
22+
fn default() -> Self {
23+
Language {
24+
lang: "english".to_string(),
25+
}
26+
}
27+
}

src/config/config_tables/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub mod cursor_style;
22
pub mod graph_colors;
33
pub mod mode_settings;
44
pub mod theme;
5+
pub mod language;

src/config/toml_parser.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ pub struct ModesTable {
3737
pub punctuation_chance: Option<String>,
3838
}
3939

40+
#[derive(Serialize, Deserialize)]
41+
#[derive(Clone)]
42+
pub struct LanguageTable {
43+
pub lang: Option<String>
44+
}
45+
4046
#[derive(Serialize, Deserialize)]
4147
pub struct ConfigToml {
4248
theme: Option<ThemeTable>,
4349
graph: Option<GraphTable>,
4450
cursor: Option<CursorTable>,
4551
modes: Option<ModesTable>,
52+
language: Option<LanguageTable>,
4653
}
4754

4855
impl ConfigToml {
@@ -83,6 +90,10 @@ impl ConfigToml {
8390
pub fn get_modes(&self) -> Option<ModesTable> {
8491
self.modes.clone()
8592
}
93+
94+
pub fn get_language(&self) -> Option<LanguageTable> {
95+
self.language.clone()
96+
}
8697
}
8798

8899
impl Default for ConfigToml {
@@ -92,6 +103,7 @@ impl Default for ConfigToml {
92103
graph: None,
93104
cursor: None,
94105
modes: None,
106+
language: None,
95107
}
96108
}
97109
}

src/terminal/game.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::keyboard::{handle_input, InputAction};
12
use anyhow::{Context, Result};
23
use crossterm::cursor::{self, SetCursorStyle};
34
use crossterm::event::poll;
@@ -8,7 +9,6 @@ use crossterm::{
89
terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType},
910
ExecutableCommand,
1011
};
11-
use super::keyboard::{handle_input, InputAction};
1212
use std::io::stdout;
1313
use std::io::Write;
1414
use std::sync::atomic::{AtomicBool, Ordering};
@@ -17,6 +17,7 @@ use std::thread;
1717
use std::time::{Duration, Instant};
1818

1919
use crate::config::cursor_style::CursorKind;
20+
use crate::config::language;
2021
use crate::config::theme::ThemeColors;
2122
use crate::mode::Mode;
2223
use crate::scores::finish_overview;
@@ -65,10 +66,10 @@ impl Game {
6566
pub fn run(mode: Mode, theme: ThemeColors) -> Result<()> {
6667
let mut stdout = stdout();
6768

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

7374
mode.transform(&mut game.list);
7475

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

161162
if !game.quit {
162-
163163
stdout.execute(cursor::Hide)?;
164164
let score = Score::new(
165165
stats.wpm() as u32,
@@ -243,4 +243,3 @@ fn start_timer(
243243

244244
Ok(())
245245
}
246-

0 commit comments

Comments
 (0)