aboutsummaryrefslogtreecommitdiff
path: root/menubar/model.swift
diff options
context:
space:
mode:
Diffstat (limited to 'menubar/model.swift')
-rw-r--r--menubar/model.swift19
1 files changed, 14 insertions, 5 deletions
diff --git a/menubar/model.swift b/menubar/model.swift
index da5ad15..a17b009 100644
--- a/menubar/model.swift
+++ b/menubar/model.swift
@@ -219,7 +219,9 @@ func runDinggerInLoginShell(_ args: [String]) -> (ok: Bool, output: String) {
private let home = NSHomeDirectory()
-/// Every agent pane, in herdr's priority order, oldest waiting first.
+/// Every agent pane: herdr's status priority; within a status, done and
+/// blocked oldest first (the queue), working and idle most recent first
+/// (`@dingger_since`: when the pane entered its status); then by place.
func fetchRows() -> [Row] {
let format = [
"#{pane_id}", "#{@agent}", "#{@agent_state}", "#{@dingger_since}", "#{@agent_name}",
@@ -236,11 +238,18 @@ func fetchRows() -> [Row] {
session: f[5], window: window, since: Int(f[3]) ?? Int.max,
path: f[9].hasPrefix(home) ? "~" + f[9].dropFirst(home.count) : f[9])
}
- return rows.sorted {
- if $0.status.priority != $1.status.priority { return $0.status.priority > $1.status.priority }
- if $0.since != $1.since { return $0.since < $1.since }
- return $0.location < $1.location
+ return rows.sorted(by: listedBefore)
+}
+
+/// The list order (see `fetchRows`).
+func listedBefore(_ a: Row, _ b: Row) -> Bool {
+ if a.status.priority != b.status.priority { return a.status.priority > b.status.priority }
+ if a.since != b.since {
+ // Int.max: never stamped; last either way.
+ if a.since == Int.max || b.since == Int.max { return a.since < b.since }
+ return a.waiting ? a.since < b.since : a.since > b.since
}
+ return a.location < b.location
}
/// Show the pane and mark it attended; the same code path as the tmux