Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ impl<'a> ListState<'a> {
git_config_set(&cred_key, &account.username, scope);

let mut status_lines = Vec::new();
let mut has_status_issue = false;

if let Some(token) = crate::models::get_token(&account.username, account.alias.as_deref())
.filter(|t| !t.is_empty())
Expand All @@ -453,13 +454,15 @@ impl<'a> ListState<'a> {
}

if let Some(warning) = crate::utils::check_credential_helper() {
has_status_issue = true;
status_lines.push(warning);
}

// Clear any potentially conflicting credentials
git_credential_reject(host);
git_credential_approve(&account.username, &token, host, url.as_deref());
} else {
has_status_issue = true;
status_lines.push(format!(
" {} No token found for {}. Git may prompt for authentication.",
"⚠".yellow(),
Expand All @@ -475,10 +478,7 @@ impl<'a> ListState<'a> {
scope.green()
));

raw_show_status(
&status_lines,
if status_lines.len() > 3 { 2500 } else { 1500 },
);
raw_show_status(&status_lines, has_status_issue);
true
}

Expand Down
36 changes: 34 additions & 2 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ use crossterm::{
terminal::{self, ClearType},
};
use std::io::{Write, stdout};
use std::time::{Duration, Instant};

fn status_display_duration_ms(line_count: usize, has_issue: bool) -> u64 {
if has_issue {
5000
} else if line_count > 3 {
2500
} else {
1500
}
}

/// Enter raw mode and hide cursor.
pub fn enter_raw_mode() {
Expand Down Expand Up @@ -316,7 +327,7 @@ pub fn raw_password(prompt: &str) -> Option<String> {
}

/// Show status message lines, sleep, then clear them.
pub fn raw_show_status(lines: &[String], duration_ms: u64) {
pub fn raw_show_status(lines: &[String], has_issue: bool) {
let mut stdout = stdout();

for line in lines {
Expand All @@ -329,6 +340,27 @@ pub fn raw_show_status(lines: &[String], duration_ms: u64) {
}
stdout.flush().ok();

std::thread::sleep(std::time::Duration::from_millis(duration_ms));
let duration = Duration::from_millis(status_display_duration_ms(lines.len(), has_issue));
let start = Instant::now();

while start.elapsed() < duration {
let remaining = duration.saturating_sub(start.elapsed());
let poll_timeout = remaining.min(Duration::from_millis(100));

let Ok(has_event) = event::poll(poll_timeout) else {
continue;
};
if !has_event {
continue;
}

let Ok(Event::Key(key)) = event::read() else {
continue;
};
if key.kind == KeyEventKind::Press && key.code == KeyCode::Enter {
break;
}
}

raw_clear_lines(&mut stdout, lines.len());
}
Loading