aboutsummaryrefslogtreecommitdiff
path: root/menubar
diff options
context:
space:
mode:
Diffstat (limited to 'menubar')
-rw-r--r--menubar/main.swift9
-rw-r--r--menubar/model.swift19
2 files changed, 23 insertions, 5 deletions
diff --git a/menubar/main.swift b/menubar/main.swift
index 0d367b8..17b9fcc 100644
--- a/menubar/main.swift
+++ b/menubar/main.swift
@@ -388,6 +388,15 @@ if arguments.contains("--selftest") {
if Hotkey.parse("cmd+shift+f12")?.display != "⇧⌘F12" { failures.append("hotkey: parse cmd+shift+f12") }
if Hotkey.parse(Settings().jumpHotkey)?.display != "⌃⌥⌘U" { failures.append("hotkey: default jump is ⌃⌥⌘U") }
if Hotkey.parse(Settings().searchHotkey)?.display != "⌃⌥⇧⌘U" { failures.append("hotkey: default search is ⌃⌥⇧⌘U") }
+ let order: [(String, Status, Int)] = [
+ ("idle old", .idle, 10), ("done new", .done, 90), ("idle unknown", .idle, Int.max),
+ ("working old", .working, 20), ("idle new", .idle, 80), ("done old", .done, 30),
+ ("blocked", .blocked, 99), ("working new", .working, 70),
+ ]
+ let listed = order.map { Row(paneId: $0.0, agent: "pi", name: $0.0, status: $0.1, session: "s", window: "w",
+ since: $0.2, path: "~") }.sorted(by: listedBefore).map(\.name)
+ let expected = ["blocked", "done old", "done new", "working new", "working old", "idle new", "idle old", "idle unknown"]
+ if listed != expected { failures.append("order: waiting oldest first, the rest most recent first: \(listed)") }
failures.forEach { print("FAIL \($0)") }
print(failures.isEmpty ? "selftest ok" : "selftest: \(failures.count) failed")
exit(failures.isEmpty ? 0 : 1)
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