Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5d23555
dash: kill and setsid in one module; config keys max_jobs, notify, model
catalan-adobe Dec 1, 2026
87560af
dash: jobs and their files: states from the exit file, the queue, toa…
catalan-adobe Dec 1, 2026
a9b0e05
dash: r and p run jobs: the loop check, a confirm dialog, the queue, …
catalan-adobe Dec 1, 2026
95bc30c
dash: the Jobs view, the log, dialogs and toasts on screen; job count…
catalan-adobe Dec 1, 2026
a062dc8
dash/README: jobs, their keys and files, dash.max_jobs, dash.notify, …
catalan-adobe Dec 1, 2026
450dea8
dash: a round's toast names the round its job posted: the one posted …
catalan-adobe Dec 1, 2026
d6f2331
dash: the dialog names the account a round posts as, on the PR's host…
catalan-adobe Dec 1, 2026
2c75d7f
dash: a jobs worker owns the jobs folder and the jobs' processes; the…
catalan-adobe Dec 1, 2026
c72fa10
dash: no signal to a job's group unless its leader is still the job's…
catalan-adobe Dec 1, 2026
6d7b334
dash: a job's command runs only once its record is saved: the wrapper…
catalan-adobe Dec 1, 2026
db78394
dash: a quit finishes the stops under way; a stop found at start goes on
catalan-adobe Dec 1, 2026
0c700d1
dash: dashboards that share a jobs folder share dash.max_jobs and the…
catalan-adobe Dec 1, 2026
cd9826c
dash: K asks before it takes a job off the queue, and never stops one…
catalan-adobe Dec 1, 2026
c575a75
dash: toasts wait their turn, and a job's end is marked shown when it…
catalan-adobe Dec 1, 2026
b5d38b0
dash: long log lines wrap; the log scrolls by screen rows
catalan-adobe Dec 1, 2026
53d55b0
dash: a dialog's buttons always show; Start waits until the whole tex…
catalan-adobe Dec 1, 2026
2be7841
dash: c names the jobs it could not clear, and deletes a job's record…
catalan-adobe Dec 1, 2026
915aaf1
dash/README: the confirm and what r posts, the account, the jobs work…
catalan-adobe Dec 1, 2026
1253d10
Merge remote-tracking branch 'origin/main' into dash-d2a-jobs
catalan-adobe Dec 1, 2026
af53662
Merge remote-tracking branch 'origin/main' into dash-d2a-jobs
catalan-adobe Dec 1, 2026
249cc2c
Dashboard: K stops only the jobs this dashboard process started
catalan-adobe Dec 1, 2026
6232d44
Dashboard: no round under a login -u can't name
catalan-adobe Dec 1, 2026
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
147 changes: 136 additions & 11 deletions dash/README.md

Large diffs are not rendered by default.

138 changes: 130 additions & 8 deletions dash/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
//! Application state: the data, the list rows, the selection, focus, tabs and modes.
//!
//! The state is pure: key handling returns nothing and pushes `Effect`s (refresh, load a PR's
//! detail) that the event loop runs in worker threads. Tests drive it without a terminal.
//! detail, a loop check) that the event loop runs in worker threads. Tests drive it without a terminal.
//! Jobs (`jobs_app.rs`) go to the jobs worker (`jobs_worker.rs`), which owns their files and processes.

use crate::config::Config;
use crate::jobs::JobKind;
use crate::jobs::{CheckAnswer, JobList};
use crate::jobs_app::{Dialog, DialogView, JobsCtx, LogView, ToastMsg};
use crate::keys::{Action, Focus, KeyChord, Keymap, Lookup};
use crate::model::{Group, Pr, Show, Status, parse_time};
use crate::theme::Theme;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use nucleo_matcher::pattern::{CaseMatching, Normalization, Pattern};
use nucleo_matcher::{Matcher, Utf32Str};
use std::collections::HashMap;
use std::collections::{HashMap, VecDeque};
use std::rc::Rc;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -72,6 +76,14 @@ pub enum Mode {
Help,
}

