Files
torlink/src/ui/keymap.ts
T

88 lines
2.1 KiB
TypeScript
Raw Normal View History

2026-06-27 02:03:19 -04:00
import type { DownloadFocus, Region, Section } from "./store";
export interface Hint {
keys: string;
label: string;
}
interface HelpGroup {
title: string;
hints: Hint[];
}
export const HELP_GROUPS: HelpGroup[] = [
{
title: "Navigate",
hints: [
{ keys: "↑ ↓", label: "Move" },
{ keys: "↵", label: "Open" },
{ keys: "tab", label: "Switch pane" },
{ keys: "esc", label: "Back" },
{ keys: "q", label: "Quit" },
],
},
{
title: "Search",
hints: [
{ keys: "/", label: "Edit search" },
{ keys: "↵", label: "Run search" },
{ keys: "m", label: "Paste magnet" },
],
},
{
title: "Downloads",
hints: [
{ keys: "p", label: "Pause/resume" },
{ keys: "c", label: "Cancel/remove" },
{ keys: "f", label: "Retry failed" },
{ keys: "d", label: "Download again" },
{ keys: "x", label: "Clear recent" },
],
},
];
const ALWAYS: Hint = { keys: "?", label: "Keys" };
const SWITCH: Hint = { keys: "tab", label: "Switch pane" };
export function footerHints(
region: Region,
section: Section,
downloadFocus?: DownloadFocus | null,
): Hint[] {
if (region === "sidebar") {
return [
{ keys: "↑↓", label: "Move" },
{ keys: "↵", label: "Open" },
SWITCH,
ALWAYS,
{ keys: "q", label: "Quit" },
];
}
if (section === "downloads") {
if (downloadFocus === "paused") {
return [{ keys: "p", label: "Resume" }, { keys: "c", label: "Cancel" }, SWITCH, ALWAYS];
}
if (downloadFocus === "failed") {
return [{ keys: "f", label: "Retry" }, { keys: "c", label: "Remove" }, SWITCH, ALWAYS];
}
if (downloadFocus === "recent") {
return [
{ keys: "d", label: "Download again" },
{ keys: "c", label: "Remove" },
{ keys: "x", label: "Clear" },
SWITCH,
ALWAYS,
];
}
return [{ keys: "p", label: "Pause" }, { keys: "c", label: "Cancel" }, SWITCH, ALWAYS];
}
return [
{ keys: "d", label: "Download" },
{ keys: "/", label: "Search" },
{ keys: "m", label: "Paste magnet" },
SWITCH,
ALWAYS,
];
}