Skip to content

Commit 4007761

Browse files
committed
docs: add docstrings to improve coverage
Add documentation comments to public functions and structs in animation.rs, main.rs, and ui.rs to meet the 80% docstring coverage threshold.
1 parent d8ba787 commit 4007761

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/animation.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub struct EditorBuffer {
8181
}
8282

8383
impl EditorBuffer {
84+
/// Creates a new empty editor buffer with default values.
8485
pub fn new() -> Self {
8586
Self {
8687
lines: vec![String::new()],
@@ -97,6 +98,7 @@ impl EditorBuffer {
9798
}
9899
}
99100

101+
/// Creates an editor buffer initialized with the given content.
100102
pub fn from_content(content: &str) -> Self {
101103
let lines: Vec<String> = if content.is_empty() {
102104
vec![String::new()]
@@ -119,6 +121,7 @@ impl EditorBuffer {
119121
}
120122
}
121123

124+
/// Inserts a character at the specified line and column position.
122125
pub fn insert_char(&mut self, line: usize, col: usize, ch: char) {
123126
if line >= self.lines.len() {
124127
self.lines.resize(line + 1, String::new());
@@ -135,13 +138,15 @@ impl EditorBuffer {
135138
line_str.insert(byte_idx, ch);
136139
}
137140

141+
/// Inserts a new line with the given content at the specified position.
138142
pub fn insert_line(&mut self, line: usize, content: String) {
139143
if line > self.lines.len() {
140144
self.lines.resize(line, String::new());
141145
}
142146
self.lines.insert(line, content);
143147
}
144148

149+
/// Deletes the line at the specified position.
145150
pub fn delete_line(&mut self, line: usize) {
146151
if line < self.lines.len() {
147152
self.lines.remove(line);
@@ -251,6 +256,7 @@ pub struct AnimationEngine {
251256
}
252257

253258
impl AnimationEngine {
259+
/// Creates a new animation engine with the specified typing speed.
254260
pub fn new(speed_ms: u64) -> Self {
255261
let target_fps: u64 = 120;
256262
let frame_interval_ms = 1000 / target_fps;
@@ -302,10 +308,12 @@ impl AnimationEngine {
302308
self.base_speed_ms
303309
}
304310

311+
/// Sets the viewport height for scroll calculations.
305312
pub fn set_viewport_height(&mut self, height: usize) {
306313
self.viewport_height = height;
307314
}
308315

316+
/// Sets the content width for line wrapping calculations.
309317
pub fn set_content_width(&mut self, width: usize) {
310318
self.content_width = width;
311319
}
@@ -802,7 +810,7 @@ impl AnimationEngine {
802810
(cursor_line, buffer_line)
803811
}
804812

805-
/// Update animation state and return true if display needs refresh
813+
/// Updates animation state and returns true if display needs refresh.
806814
pub fn tick(&mut self) -> bool {
807815
self.update_cursor_blink();
808816

@@ -1101,6 +1109,7 @@ impl AnimationEngine {
11011109
self.buffer.scroll_offset = logical_offset;
11021110
}
11031111

1112+
/// Returns true if the animation has completed.
11041113
pub fn is_finished(&self) -> bool {
11051114
self.state == AnimationState::Finished
11061115
}

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::path::{Path, PathBuf};
1616
use theme::Theme;
1717
use ui::UI;
1818

19+
/// Defines the order in which commits are played back during animation.
1920
#[derive(Debug, Clone, Copy, Default, ValueEnum)]
2021
pub enum PlaybackOrder {
2122
#[default]
@@ -169,6 +170,7 @@ pub enum ThemeCommands {
169170
}
170171

171172
impl Args {
173+
/// Validates the command-line arguments and returns the Git repository path.
172174
pub fn validate(&self) -> Result<PathBuf> {
173175
let start_path = self.path.clone().unwrap_or_else(|| PathBuf::from("."));
174176

src/ui.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum UIState {
3232
Finished,
3333
}
3434

35+
/// Main UI controller for the gitlogue terminal interface.
3536
pub struct UI<'a> {
3637
state: UIState,
3738
speed_ms: u64,
@@ -50,6 +51,7 @@ pub struct UI<'a> {
5051
}
5152

5253
impl<'a> UI<'a> {
54+
/// Creates a new UI instance with the specified configuration.
5355
pub fn new(
5456
speed_ms: u64,
5557
repo: Option<&'a GitRepository>,
@@ -101,11 +103,13 @@ impl<'a> UI<'a> {
101103
.expect("Error setting Ctrl-C handler");
102104
}
103105

106+
/// Loads a commit and starts the animation.
104107
pub fn load_commit(&mut self, metadata: CommitMetadata) {
105108
self.engine.load_commit(&metadata);
106109
self.state = UIState::Playing;
107110
}
108111

112+
/// Runs the main UI event loop.
109113
pub fn run(&mut self) -> Result<()> {
110114
enable_raw_mode()?;
111115
let mut stdout = io::stdout();

0 commit comments

Comments
 (0)