Files
chandra/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt
T
Claude 8ecdef17d4
CI / test (push) Failing after 17s
Settings > Panel: a cleaner module selector with reordering
The Panel tab was one flat list: every panel module with an "x" that removed
it on any click, then every module on disk again with cryptic "x1" counts and
a Browse row that looked selected.

- "In the panel, left to right": the modules in panel order, each with
  move up / move down / remove buttons. Clicking the row itself does nothing,
  so a stray click no longer removes a module. Backspace/Delete removes the
  highlighted one, PageUp/PageDown move it.
- "Add to the panel": grouped (Apps and windows, System, Clocks, Other),
  each with a one-line description and an Add button. A module already in the
  panel is left out, except clocks, which offer "Add another". With nothing
  left: "Everything is in the panel".
- "Browse for a module file..." is a secondary outlined button.
- Section headings are larger and full contrast; the popup is 320 wide and
  now fits a 720-high screen with the default panel.

Reordering goes through a new modules.move-instance(slot, delta) capability
call, plumbed through both hosts: wasmer stub request 17, host-wasm, the
plasmoids host WIT (move-instance(instance-move)) and wasmhost. The shell's
move_slot clamps to the ends and saves panel.edn, so the saved format is
unchanged. DesktopShell::slot_popup_texts lets tests find popup rows by text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhRDWZf5WcmrNwnFe3
2026-11-25 20:35:54 +00:00

727 lines
23 KiB
MoonBit