/// What fills the body: the list and the detail, the Jobs view, or a job's log.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum View {
Dashboard,
Jobs,
Log,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ListRow {
Header(Group, usize),
Expand Down Expand Up @@ -132,6 +144,17 @@ pub enum Effect {
Refresh,
/// `show <PR> --json`, as the account that listed the PR.
LoadShow(ShowRequest),
/// `<PR> --check --json`, before a job.
Check(CheckRequest),
}

/// A loop check for the dialog `id`: the PR and the account that listed it.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CheckRequest {
pub id: u64,
pub key: String,
pub url: String,
pub account: Option<String>,
}

/// What a `show` call is for: the PR, its URL, and the account that listed it (`-u`: status reads every account, and a
Expand All @@ -158,6 +181,13 @@ pub enum WorkerMsg {
key: String,
result: Result<Show, String>,
},
/// The answer to the loop check `id` (boxed: the decision is large, and events move often).
Check {
id: u64,
result: Box<Result<CheckAnswer, String>>,
},
/// The jobs worker.
Jobs(crate::jobs_worker::JobsMsg),
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -218,6 +248,39 @@ pub struct App {
pub size: (u16, u16),
pub should_quit: bool,
pub effects: Vec<Effect>,
pub view: View,
/// A dialog over everything: it takes the keys.
pub dialog: Option<Dialog>,
/// How much of the dialog's text shows, and whether all of it has.
pub dialog_view: DialogView,
pub jobs: JobList,
/// The selected row of the Jobs view.
pub jobs_selected: usize,
pub log: Option<LogView>,
/// Job ends on screen, newest last.
pub toasts: Vec<ToastMsg>,
/// Toasts waiting for room on screen, first in first out.
pub toast_queue: VecDeque<ToastMsg>,
/// Jobs sent to the worker whose admission is not answered yet: (job ID, PR key, kind).
pub(crate) admitting: Vec<(String, String, JobKind)>,
/// The queued job being taken off the queue, and its PR's number.
pub(crate) unqueued_pr: Option<(String, String)>,
/// The job whose log closed because it went from the list.
pub(crate) closed_log: Option<String>,
/// What `dash.notify` writes to the terminal on a job's end (a bell, an OSC 9): the event loop writes it.
pub alerts: Vec<String>,
/// The jobs folder and the CLI; `None`: no jobs (fixtures).
pub(crate) jobs_ctx: Option<JobsCtx>,
pub(crate) next_check_id: u64,
/// Counts the `status --json` runs started and answered, so that a job's toast waits for one started after its end.
pub(crate) refresh_epoch: u64,
pub(crate) refresh_done: u64,
/// Unix seconds: when the last `status --json` started.
pub(crate) refresh_started_at: i64,
/// A job ended while a refresh ran: one more after it.
pub(crate) refresh_again: bool,
/// Jobs whose toast waits for the status of this refresh epoch: (job ID, epoch).
pub(crate) awaiting: Vec<(String, u64)>,
selected_at: Option<Instant>,
next_refresh: Option<Instant>,
matcher: Matcher,
Expand Down Expand Up @@ -256,6 +319,25 @@ impl App {
size: (160, 45),
should_quit: false,
effects: Vec::new(),
view: View::Dashboard,
dialog: None,
dialog_view: DialogView::default(),
jobs: JobList::default(),
jobs_selected: 0,
log: None,
toasts: Vec::new(),
toast_queue: VecDeque::new(),
admitting: Vec::new(),
unqueued_pr: None,
closed_log: None,
alerts: Vec::new(),
jobs_ctx: None,
next_check_id: 1,
refresh_epoch: 0,
refresh_done: 0,
refresh_started_at: 0,
refresh_again: false,
awaiting: Vec::new(),
selected_at: None,
next_refresh: None,
matcher: Matcher::new(nucleo_matcher::Config::DEFAULT),
Expand All @@ -265,6 +347,8 @@ impl App {
/// Asks for the first paint (cache) and the first refresh.
pub fn start(&mut self) {
self.refreshing = true;
self.refresh_epoch += 1;
self.refresh_started_at = crate::jobs_app::unix_now();
self.effects.push(Effect::LoadInitial);
}

Expand Down Expand Up @@ -326,6 +410,8 @@ impl App {
WorkerMsg::Status { cached: false, result } => {
self.refreshing = false;
self.schedule_refresh();
self.refresh_done = self.refresh_epoch;
let ok = result.is_ok();
match result {
Ok(status) => {
self.status_error = None;
Expand All @@ -336,7 +422,10 @@ impl App {
}
Err(e) => self.status_error = Some(e),
}
self.status_answered(ok);
}
WorkerMsg::Check { id, result } => self.check_answered(id, *result),
WorkerMsg::Jobs(msg) => self.jobs_msg(msg),
WorkerMsg::Show { id, key, result } => {
// Only the answer to the current request counts: not a late one to an earlier request. An answer to a
// request made before the last refresh is taken for that list: it is read again.
Expand All @@ -359,15 +448,23 @@ impl App {
self.info("Already refreshing");
return;
}
self.start_refresh();
}

pub(crate) fn start_refresh(&mut self) {
self.refreshing = true;
self.refresh_epoch += 1;
self.refresh_started_at = crate::jobs_app::unix_now();
self.effects.push(Effect::Refresh);
}

/// Runs time-based work: message expiry, the periodic refresh, loading the selected detail.
/// Runs time-based work: message and toast expiry, the periodic refresh, loading the selected detail, the jobs.
pub fn tick(&mut self, now: Instant) {
if self.message.as_ref().and_then(|m| m.until).is_some_and(|u| now >= u) {
self.message = None;
}
self.toasts.retain(|t| now < t.until);
self.present_toasts(now);
if !self.refreshing && self.next_refresh.is_some_and(|t| now >= t) {
self.refresh();
}
Expand Down Expand Up @@ -573,15 +670,25 @@ impl App {

// ── keys ────────────────────────────────────────────────────────────────

/// The focus keys are looked up for: the Jobs view and the log have theirs.
pub fn key_focus(&self) -> Focus {
if self.view == View::Dashboard { self.focus } else { Focus::Jobs }
}

pub fn handle_key(&mut self, ev: KeyEvent) {
if self.dialog.is_some() {
self.dialog_key(ev);
return;
}
match self.mode {
Mode::Filter => self.filter_key(ev),
Mode::Palette => self.palette_key(ev),
Mode::Help => self.help_key(ev),
Mode::Normal => {
let chord = KeyChord::from_event(&ev);
self.pending.push(chord);
match self.keymap.lookup(&self.pending, self.focus) {
let focus = self.key_focus();
match self.keymap.lookup(&self.pending, focus) {
Lookup::Action(a) => {
self.pending.clear();
self.dispatch(a);
Expand All @@ -590,7 +697,7 @@ impl App {
Lookup::None => {
// A dead prefix: try the last key alone (`g` then `j` is `j`).
self.pending.clear();
if let Lookup::Action(a) = self.keymap.lookup(&[chord], self.focus) {
if let Lookup::Action(a) = self.keymap.lookup(&[chord], focus) {
self.dispatch(a);
}
}
Expand All @@ -601,6 +708,9 @@ impl App {

pub fn dispatch(&mut self, action: Action) {
use Action::*;
if self.view != View::Dashboard && self.dispatch_jobs_view(action) {
return;
}
let in_detail = self.focus == Focus::Detail && self.detail_visible();
match action {
MoveDown if in_detail => self.detail_move(1),
Expand Down Expand Up @@ -638,7 +748,19 @@ impl App {
self.help_scroll = 0;
}
Refresh => self.refresh(),
Quit => self.should_quit = true,
Quit => self.quit(),
RunRound => self.start_job_dialog(crate::jobs::JobKind::Round),
Preview => self.start_job_dialog(crate::jobs::JobKind::Preview),
Jobs => self.open_jobs_view(),
StopJob => {
let job = self.selected_pr().and_then(|p| self.jobs.active_for(&p.key)).map(|j| j.id().to_string());
match job {
Some(id) => self.ask_stop(&id),
None => self.info("No job for this PR"),
}
}
ClearJobs => self.clear_finished(),
FollowLog => self.info("Follow is for a job's log: J, then enter"),
other => {
let phase = other.phase().unwrap_or("a later version");
self.info(format!("{} comes in phase {phase}", other.title()));
Expand Down Expand Up @@ -1018,8 +1140,8 @@ mod tests {
app.handle_key(code(KeyCode::Esc));
assert_eq!(app.mode, Mode::Normal);
// Later-phase actions are not in the palette.
app.palette_query = "run round".into();
assert!(!app.palette_items().contains(&Action::RunRound));
app.palette_query = "agent".into();
assert!(!app.palette_items().contains(&Action::AskAgent));
}

#[test]
Expand Down
Loading