diff options
| author | srdusr <[email protected]> | 2025-08-04 16:40:00 +0200 |
|---|---|---|
| committer | srdusr <[email protected]> | 2025-08-04 16:40:00 +0200 |
| commit | 8c95e90fa54db565919ec323818f77e7256812c8 (patch) | |
| tree | 109c4531e283f00c37713339441caee9a2366d9d /src/main.rs | |
| parent | fe660228f2bcce262a7e18b4ced25736778b1eeb (diff) | |
| download | typerpunk-8c95e90fa54db565919ec323818f77e7256812c8.tar.gz typerpunk-8c95e90fa54db565919ec323818f77e7256812c8.zip | |
Add cursor (currently block only)
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 6a4bcba..9c529f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,6 +122,7 @@ fn draw_typing_game(f: &mut Frame<CrosstermBackend<std::io::Stdout>>, chunk: Rec let time_used = app.time_taken as f64; let mut colored_text: Vec<Span> = Vec::new(); + let cursor_pos = app.input_string.len(); // Iterate over each character in the current sentence and color it based on user input for (index, c) in app.current_sentence().chars().enumerate() { @@ -135,17 +136,24 @@ fn draw_typing_game(f: &mut Frame<CrosstermBackend<std::io::Stdout>>, chunk: Rec Color::Gray }; - let span = Span::styled(c.to_string(), Style::default().fg(color)); + // cursor + let span = if index == cursor_pos { + Span::styled( + c.to_string(), + Style::default().fg(color).add_modifier(Modifier::REVERSED), + ) + } else { + Span::styled(c.to_string(), Style::default().fg(color)) + }; colored_text.push(span); } - // Create text to be displayed let text = vec![ Spans::from(Span::styled( "Type the following sentence:", Style::default().add_modifier(Modifier::BOLD), )), - colored_text.into(), + Spans::from(colored_text), Spans::from(Span::styled(format!("WPM: {:.2}", wpm), Style::default())), Spans::from(Span::styled( format!("Time: {:.1} seconds", time_used), |