///| Implementation of `chandra:desktop/plasmoid` for the settings module: the panel's "Settings"
/// button. Its popup has three tabs, split by where things live:
///
/// - Session: the session settings the shell offers (`session-settings.settings`: reopen windows
/// at login, remember window positions, dark mode), each with an on/off switch;
/// - Desktop: what is drawn on the desktop. Today that is the wallpaper (`wallpaper.wallpapers`,
/// the current one ticked); modules can't be placed on the desktop yet, so when they can they
/// get their own section here;
/// - Panel: the modules in the panel in panel order (left to right), each with move-up/down and
/// remove buttons; then the modules that can be added, grouped by kind with a short description
/// and an Add button (a module already in the panel is left out unless more than one makes
/// sense, like a clock); and a "Browse for a module file..." button (`modules`). The panel
/// menu's "Modules..." opens this tab;
/// - Power: the battery (`system`, when there is one), how long without input before the screen
/// turns off and before the computer suspends (a click steps through the choices), and Suspend,
/// Restart and Power off now (`power`); Restart and Power off ask for a second click.
///
/// Clicking a row acts at once and the popup stays open; a row in the panel list only acts through
/// its buttons, so a stray click doesn't remove anything. Up/Down move the highlight, Left/Right
/// (or 1-4) switch tabs, Enter or Space acts on the highlighted row, Backspace or Delete removes
/// the highlighted panel module and PageUp/PageDown move it, Escape or a click elsewhere closes. The shell remembers settings and wallpaper in state.edn, the panel in
/// panel.edn.
///| Popup geometry: the tab bar, then a column of rows, with a margin around them.
let popup_w : Int = 320
///|
let margin : Int = 6
///|
let tab_h : Int = 30
///| Top of the first row (below the tab bar). Rows are `row_h` tall except on the Panel tab (see
/// `row_height`).
let rows_top : Int = 40
///|
let row_h : Int = 28
///| The switch at the right end of a setting row.
let switch_w : Int = 34
///|
let switch_h : Int = 18
///|
let tab_names : Array[String] = ["Session", "Desktop", "Panel", "Power"]
///| A popup row.
enum Row {
Heading(String)
Setting(Int, String)
Wallpaper(Int, String)
/// A group of modules in the Add list ("Clocks").
Category(String)
/// A loaded panel instance: slot, name, its place in the panel and how many there are.
Loaded(String, String, Int, Int)
/// A module that can be added: path, name, description and how many instances are loaded.
Available(String, String, String, UInt)
/// Every module is in the panel already.
NothingToAdd
Browse
/// A line of text (the battery).
Info(String)
/// A timeout that steps through `choices`: 0 screen off, 1 suspend.
Timeout(Int, String)
/// Suspend (0), power off (1) or restart (2) now.
PowerNow(Int, String)
}
///| The timeout choices, in minutes (0: never).
let screen_off_choices : Array[Int] = [0, 1, 2, 5, 10, 15, 30, 60]
///|
let suspend_choices : Array[Int] = [0, 5, 10, 15, 30, 60, 120]
///| The power action waiting for its confirming second click (-1: none).
let armed : Ref[Int] = { val: -1 }
///| "Never", "5 min", "1 hour", "2 hours".
fn minutes_label(m : Int) -> String {
if m <= 0 {
"Never"
} else if m % 60 == 0 {
let h = m / 60
h.to_string() + (if h == 1 { " hour" } else { " hours" })
} else {
m.to_string() + " min"
}
}
///| The choice after `cur` in `choices` (wrapping round to the first).
fn next_choice(choices : Array[Int], cur : Int) -> Int {
for c in choices {
if c > cur {
return c
}
}
choices[0]
}
///| Whether the popup is open, its tab, and which row is highlighted (-1: none).
let open_ : Ref[Bool] = { val: false }
///|
let tab : Ref[Int] = { val: 0 }
///|
let hover : Ref[Int] = { val: -1 }
///| The groups of the Add list, in order.
let categories : Array[String] = ["Apps and windows", "System", "Clocks", "Other"]
///| Which group a module (by id, its file stem) belongs to; modules we don't know go in "Other".
fn category_of(id : String) -> String {
match id {
"launcher" | "dock" | "tasks" | "layout" => "Apps and windows"
"session-settings" | "network" | "battery" | "screenshot" | "logout" => "System"
"clock-digital" | "clock-binary" | "moon-disc" => "Clocks"
_ => "Other"
}
}
///| One line on what a module does ("" for modules we don't know).
fn description_of(id : String) -> String {
match id {
"launcher" => "Search and start apps"
"dock" => "Pinned apps, one click away"
"tasks" => "Your open windows"
"layout" => "Switch tiling and floating"
"session-settings" => "This settings window"
"network" => "Wi-Fi and wired network"
"battery" => "Charge and time left"
"screenshot" => "Capture or record the screen"
"logout" => "End the session"
"clock-digital" => "The time, 12 or 24-hour"
"clock-binary" => "The time in binary"
"moon-disc" => "Tonight's moon phase"
"inspector" => "Inspect the shell's interface"
_ => ""
}
}
///| Whether more than one of a module makes sense in the panel; the others leave the Add list
/// once they are in the panel.
fn allows_many(id : String) -> Bool {
id.has_prefix("clock-")
}
///| The rows of the current tab, read live from the host (loading a module changes them).
fn rows() -> Array[Row] {
let rs : Array[Row] = []
match tab.val {
0 => {
let names = @settings.settings()
for i = 0; i < names.length(); i = i + 1 {
rs.push(Setting(i, names[i]))
}
}
1 => {
rs.push(Heading("Wallpaper"))
let names = @wallpaper.wallpapers()
for i = 0; i < names.length(); i = i + 1 {
rs.push(Wallpaper(i, names[i]))
}
}
3 => {
let snap = @system.read()
if snap.battery_percent >= 0 {
rs.push(Heading("Battery"))
let state = if snap.charging { " (charging)" } else { "" }
rs.push(Info(snap.battery_percent.to_string() + "%" + state))
}
rs.push(Heading("When idle"))
rs.push(Timeout(0, "Turn screen off after"))
rs.push(Timeout(1, "Suspend after"))
rs.push(Heading("Now"))
rs.push(PowerNow(0, "Suspend"))
rs.push(PowerNow(2, "Restart"))
rs.push(PowerNow(1, "Power off"))
}
_ => {
rs.push(Heading("In the panel, left to right"))
let loaded = @modules.loaded()
for i = 0; i < loaded.length(); i = i + 1 {
rs.push(Loaded(loaded[i].slot, loaded[i].name, i, loaded.length()))
}
rs.push(Heading("Add to the panel"))
let avail = @modules.available()
let mut any = false
for cat in categories {
let mut first = true
for m in avail {
if category_of(m.id) != cat || (m.loaded > 0U && !allows_many(m.id)) {
continue
}
if first {
rs.push(Category(cat))
first = false
}
rs.push(Available(m.path, m.name, description_of(m.id), m.loaded))
any = true
}
}
if !any {
rs.push(NothingToAdd)
}
rs.push(Browse)
}
}
rs
}
///| Whether row `i` of `rs` can be highlighted and acted on (headings can't).
fn active(rs : Array[Row], i : Int) -> Bool {
i >= 0 && i < rs.length() && !(rs[i] is (Heading(_) | Info(_) | Category(_) | NothingToAdd))
}
///| First active row of `rs`, or -1.
fn first_active(rs : Array[Row]) -> Int {
for i = 0; i < rs.length(); i = i + 1 {
if active(rs, i) {
return i
}
}
-1
}
///| Tab under a popup-local point, or -1.
fn tab_at(x : Int, y : Int) -> Int {
if y < margin || y >= margin + tab_h || x < margin || x >= popup_w - margin {
return -1
}
let i = (x - margin) / tab_w()
if i < tab_names.length() { i } else { -1 }
}
///|
fn tab_w() -> Int {
(popup_w - 2 * margin) / tab_names.length()
}
///| Height of a row: the Panel tab's rows vary (two-line Add rows, slim group labels); every
/// other row is `row_h`.
fn row_height(r : Row) -> Int {
match r {
Loaded(_, _, _, _) => loaded_h
Category(_) => category_h
Available(_, _, _, _) => available_h
Browse => browse_h
_ => row_h
}
}
///|
let loaded_h : Int = 30
///|
let category_h : Int = 22
///|
let available_h : Int = 42
///|
let browse_h : Int = 44
///| Top of each row, popup-local.
fn row_tops(rs : Array[Row]) -> Array[Int] {
let tops = []
let mut y = rows_top
for r in rs {
tops.push(y)
y = y + row_height(r)
}
tops
}
///| Row under a popup-local point, or -1 (headings count as none).
fn row_at(rs : Array[Row], x : Int, y : Int) -> Int {
if x < margin || x >= popup_w - margin || y < rows_top {
return -1
}
let tops = row_tops(rs)
for i = 0; i < rs.length(); i = i + 1 {
if y >= tops[i] && y < tops[i] + row_height(rs[i]) {
return if active(rs, i) { i } else { -1 }
}
}
-1
}
///|
fn popup_h(rs : Array[Row]) -> Int {
let mut h = rows_top + margin
for r in rs {
h = h + row_height(r)
}
h
}
///| The small buttons at the right end of a panel-list row, popup-local: move up, move down,
/// remove.
let btn_size : Int = 24
///|
fn loaded_button(k : Int, top : Int) -> @types.Rect {
// Remove sits apart from the two move buttons.
let right = popup_w - margin - 6
let x = match k {
2 => right - btn_size
1 => right - btn_size - 12 - btn_size
_ => right - btn_size - 12 - 2 * btn_size - 2
}
@ui.rect(x, top + (loaded_h - 2 - btn_size) / 2, btn_size, btn_size)
}
///| Which button of a panel-list row is under popup-local `x`/`y` (0 up, 1 down, 2 remove), or -1.
fn loaded_button_at(top : Int, x : Int, y : Int) -> Int {
for k = 0; k < 3; k = k + 1 {
let b = loaded_button(k, top)
if x >= b.x && x < b.x + @ui.rect_w(b) && y >= b.y && y < b.y + @ui.rect_h(b) {
return k
}
}
-1
}
///| The button under the pointer in the highlighted row (-1: none).
let hover_btn : Ref[Int] = { val: -1 }
///|
fn set_tab(i : Int) -> Unit {
tab.val = i
armed.val = -1
hover.val = first_active(rows())
hover_btn.val = -1
}
///|
fn close() -> Unit {
open_.val = false
armed.val = -1
hover.val = -1
}
///| Act on row `i`: flip a setting, show a wallpaper, load a module, or browse. A panel-list row
/// acts only through button `btn` (0 move up, 1 move down, 2 remove).
fn act(rs : Array[Row], i : Int, btn~ : Int = -1) -> Unit {
if !active(rs, i) {
return
}
let was_armed = armed.val
armed.val = -1
match rs[i] {
Timeout(0, _) => @power.set_screen_off_minutes(next_choice(screen_off_choices, @power.screen_off_minutes().reinterpret_as_int()).reinterpret_as_uint())
Timeout(_, _) => @power.set_suspend_minutes(next_choice(suspend_choices, @power.suspend_minutes().reinterpret_as_int()).reinterpret_as_uint())
PowerNow(0, _) => @power.suspend()
PowerNow(a, _) =>
// Restart and power off take a second click on the same row.
if was_armed == a {
if a == 1 {
@power.power_off()
} else {
@power.reboot()
}
} else {
armed.val = a
}
Info(_) => ()
Setting(k, _) => {
let idx = k.reinterpret_as_uint()
@settings.set_setting(idx, !@settings.is_on(idx))
}
Wallpaper(k, _) => @wallpaper.set_wallpaper(k.reinterpret_as_uint())
Loaded(slot, _, idx, n) =>
match btn {
0 => if idx > 0 { @modules.move_instance(slot, -1) }
1 => if idx < n - 1 { @modules.move_instance(slot, 1) }
2 => @modules.unload_instance(slot)
_ => ()
}
Available(path, _, _, _) => @modules.load_module(path)
Browse => @modules.browse()
Heading(_) | Category(_) | NothingToAdd => ()
}
}
///| Move the highlight by `step` rows, skipping headings; stays put at either end.
fn move_hover(step : Int) -> Unit {
let rs = rows()
let mut i = hover.val + step
while i >= 0 && i < rs.length() {
if active(rs, i) {
hover.val = i
return
}
i = i + step
}
}
///|
pub fn info() -> PlasmoidInfo {
{
id: "org.chandra.session-settings",
name: "Settings",
preferred: { w: 92, h: 34 },
min_width: 34,
stretch: false,
}
}
///|
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
let t = @theme.get_tokens()
let w = size.w.reinterpret_as_int()
let h = size.h.reinterpret_as_int()
let r = t.radius.reinterpret_as_int()
let fs = t.font_size.reinterpret_as_int()
let bg = if open_.val { t.palette.accent } else { t.palette.surface_hover }
let fg = if open_.val { t.palette.accent_foreground } else { t.palette.foreground }
// A small switch glyph (track and knob), then the label when there is room.
let gx = 8
let gy = h / 2
let ops = [
@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r),
@ui.stroke_rect(@ui.rect(gx, gy - 6, 20, 12), fg, width=1, radius=6),
@ui.circle(gx + 14, gy, 4, fg),
]
if w >= 70 {
ops.push(@ui.text(gx + 26, gy, "Settings", fs - 2, fg))
}
ops
}
///|
pub fn popup() -> PopupSurface? {
if !open_.val {
return None
}
let t = @theme.get_tokens()
let p = t.palette
let rs = rows()
let w = popup_w
let h = popup_h(rs)
let tops = row_tops(rs)
let r = t.radius.reinterpret_as_int()
let fs = t.font_size.reinterpret_as_int()
let ops : Array[@types.DrawOp] = [
@ui.fill_rect(@ui.rect(0, 0, w, h), p.surface_popup, radius=r),
@ui.stroke_rect(@ui.rect(0, 0, w, h), p.border, width=1, radius=r),
]
// Tab bar: the current tab filled with the accent.
let tw = tab_w()
for i = 0; i < tab_names.length(); i = i + 1 {
let x = margin + i * tw
let cur = i == tab.val
if cur {
ops.push(@ui.fill_rect(@ui.rect(x + 1, margin, tw - 2, tab_h - 2), p.accent, radius=r))
}
let fg = if cur { p.accent_foreground } else { p.foreground_muted }
ops.push(@ui.text(x + tw / 2, margin + (tab_h - 2) / 2, tab_names[i], fs - 2, fg, align=CENTER, bold=cur))
}
ops.push(@ui.line(margin, rows_top - 3, w - margin, rows_top - 3, p.border, width=1))
let cur_wall = @wallpaper.current_wallpaper().reinterpret_as_int()
for i = 0; i < rs.length(); i = i + 1 {
let y = tops[i]
let rh = row_height(rs[i])
let mid = y + (rh - 2) / 2
let hot = i == hover.val
// Hover: a soft fill behind switches, the accent behind list rows.
let list_fg = if hot { p.accent_foreground } else { p.foreground }
match rs[i] {
Heading(_) | Category(_) | NothingToAdd | Browse => ()
// Rows with their own buttons get the soft fill, so the buttons stand out.
Setting(_, _) | Loaded(_, _, _, _) | Available(_, _, _, _) =>
if hot {
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, rh - 2), p.surface_hover, radius=r))
}
Info(_) => ()
_ =>
if hot {
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, rh - 2), p.accent, radius=r))
}
}
match rs[i] {
Heading(label) => ops.push(@ui.text(margin + 8, mid + 2, label, fs - 1, p.foreground, bold=true))
Category(label) => ops.push(@ui.text(margin + 10, mid, label, fs - 3, p.foreground_muted, bold=true))
NothingToAdd => ops.push(@ui.text(margin + 10, mid, "Everything is in the panel", fs - 2, p.foreground_muted))
Setting(k, name) => {
ops.push(@ui.text(margin + 10, mid, name, fs - 1, p.foreground))
// The switch: an accent track with the knob on the right when on, a muted outline when off.
let on = @settings.is_on(k.reinterpret_as_uint())
let sx = w - margin - 10 - switch_w
let sy = mid - switch_h / 2
let knob = switch_h / 2 - 3
if on {
ops.push(@ui.fill_rect(@ui.rect(sx, sy, switch_w, switch_h), p.accent, radius=switch_h / 2))
ops.push(@ui.circle(sx + switch_w - switch_h / 2, mid, knob, p.accent_foreground))
} else {
ops.push(@ui.stroke_rect(@ui.rect(sx, sy, switch_w, switch_h), p.foreground_muted, width=1, radius=switch_h / 2))
ops.push(@ui.circle(sx + switch_h / 2, mid, knob, p.foreground_muted))
}
}
Wallpaper(k, name) => {
if k == cur_wall {
// A tick: two strokes.
ops.push(@ui.line(margin + 8, mid, margin + 11, mid + 4, list_fg, width=2))
ops.push(@ui.line(margin + 11, mid + 4, margin + 18, mid - 4, list_fg, width=2))
}
ops.push(@ui.text(margin + 26, mid, name, fs - 1, list_fg, bold=k == cur_wall))
}
Loaded(_, name, idx, n) => {
ops.push(@ui.text(margin + 10, mid, name, fs - 1, p.foreground))
for k = 0; k < 3; k = k + 1 {
let enabled = match k {
0 => idx > 0
1 => idx < n - 1
_ => true
}
let b = loaded_button(k, y)
let bx = b.x
let by = b.y
let cx = bx + btn_size / 2
let cy = by + btn_size / 2
let btn_hot = hot && hover_btn.val == k && enabled
if btn_hot {
ops.push(@ui.fill_rect(b, p.accent, radius=r))
}
let ic = if btn_hot {
p.accent_foreground
} else if !enabled {
@ui.with_alpha(p.foreground_muted, 40)
} else if hot {
p.foreground
} else {
p.foreground_muted
}
match k {
0 => {
ops.push(@ui.line(cx - 5, cy + 2, cx, cy - 3, ic, width=2))
ops.push(@ui.line(cx, cy - 3, cx + 5, cy + 2, ic, width=2))
}
1 => {
ops.push(@ui.line(cx - 5, cy - 2, cx, cy + 3, ic, width=2))
ops.push(@ui.line(cx, cy + 3, cx + 5, cy - 2, ic, width=2))
}
_ => {
ops.push(@ui.line(cx - 4, cy - 4, cx + 4, cy + 4, ic, width=2))
ops.push(@ui.line(cx - 4, cy + 4, cx + 4, cy - 4, ic, width=2))
}
}
}
}
Available(_, name, desc, n) => {
if desc == "" {
ops.push(@ui.text(margin + 10, mid, name, fs - 1, p.foreground))
} else {
ops.push(@ui.text(margin + 10, y + 13, name, fs - 1, p.foreground))
ops.push(@ui.text(margin + 10, y + 29, desc, fs - 3, p.foreground_muted))
}
// The Add button: outlined, filled with the accent while its row is highlighted.
let label = if n > 0U { "Add another" } else { "Add" }
let bw = @ui.text_width(label, fs - 2) + 20
let bh = 24
let bx = w - margin - 8 - bw
let by = mid - bh / 2
if hot {
ops.push(@ui.fill_rect(@ui.rect(bx, by, bw, bh), p.accent, radius=bh / 2))
} else {
ops.push(@ui.stroke_rect(@ui.rect(bx, by, bw, bh), p.accent, width=1, radius=bh / 2))
}
let bfg = if hot { p.accent_foreground } else { p.accent }
ops.push(@ui.text(bx + bw / 2, mid, label, fs - 2, bfg, align=CENTER, bold=true))
}
Browse => {
// A secondary button below the list: an outline, softly filled while highlighted.
ops.push(@ui.line(margin + 4, y + 2, w - margin - 4, y + 2, p.border, width=1))
let label = "Browse for a module file..."
let bw = @ui.text_width(label, fs - 2) + 28
let bh = 28
let bx = (w - bw) / 2
let by = y + 9
if hot {
ops.push(@ui.fill_rect(@ui.rect(bx, by, bw, bh), p.surface_hover, radius=r))
}
ops.push(@ui.stroke_rect(@ui.rect(bx, by, bw, bh), if hot { p.accent } else { p.border }, width=1, radius=r))
ops.push(@ui.text(w / 2, by + bh / 2, label, fs - 2, if hot { p.foreground } else { p.foreground_muted }, align=CENTER))
}
Info(text) => ops.push(@ui.text(margin + 10, mid, text, fs - 1, p.foreground))
Timeout(k, label) => {
let m = if k == 0 { @power.screen_off_minutes() } else { @power.suspend_minutes() }
ops.push(@ui.text(margin + 10, mid, label, fs - 1, list_fg))
ops.push(@ui.text(w - margin - 10, mid, minutes_label(m.reinterpret_as_int()), fs - 1, list_fg, align=RIGHT, bold=true))
}
PowerNow(a, label) => {
let text = if armed.val == a { "Click again to " + label.to_lower() } else { label }
ops.push(@ui.text(margin + 10, mid, text, fs - 1, list_fg, bold=armed.val == a))
}
}
}
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
}
///|
pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
match (target, event) {
(WIDGET, PointerDown(_)) => {
if open_.val {
close()
} else {
open_.val = true
set_tab(tab.val) // reopens on the tab it was left on
}
true
}
(POPUP, PointerMove(p)) => {
let rs = rows()
let i = row_at(rs, p.x, p.y)
let b = if i >= 0 && rs[i] is Loaded(_, _, _, _) {
loaded_button_at(row_tops(rs)[i], p.x, p.y)
} else {
-1
}
if i >= 0 && (i != hover.val || b != hover_btn.val) {
hover.val = i
hover_btn.val = b
true
} else {
false
}
}
(POPUP, PointerDown(p)) => {
let ti = tab_at(p.x, p.y)
if ti >= 0 {
if ti != tab.val {
set_tab(ti)
}
return true
}
let rs = rows()
let i = row_at(rs, p.x, p.y)
if i >= 0 {
let btn = if rs[i] is Loaded(_, _, _, _) {
loaded_button_at(row_tops(rs)[i], p.x, p.y)
} else {
-1
}
act(rs, i, btn~)
// A module list changes length: keep the highlight on a real row.
let after = rows()
hover.val = if active(after, i) { i } else { first_active(after) }
// A moved module: keep the highlight on it, under the pointer's button.
match rs[i] {
Loaded(_, _, idx, n) =>
if btn == 0 && idx > 0 {
hover.val = i - 1
} else if btn == 1 && idx < n - 1 {
hover.val = i + 1
}
_ => ()
}
hover_btn.val = -1
}
true
}
(_, FocusLost) =>
if open_.val {
close()
true
} else {
false
}
(_, KeyDown(k)) =>
if !open_.val {
false
} else if k == "Escape" {
close()
true
} else if k == "Enter" || k == " " || k == "Space" {
let rs = rows()
act(rs, hover.val)
let after = rows()
if !active(after, hover.val) {
hover.val = first_active(after)
}
true
} else if k == "Backspace" || k == "Delete" || k == "PageUp" || k == "PageDown" {
let rs = rows()
match (if active(rs, hover.val) { Some(rs[hover.val]) } else { None }) {
Some(Loaded(_, _, idx, n)) => {
let btn = if k == "PageUp" { 0 } else if k == "PageDown" { 1 } else { 2 }
act(rs, hover.val, btn~)
if btn == 0 && idx > 0 {
hover.val = hover.val - 1
} else if btn == 1 && idx < n - 1 {
hover.val = hover.val + 1
}
let after = rows()
if !active(after, hover.val) {
hover.val = first_active(after)
}
true
}
_ => false
}
} else if k == "ArrowDown" || k == "Down" {
move_hover(1)
true
} else if k == "ArrowUp" || k == "Up" {
move_hover(-1)
true
} else if k == "ArrowRight" || k == "Right" {
set_tab((tab.val + 1) % tab_names.length())
true
} else if k == "ArrowLeft" || k == "Left" {
set_tab((tab.val + tab_names.length() - 1) % tab_names.length())
true
} else if k == "1" || k == "2" || k == "3" || k == "4" {
set_tab(k[0].to_int() - '1'.to_int())
true
} else {
false
}
_ => false
}
}