Skip to content

Commit dded1a1

Browse files
RobbyV2RobbyV2
authored andcommitted
0.1.8
1 parent 5c87e8a commit dded1a1

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ git clone https://github.com/RobbyV2/tuitype.git
1515
cd tuitype
1616
```
1717

18-
1. Run the application:
18+
2. Run the application:
1919

2020
```bash
2121
cargo run

src/config/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,31 @@ pub struct ThemeConfig {
4747
pub cursor: (u8, u8, u8),
4848
}
4949

50+
/// Configuration for the TuiType application
5051
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
5152
pub struct Config {
53+
/// The current test mode (timed, words, quote, or custom)
5254
pub test_mode: TestMode,
5355

56+
/// The difficulty level for text generation
5457
pub difficulty: Difficulty,
5558

59+
/// Custom text to use for typing tests
5660
pub custom_text: Option<String>,
5761

62+
/// The visual theme to use
5863
pub theme_type: ThemeType,
5964

65+
/// The font style to use for display
6066
pub font_style: FontStyle,
6167

68+
/// Whether to repeat the same test after completion
6269
pub repeat_test: bool,
6370

71+
/// The text from the last completed test
6472
pub last_test_text: Option<String>,
6573

74+
/// Whether to end the test on the first error
6675
pub end_on_first_error: bool,
6776
}
6877

@@ -82,6 +91,7 @@ impl Default for Config {
8291
}
8392

8493
impl Config {
94+
/// Get the configuration directory path, creating it if it doesn't exist
8595
fn get_config_dir() -> Result<PathBuf> {
8696
let mut dir = dirs::config_dir().unwrap_or_else(|| PathBuf::from("."));
8797
dir.push("tuitype");
@@ -91,19 +101,22 @@ impl Config {
91101
Ok(dir)
92102
}
93103

104+
/// Get the full path to the configuration file
94105
fn get_config_path() -> Result<PathBuf> {
95106
let mut path = Self::get_config_dir()?;
96107
path.push("config.json");
97108
Ok(path)
98109
}
99110

111+
/// Save the current configuration to disk
100112
pub fn save(&self) -> Result<()> {
101113
let path = Self::get_config_path()?;
102114
let serialized = serde_json::to_string_pretty(self)?;
103115
fs::write(path, serialized)?;
104116
Ok(())
105117
}
106118

119+
/// Load configuration from disk, creating a default config if none exists
107120
pub fn load() -> Result<Self> {
108121
let path = Self::get_config_path()?;
109122
if path.exists() {

src/input/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ impl InputHandler {
9595
match event::read()? {
9696
CrosstermEvent::Key(key) => {
9797
let state = self.key_states.entry(key.code).or_default();
98-
let should_process = state.should_process_key(now, key.kind);
99-
100-
if should_process {
98+
if state.should_process_key(now, key.kind) {
10199
return Ok(Some(Event::Key(key)));
102100
}
103101
Ok(None)

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ fn main() -> Result<()> {
2323
let backend = CrosstermBackend::new(stdout);
2424
let mut terminal = Terminal::new(backend)?;
2525

26-
let config = Config::load().unwrap_or_default();
26+
let config = Config::load().unwrap_or_else(|err| {
27+
eprintln!("Warning: Failed to load config: {err}. Using default configuration.");
28+
Config::default()
29+
});
2730

2831
let app = App::new(config);
2932
let mut input_handler = InputHandler::new(Duration::from_millis(33));

src/version.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/// The current version of TuiType
12
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

0 commit comments

Comments
 (0)