Gladius - High-Performance Typing Trainer Library
Gladius is a comprehensive Rust library for building typing trainer applications. It provides real-time typing analysis, flexible rendering systems, and detailed performance statistics with a focus on accuracy, performance, and ease of use.
๐ Quick Start
use TypingSession;
// Create a typing session
let mut session = new.unwrap;
// Process user input
while let Some = session.input
// Get progress and statistics
println!;
println!;
๐ก Key Features
๐โโ๏ธ High Performance
- Fast character processing - Amortized O(1) keystroke handling
- O(1) word lookups - Efficient character-to-word mapping
- Optimized statistics - Welford's algorithm for numerical stability
- Memory efficient - Minimal allocations during typing
๐ Comprehensive Statistics
- Words per minute (raw, corrected, actual)
- Input per minute (raw, actual)
- Accuracy percentages (raw, actual)
- Consistency analysis with standard deviation
- Detailed error tracking by character and word
- Real-time measurements at configurable intervals
๐ฏ Flexible Rendering
- Character-level rendering with typing state information
- Line-based rendering with intelligent word wrapping
- Cursor position tracking across line boundaries
- Unicode support for international characters and emojis
- Generic renderer interface for any UI framework
โ๏ธ Configurable Behavior
- Measurement intervals for statistics collection
- Line wrapping options (word boundaries vs. character wrapping)
- Newline handling (respect or ignore paragraph breaks)
- Performance tuning for different use cases
๐ Relationship to OctoType
Gladius serves as the core engine for OctoType, a TUI typing trainer. While OctoType provides the user interface, configuration system, and TUI experience, Gladius handles all the fundamental typing logic:
- Text processing and character management
- Real-time typing statistics calculation
- Input validation and error tracking
- Rendering pipeline for display
- Performance metrics and analysis
This separation allows:
- Reusability: Other applications can use Gladius as a typing engine
- Testing: Core typing logic can be thoroughly tested independently
- Maintainability: Clear separation of concerns between UI and logic
- Performance: Optimized core without UI overhead
๐ฆ Installation
Add Gladius to your Cargo.toml:
[]
= "0.3.2"
๐ Documentation
Complete API documentation is available at docs.rs/gladius.
๐งช Examples
Basic Typing Session
use ;
let mut session = new.unwrap;
// Process typing input
match session.input
Custom Configuration
use ;
let config = Configuration ;
let session = new
.unwrap
.with_configuration;
Character-level Rendering
use TypingSession;
let session = new.unwrap;
let rendered: = session.render;
โก Performance Characteristics
| Operation | Time Complexity | Notes |
|---|---|---|
| Character input | O(1) amortized, O(w) worst case | Usually constant, worst case when recalculating word state |
| Character lookup | O(1) | Direct vector indexing |
| Word lookup | O(1) | Pre-computed mapping |
| Statistics update | O(1) typical, O(m) when measuring | Most updates are constant, measurements scan history |
| Rendering | O(n) | Linear in text length |
๐ก๏ธ Thread Safety
Gladius types are not thread-safe by design for maximum performance. Each typing session should be used on a single thread. Multiple sessions can run concurrently on different threads.
๐ง Minimum Supported Rust Version (MSRV)
Gladius supports Rust 1.88.0 and later.
๐ค Contributing
If you have an idea, bug-report or alike, feel free to open an issue or PR - It's more than welcome!
๐ License
Licensed under the MIT License. See LICENSE for details.
Why "Gladius"?
Gladius is the Latin word for a small sword, but in biology, it's the name for the internal, feather-shaped shell of a squid.
Since gladius is the core library of OctoType, this name felt very fitting.