pub struct GitStatsState { /* private fields */ }markdown-preview only.Expand description
Git stats state for markdown source files.
Tracks additions, modifications, and deletions from git diff.
Implementations§
Source§impl GitStatsState
Constructor for GitStatsState.
impl GitStatsState
Constructor for GitStatsState.
Sourcepub fn new() -> GitStatsState
pub fn new() -> GitStatsState
Create a new git stats state with defaults.
Source§impl GitStatsState
Git stats getter method for GitStatsState.
impl GitStatsState
Git stats getter method for GitStatsState.
Source§impl GitStatsState
Set show git stats method for GitStatsState.
impl GitStatsState
Set show git stats method for GitStatsState.
Source§impl GitStatsState
impl GitStatsState
Sourcepub fn update(&mut self, source_path: Option<&Path>) -> bool
pub fn update(&mut self, source_path: Option<&Path>) -> bool
Update git stats if show is enabled and enough time has passed.
This method should be called periodically (e.g., in the render loop). It only computes stats every 2 seconds to avoid excessive git calls.
§Arguments
source_path- The path to the source file, if any.
§Returns
true if stats were updated, false otherwise.
Source§impl GitStatsState
impl GitStatsState
Sourcepub fn update_if_changed(
&mut self,
source_path: Option<&Path>,
watcher: &mut GitWatcher,
) -> bool
pub fn update_if_changed( &mut self, source_path: Option<&Path>, watcher: &mut GitWatcher, ) -> bool
Update git stats using a GitWatcher for change detection.
This method only computes git stats when the watcher detects that the git repository state has changed, making it more efficient than time-based polling.
§Arguments
source_path- The path to the source file, if any.watcher- A mutable reference to the GitWatcher.
§Returns
true if stats were updated, false otherwise.
§Example
use ratatui_toolkit::markdown_widget::state::git_stats::GitStatsState;
use ratatui_toolkit::services::git_watcher::GitWatcher;
use std::path::Path;
let mut git_stats = GitStatsState::new();
git_stats.set_show(true);
let mut watcher = GitWatcher::new().unwrap();
watcher.watch(Path::new(".")).unwrap();
// In your event loop:
if git_stats.update_if_changed(Some(Path::new("README.md")), &mut watcher) {
println!("Git stats updated!");
}Sourcepub fn force_update(&mut self, source_path: Option<&Path>)
pub fn force_update(&mut self, source_path: Option<&Path>)
Force update git stats immediately.
This bypasses both time-based and watcher-based checks and immediately computes git stats.
§Arguments
source_path- The path to the source file, if any.
Trait Implementations§
Source§impl Clone for GitStatsState
impl Clone for GitStatsState
Source§fn clone(&self) -> GitStatsState
fn clone(&self) -> GitStatsState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GitStatsState
impl Debug for GitStatsState
Source§impl Default for GitStatsState
Default trait implementation for GitStatsState.
impl Default for GitStatsState
Default trait implementation for GitStatsState.
Source§fn default() -> GitStatsState
fn default() -> GitStatsState
Auto Trait Implementations§
impl Freeze for GitStatsState
impl RefUnwindSafe for GitStatsState
impl Send for GitStatsState
impl Sync for GitStatsState
impl Unpin for GitStatsState
impl UnsafeUnpin for GitStatsState
impl UnwindSafe for GitStatsState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more