@carlesandres/house 0.4.6 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -5
- package/README.md +23 -11
- package/package.json +1 -1
- package/src/Browser.tsx +321 -184
- package/src/CommandPalette.tsx +78 -14
- package/src/Footer.tsx +65 -31
- package/src/Header.tsx +4 -1
- package/src/Spinner.tsx +39 -0
- package/src/StatusPopover.tsx +189 -0
- package/src/cli/argv.ts +19 -6
- package/src/commands/buildCommands.ts +22 -33
- package/src/commands/score.ts +1 -1
- package/src/config/load.ts +23 -1
- package/src/discovery/walk.ts +20 -3
- package/src/index.tsx +159 -155
- package/src/keymap/browser.ts +17 -23
- package/src/keymap/keymap.ts +4 -4
- package/src/layout/sidebarEmptyState.ts +7 -0
- package/src/markdown/frontmatter.ts +62 -0
- package/src/serve/server.ts +1 -1
- package/src/theme/resolve.ts +1 -1
- package/src/theme/themes/aura.json +1 -1
- package/src/theme/themes/carbonfox.json +1 -1
- package/src/theme/themes/lucent-orng.json +4 -4
- package/src/theme/themes/nightowl.json +2 -2
- package/src/theme/themes/orng.json +2 -2
- package/src/theme/themes/solarized.json +6 -2
- package/src/theme/themes/vesper.json +2 -2
- package/src/tips.ts +0 -5
- package/src/update/check.ts +1 -1
- package/src/update/runtime.ts +1 -1
- package/src/HelpOverlay.tsx +0 -148
package/src/CommandPalette.tsx
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CommandPalette — modal overlay for searching and running commands.
|
|
3
3
|
*
|
|
4
|
-
* Render-only: state lives in Browser.tsx alongside
|
|
4
|
+
* Render-only: state lives in Browser.tsx alongside filterOpen
|
|
5
5
|
* (#70 design log §state location). Key handling sits in Browser.tsx's
|
|
6
6
|
* `useKeyboard` palette-branch, mirroring the filterOpen pattern.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Commands are grouped by semantic category while preserving command order
|
|
9
|
+
* inside each group. Browser.tsx owns the query and selected command index;
|
|
10
|
+
* this component turns those commands into render rows and keeps the selected
|
|
11
|
+
* row visible when the list is taller than the modal body.
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
14
|
import { RGBA } from "@opentui/core"
|
|
@@ -29,6 +31,52 @@ export interface CommandPaletteProps {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
const FOOTER_HINT = "↑↓ select enter run esc close"
|
|
34
|
+
const CATEGORY_ORDER = ["Navigation", "View", "File", "Appearance", "App"] as const
|
|
35
|
+
|
|
36
|
+
type PaletteRow =
|
|
37
|
+
| { readonly kind: "spacer"; readonly key: string }
|
|
38
|
+
| { readonly kind: "header"; readonly key: string; readonly text: string }
|
|
39
|
+
| {
|
|
40
|
+
readonly kind: "command"
|
|
41
|
+
readonly key: string
|
|
42
|
+
readonly command: AppCommand
|
|
43
|
+
readonly commandIndex: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const orderCommandsForPalette = (commands: readonly AppCommand[]): readonly AppCommand[] => {
|
|
47
|
+
const grouped = new Map<string, AppCommand[]>()
|
|
48
|
+
for (const command of commands) {
|
|
49
|
+
const category = command.category ?? "Other"
|
|
50
|
+
const list = grouped.get(category)
|
|
51
|
+
if (list) list.push(command)
|
|
52
|
+
else grouped.set(category, [command])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const orderedCategories = [
|
|
56
|
+
...CATEGORY_ORDER.filter((category) => grouped.has(category)),
|
|
57
|
+
...Array.from(grouped.keys()).filter((category) => !CATEGORY_ORDER.includes(category as never)),
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
return orderedCategories.flatMap((category) => grouped.get(category) ?? [])
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const buildRows = (commands: readonly AppCommand[]): readonly PaletteRow[] => {
|
|
64
|
+
const orderedCommands = orderCommandsForPalette(commands)
|
|
65
|
+
const rows: PaletteRow[] = []
|
|
66
|
+
let previousCategory: string | null = null
|
|
67
|
+
let commandIndex = 0
|
|
68
|
+
for (const command of orderedCommands) {
|
|
69
|
+
const category = command.category ?? "Other"
|
|
70
|
+
if (category !== previousCategory) {
|
|
71
|
+
if (previousCategory !== null) rows.push({ kind: "spacer", key: `spacer-${category}` })
|
|
72
|
+
rows.push({ kind: "header", key: `header-${category}`, text: category })
|
|
73
|
+
previousCategory = category
|
|
74
|
+
}
|
|
75
|
+
rows.push({ kind: "command", key: command.id, command, commandIndex })
|
|
76
|
+
commandIndex += 1
|
|
77
|
+
}
|
|
78
|
+
return rows
|
|
79
|
+
}
|
|
32
80
|
|
|
33
81
|
export const CommandPalette = ({
|
|
34
82
|
commands,
|
|
@@ -38,11 +86,12 @@ export const CommandPalette = ({
|
|
|
38
86
|
viewportHeight,
|
|
39
87
|
}: CommandPaletteProps) => {
|
|
40
88
|
const overlayWidth = Math.min(viewportWidth - 4, 64)
|
|
89
|
+
const rows = buildRows(commands)
|
|
41
90
|
// Reserve: 2 for border (top+bottom), 1 query row, 1 spacer below query,
|
|
42
91
|
// 1 spacer above footer, 1 footer row. Body gets the rest.
|
|
43
92
|
const chrome = 2 + 1 + 1 + 1 + 1
|
|
44
93
|
const maxBody = Math.max(1, viewportHeight - 4 - chrome)
|
|
45
|
-
const desiredBody = Math.max(1,
|
|
94
|
+
const desiredBody = Math.max(1, rows.length || 1)
|
|
46
95
|
const bodyHeight = Math.min(desiredBody, maxBody)
|
|
47
96
|
const overlayHeight = chrome + bodyHeight
|
|
48
97
|
const left = Math.max(0, Math.floor((viewportWidth - overlayWidth) / 2))
|
|
@@ -51,17 +100,19 @@ export const CommandPalette = ({
|
|
|
51
100
|
// Inner content width: overlay minus 1-cell border + 1-cell padding on each side.
|
|
52
101
|
const rowWidth = Math.max(4, overlayWidth - 4)
|
|
53
102
|
|
|
54
|
-
// Window the visible slice around the
|
|
55
|
-
//
|
|
56
|
-
// inevitable backlog growth.
|
|
103
|
+
// Window the visible slice around the selected command row. Headers and
|
|
104
|
+
// spacers are render-only rows, so selection still tracks command indexes.
|
|
57
105
|
const scrollTop = (() => {
|
|
58
|
-
if (
|
|
59
|
-
const maxScroll =
|
|
106
|
+
if (rows.length <= bodyHeight) return 0
|
|
107
|
+
const maxScroll = rows.length - bodyHeight
|
|
60
108
|
let s = 0
|
|
61
|
-
|
|
109
|
+
const selectedRowIndex = rows.findIndex(
|
|
110
|
+
(row) => row.kind === "command" && row.commandIndex === selectedIndex,
|
|
111
|
+
)
|
|
112
|
+
if (selectedRowIndex >= bodyHeight) s = selectedRowIndex - bodyHeight + 1
|
|
62
113
|
return Math.max(0, Math.min(s, maxScroll))
|
|
63
114
|
})()
|
|
64
|
-
const visible =
|
|
115
|
+
const visible = rows.slice(scrollTop, scrollTop + bodyHeight)
|
|
65
116
|
|
|
66
117
|
// Shortcut column width — long enough for `shift+t`-style chords but
|
|
67
118
|
// trimmed to prevent the title from being squeezed below ~16 cells.
|
|
@@ -110,9 +161,22 @@ export const CommandPalette = ({
|
|
|
110
161
|
{commands.length === 0 ? (
|
|
111
162
|
<text wrapMode="none" content=" (no matches)" style={{ fg: colors.textMuted }} />
|
|
112
163
|
) : (
|
|
113
|
-
visible.map((
|
|
114
|
-
|
|
115
|
-
|
|
164
|
+
visible.map((row) => {
|
|
165
|
+
if (row.kind === "spacer") {
|
|
166
|
+
return <text key={row.key} content=" " />
|
|
167
|
+
}
|
|
168
|
+
if (row.kind === "header") {
|
|
169
|
+
return (
|
|
170
|
+
<text
|
|
171
|
+
key={row.key}
|
|
172
|
+
wrapMode="none"
|
|
173
|
+
content={fit(row.text, rowWidth)}
|
|
174
|
+
style={{ fg: colors.textMuted, attributes: 1 }}
|
|
175
|
+
/>
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
const cmd = row.command
|
|
179
|
+
const isSelected = row.commandIndex === selectedIndex
|
|
116
180
|
const selector = isSelected ? "▸ " : " "
|
|
117
181
|
const titleText = fit(cmd.title, titleWidth)
|
|
118
182
|
const shortcutText = cmd.shortcut
|
package/src/Footer.tsx
CHANGED
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
* require a real cell-width counter (e.g. East Asian Width).
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import type React from "react"
|
|
24
25
|
import type { KeyBinding } from "./keymap/keymap.ts"
|
|
25
26
|
import { displayKey } from "./keymap/displayKey.ts"
|
|
27
|
+
import { Spinner } from "./Spinner.tsx"
|
|
26
28
|
import { colors } from "./theme/colors.ts"
|
|
27
29
|
|
|
28
30
|
/** Rows the Footer occupies. Importers use it for layout math so a future
|
|
@@ -38,24 +40,26 @@ export interface FooterProps<C> {
|
|
|
38
40
|
* no TTL, cleared by the caller when the underlying activity finishes.
|
|
39
41
|
* Loses to `notice` when both are set so transient toasts still surface. */
|
|
40
42
|
readonly discoveryStatus?: string | null
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
/** Test seam: override spinner tick speed so tests don't sleep on the full
|
|
44
|
+
* production interval. Ignored when discoveryStatus is null. */
|
|
45
|
+
readonly discoverySpinnerIntervalMs?: number
|
|
46
|
+
readonly discoverySpinnerInitialFrameIndex?: number
|
|
47
|
+
/** Test seam: deterministic footer spinner driver. */
|
|
48
|
+
readonly discoverySpinnerRegisterTick?: ((tick: () => void) => void) | null
|
|
49
|
+
/** Optional toggle callback for the discovery-warning popover. */
|
|
50
|
+
readonly onDiscoveryWarningToggle?: () => void
|
|
46
51
|
}
|
|
47
52
|
|
|
53
|
+
const normalizeStatusLine = (status: string): string => status.replace(/\s+/g, " ").trim()
|
|
54
|
+
|
|
48
55
|
const HINT_SEPARATOR = " "
|
|
49
56
|
|
|
50
|
-
/** Hint row entries. `key === null` is a standalone chip (e.g. the filter
|
|
51
|
-
* chip) and renders as muted text without the key/label split. */
|
|
52
57
|
interface Hint {
|
|
53
|
-
readonly key: string
|
|
58
|
+
readonly key: string
|
|
54
59
|
readonly label: string
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
const hintWidth = (h: Hint): number =>
|
|
58
|
-
h.key === null ? h.label.length : h.key.length + 1 + h.label.length // key + " " + label
|
|
62
|
+
const hintWidth = (h: Hint): number => h.key.length + 1 + h.label.length // key + " " + label
|
|
59
63
|
|
|
60
64
|
const formatHint = <C,>(b: KeyBinding<C>): Hint | null => {
|
|
61
65
|
if (!b.hint) return null
|
|
@@ -65,8 +69,8 @@ const formatHint = <C,>(b: KeyBinding<C>): Hint | null => {
|
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
/** Drop hints from the end until they fit within `width`. If not even the
|
|
68
|
-
* first hint fits, fall back to the bare key
|
|
69
|
-
*
|
|
72
|
+
* first hint fits, fall back to the bare key truncated to width, so the row
|
|
73
|
+
* is never silently blank on tight viewports. */
|
|
70
74
|
const fitHints = (hints: readonly Hint[], width: number): Hint[] => {
|
|
71
75
|
if (width <= 0 || hints.length === 0) return []
|
|
72
76
|
const acc: Hint[] = []
|
|
@@ -79,19 +83,24 @@ const fitHints = (hints: readonly Hint[], width: number): Hint[] => {
|
|
|
79
83
|
}
|
|
80
84
|
if (acc.length > 0) return acc
|
|
81
85
|
const first = hints[0]!
|
|
82
|
-
if (first.key === null) return [{ key: null, label: first.label.slice(0, width) }]
|
|
83
86
|
return [{ key: first.key.slice(0, width), label: "" }]
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
const STATUS_SEPARATOR = " · "
|
|
87
90
|
|
|
91
|
+
const isPartialDiscoveryWarning = (status: string | null): boolean =>
|
|
92
|
+
status?.startsWith("scan incomplete:") ?? false
|
|
93
|
+
|
|
88
94
|
export const Footer = <C,>({
|
|
89
95
|
bindings,
|
|
90
96
|
ctx,
|
|
91
97
|
width,
|
|
92
98
|
notice,
|
|
93
99
|
discoveryStatus,
|
|
94
|
-
|
|
100
|
+
discoverySpinnerIntervalMs,
|
|
101
|
+
discoverySpinnerInitialFrameIndex,
|
|
102
|
+
discoverySpinnerRegisterTick,
|
|
103
|
+
onDiscoveryWarningToggle,
|
|
95
104
|
}: FooterProps<C>) => {
|
|
96
105
|
const usableWidth = Math.max(0, width - 2) // 1-cell horizontal padding each side
|
|
97
106
|
|
|
@@ -106,13 +115,6 @@ export const Footer = <C,>({
|
|
|
106
115
|
} as const
|
|
107
116
|
|
|
108
117
|
const hints: Hint[] = []
|
|
109
|
-
// The filter chip prepends to the hint row when a filter is applied and the
|
|
110
|
-
// input is closed. Bracketed to avoid looking like a `key:hint` binding —
|
|
111
|
-
// "filter" is not a key. Surfaces the otherwise-invisible invariant that
|
|
112
|
-
// `[`/`]` walks the filtered set. See DESIGN.md §7.1 Q1.
|
|
113
|
-
if (filterQuery && filterQuery.length > 0) {
|
|
114
|
-
hints.push({ key: null, label: `[filter: ${filterQuery}]` })
|
|
115
|
-
}
|
|
116
118
|
for (const b of bindings) {
|
|
117
119
|
// Hint visibility prefers `hintWhen` (binding-specific) over `when`
|
|
118
120
|
// (dispatch gate). Falling back to `when` keeps the original
|
|
@@ -126,14 +128,17 @@ export const Footer = <C,>({
|
|
|
126
128
|
// Discovery status sits left of the hints, separated by " · ". On tight
|
|
127
129
|
// viewports it claims its budget first; hints fit into the remainder so
|
|
128
130
|
// the indicator stays visible while less-essential hints drop off.
|
|
129
|
-
const status =
|
|
130
|
-
|
|
131
|
+
const status =
|
|
132
|
+
discoveryStatus && discoveryStatus.length > 0 ? normalizeStatusLine(discoveryStatus) : null
|
|
133
|
+
const isPartialWarning = isPartialDiscoveryWarning(status)
|
|
134
|
+
const statusBudget = status
|
|
135
|
+
? Math.min((isPartialWarning ? 1 : status.length) + STATUS_SEPARATOR.length, usableWidth)
|
|
136
|
+
: 0
|
|
131
137
|
const hintsWidth = Math.max(0, usableWidth - statusBudget)
|
|
132
138
|
const visibleHints = fitHints(hints, hintsWidth)
|
|
133
139
|
const statusContent = status
|
|
134
140
|
? status.slice(0, Math.max(0, statusBudget - STATUS_SEPARATOR.length))
|
|
135
141
|
: ""
|
|
136
|
-
|
|
137
142
|
const noticeContent = notice
|
|
138
143
|
? notice.length > usableWidth
|
|
139
144
|
? notice.slice(0, usableWidth)
|
|
@@ -156,12 +161,6 @@ export const Footer = <C,>({
|
|
|
156
161
|
/>,
|
|
157
162
|
]
|
|
158
163
|
: []
|
|
159
|
-
if (h.key === null) {
|
|
160
|
-
return [
|
|
161
|
-
...sep,
|
|
162
|
-
<text key={`l${i}`} content={h.label} wrapMode="none" style={{ fg: colors.secondary }} />,
|
|
163
|
-
]
|
|
164
|
-
}
|
|
165
164
|
return [
|
|
166
165
|
...sep,
|
|
167
166
|
<text key={`k${i}`} content={h.key} wrapMode="none" style={{ fg: colors.text }} />,
|
|
@@ -184,10 +183,45 @@ export const Footer = <C,>({
|
|
|
184
183
|
)
|
|
185
184
|
}
|
|
186
185
|
|
|
186
|
+
const warningTrigger = isPartialWarning ? (
|
|
187
|
+
<box
|
|
188
|
+
{...(onDiscoveryWarningToggle === undefined ? {} : { onMouseUp: onDiscoveryWarningToggle })}
|
|
189
|
+
style={{
|
|
190
|
+
width: 1,
|
|
191
|
+
height: 1,
|
|
192
|
+
flexDirection: "row",
|
|
193
|
+
backgroundColor: colors.backgroundElement,
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
<text content="!" wrapMode="none" style={{ fg: colors.warning, attributes: 1 }} />
|
|
197
|
+
</box>
|
|
198
|
+
) : null
|
|
199
|
+
|
|
187
200
|
if (status !== null) {
|
|
201
|
+
const spinnerProps = {
|
|
202
|
+
fg: colors.secondary,
|
|
203
|
+
...(discoverySpinnerIntervalMs === undefined
|
|
204
|
+
? {}
|
|
205
|
+
: { intervalMs: discoverySpinnerIntervalMs }),
|
|
206
|
+
...(discoverySpinnerInitialFrameIndex === undefined
|
|
207
|
+
? {}
|
|
208
|
+
: { initialFrameIndex: discoverySpinnerInitialFrameIndex }),
|
|
209
|
+
...(discoverySpinnerRegisterTick === undefined
|
|
210
|
+
? {}
|
|
211
|
+
: { registerTick: discoverySpinnerRegisterTick }),
|
|
212
|
+
} satisfies React.ComponentProps<typeof Spinner>
|
|
213
|
+
|
|
188
214
|
return (
|
|
189
215
|
<box style={rowStyle}>
|
|
190
|
-
|
|
216
|
+
{isPartialWarning ? null : <Spinner {...spinnerProps} />}
|
|
217
|
+
{isPartialWarning ? null : (
|
|
218
|
+
<text content=" " wrapMode="none" style={{ fg: colors.textMuted }} />
|
|
219
|
+
)}
|
|
220
|
+
{isPartialWarning ? (
|
|
221
|
+
warningTrigger
|
|
222
|
+
) : (
|
|
223
|
+
<text content={statusContent} wrapMode="none" style={{ fg: colors.secondary }} />
|
|
224
|
+
)}
|
|
191
225
|
<text content={STATUS_SEPARATOR} wrapMode="none" style={{ fg: colors.textMuted }} />
|
|
192
226
|
{renderHints()}
|
|
193
227
|
</box>
|
package/src/Header.tsx
CHANGED
|
@@ -61,7 +61,10 @@ export const Header = ({ width, currentFile, version = pkg.version }: HeaderProp
|
|
|
61
61
|
backgroundColor: colors.backgroundPanel,
|
|
62
62
|
}}
|
|
63
63
|
>
|
|
64
|
-
<text
|
|
64
|
+
<text wrapMode="none">
|
|
65
|
+
<span style={{ fg: colors.text }}>{brand}</span>
|
|
66
|
+
{showFile && <span style={{ fg: colors.textMuted }}>{`${FILE_SEPARATOR}${file}`}</span>}
|
|
67
|
+
</text>
|
|
65
68
|
{showRight && <text content={right} wrapMode="none" style={{ fg: colors.text }} />}
|
|
66
69
|
</box>
|
|
67
70
|
)
|
package/src/Spinner.tsx
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react"
|
|
2
|
+
import { colors } from "./theme/colors.ts"
|
|
3
|
+
|
|
4
|
+
const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] as const
|
|
5
|
+
const FRAME_COUNT = FRAMES.length
|
|
6
|
+
const normalizeFrameIndex = (index: number) => ((index % FRAME_COUNT) + FRAME_COUNT) % FRAME_COUNT
|
|
7
|
+
|
|
8
|
+
export interface SpinnerProps {
|
|
9
|
+
readonly fg?: string
|
|
10
|
+
readonly intervalMs?: number
|
|
11
|
+
readonly initialFrameIndex?: number
|
|
12
|
+
/** Test seam: deterministic driver for frame advancement. When present,
|
|
13
|
+
* Spinner registers its tick callback here instead of starting an interval. */
|
|
14
|
+
readonly registerTick?: ((tick: () => void) => void) | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Spinner = ({
|
|
18
|
+
fg = colors.textMuted,
|
|
19
|
+
intervalMs = 100,
|
|
20
|
+
initialFrameIndex = 0,
|
|
21
|
+
registerTick = null,
|
|
22
|
+
}: SpinnerProps) => {
|
|
23
|
+
const [index, setIndex] = useState(() => normalizeFrameIndex(initialFrameIndex))
|
|
24
|
+
const tickRef = useRef<() => void>(() => undefined)
|
|
25
|
+
tickRef.current = () => setIndex((prev) => (prev + 1) % FRAME_COUNT)
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (registerTick) {
|
|
29
|
+
registerTick(() => tickRef.current())
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
const id = setInterval(() => {
|
|
33
|
+
tickRef.current()
|
|
34
|
+
}, intervalMs)
|
|
35
|
+
return () => clearInterval(id)
|
|
36
|
+
}, [intervalMs, registerTick])
|
|
37
|
+
|
|
38
|
+
return <text content={FRAMES[index] ?? FRAMES[0]} wrapMode="none" style={{ fg }} />
|
|
39
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { useTerminalDimensions } from "@opentui/react"
|
|
2
|
+
import { useMemo, useState } from "react"
|
|
3
|
+
import { colors } from "./theme/colors.ts"
|
|
4
|
+
|
|
5
|
+
export type StatusPopoverVariant = "info" | "warning" | "error" | "success"
|
|
6
|
+
|
|
7
|
+
export interface StatusPopoverProps {
|
|
8
|
+
readonly icon: string
|
|
9
|
+
readonly content: string
|
|
10
|
+
readonly variant?: StatusPopoverVariant
|
|
11
|
+
readonly open?: boolean
|
|
12
|
+
readonly defaultOpen?: boolean
|
|
13
|
+
readonly onOpenChange?: (open: boolean) => void
|
|
14
|
+
readonly showPanel?: boolean
|
|
15
|
+
readonly minWidth?: number
|
|
16
|
+
readonly maxWidth?: number
|
|
17
|
+
readonly maxHeight?: number
|
|
18
|
+
readonly zIndex?: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface StatusPopoverPanelProps {
|
|
22
|
+
readonly content: string
|
|
23
|
+
readonly variant?: StatusPopoverVariant
|
|
24
|
+
readonly minWidth?: number
|
|
25
|
+
readonly maxWidth?: number
|
|
26
|
+
readonly maxHeight?: number
|
|
27
|
+
readonly zIndex?: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const clamp = (n: number, min: number, max: number) => Math.max(min, Math.min(max, n))
|
|
31
|
+
|
|
32
|
+
const variantFg = (variant: StatusPopoverVariant): string => {
|
|
33
|
+
switch (variant) {
|
|
34
|
+
case "info":
|
|
35
|
+
return colors.info
|
|
36
|
+
case "warning":
|
|
37
|
+
return colors.warning
|
|
38
|
+
case "error":
|
|
39
|
+
return colors.error
|
|
40
|
+
case "success":
|
|
41
|
+
return colors.success
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const measureLine = (line: string): number => line.length
|
|
46
|
+
|
|
47
|
+
const wrapLine = (line: string, width: number): string[] => {
|
|
48
|
+
if (width <= 0) return [line]
|
|
49
|
+
if (line.length <= width) return [line]
|
|
50
|
+
const out: string[] = []
|
|
51
|
+
let i = 0
|
|
52
|
+
while (i < line.length) {
|
|
53
|
+
out.push(line.slice(i, i + width))
|
|
54
|
+
i += width
|
|
55
|
+
}
|
|
56
|
+
return out
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const StatusPopover = ({
|
|
60
|
+
icon,
|
|
61
|
+
content,
|
|
62
|
+
variant = "warning",
|
|
63
|
+
open,
|
|
64
|
+
defaultOpen = false,
|
|
65
|
+
onOpenChange,
|
|
66
|
+
showPanel = true,
|
|
67
|
+
minWidth = 14,
|
|
68
|
+
maxWidth = 40,
|
|
69
|
+
maxHeight = 12,
|
|
70
|
+
zIndex = 30,
|
|
71
|
+
}: StatusPopoverProps) => {
|
|
72
|
+
const { width: viewportWidth, height: viewportHeight } = useTerminalDimensions()
|
|
73
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen)
|
|
74
|
+
const isOpen = open ?? uncontrolledOpen
|
|
75
|
+
const setOpen = (next: boolean) => {
|
|
76
|
+
if (open === undefined) setUncontrolledOpen(next)
|
|
77
|
+
onOpenChange?.(next)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const lines = useMemo(() => content.split(/\r?\n/), [content])
|
|
81
|
+
const textWidth = useMemo(() => {
|
|
82
|
+
const widest = Math.max(1, ...lines.map(measureLine))
|
|
83
|
+
return clamp(widest, minWidth, Math.min(maxWidth, Math.max(1, viewportWidth - 4)))
|
|
84
|
+
}, [content, lines, maxWidth, minWidth, viewportWidth])
|
|
85
|
+
|
|
86
|
+
const wrapped = useMemo(
|
|
87
|
+
() => lines.flatMap((line) => wrapLine(line, textWidth)),
|
|
88
|
+
[lines, textWidth],
|
|
89
|
+
)
|
|
90
|
+
const bodyHeight = Math.min(maxHeight, Math.max(1, wrapped.length))
|
|
91
|
+
const popoverWidth = Math.min(textWidth + 2, Math.max(1, viewportWidth - 2))
|
|
92
|
+
const popoverHeight = Math.min(bodyHeight + 2, Math.max(3, viewportHeight - 2))
|
|
93
|
+
|
|
94
|
+
const left = 1
|
|
95
|
+
const top = Math.max(0, viewportHeight - popoverHeight - 2)
|
|
96
|
+
|
|
97
|
+
const linesToRender = wrapped.slice(0, Math.max(0, popoverHeight - 2))
|
|
98
|
+
while (linesToRender.length < popoverHeight - 2) linesToRender.push("")
|
|
99
|
+
const triggerFg = variantFg(variant)
|
|
100
|
+
const borderColor = variantFg(variant)
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<>
|
|
104
|
+
<box
|
|
105
|
+
onMouseUp={() => setOpen(!isOpen)}
|
|
106
|
+
style={{
|
|
107
|
+
width: 3,
|
|
108
|
+
height: 1,
|
|
109
|
+
flexDirection: "row",
|
|
110
|
+
backgroundColor: colors.backgroundElement,
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
<text content={` ${icon} `} wrapMode="none" style={{ fg: triggerFg, attributes: 1 }} />
|
|
114
|
+
</box>
|
|
115
|
+
{showPanel && isOpen && (
|
|
116
|
+
<box
|
|
117
|
+
position="absolute"
|
|
118
|
+
left={left}
|
|
119
|
+
top={top}
|
|
120
|
+
width={popoverWidth}
|
|
121
|
+
height={popoverHeight}
|
|
122
|
+
zIndex={zIndex}
|
|
123
|
+
style={{
|
|
124
|
+
border: true,
|
|
125
|
+
borderColor,
|
|
126
|
+
backgroundColor: colors.backgroundPanel,
|
|
127
|
+
flexDirection: "column",
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<text content="" />
|
|
131
|
+
{linesToRender.map((line, i) => (
|
|
132
|
+
<text key={i} content={line} wrapMode="none" style={{ fg: colors.text }} />
|
|
133
|
+
))}
|
|
134
|
+
<text content="" />
|
|
135
|
+
</box>
|
|
136
|
+
)}
|
|
137
|
+
</>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const StatusPopoverPanel = ({
|
|
142
|
+
content,
|
|
143
|
+
variant = "warning",
|
|
144
|
+
minWidth = 14,
|
|
145
|
+
maxWidth = 40,
|
|
146
|
+
maxHeight = 12,
|
|
147
|
+
zIndex = 30,
|
|
148
|
+
}: StatusPopoverPanelProps) => {
|
|
149
|
+
const { width: viewportWidth, height: viewportHeight } = useTerminalDimensions()
|
|
150
|
+
const lines = useMemo(() => content.split(/\r?\n/), [content])
|
|
151
|
+
const textWidth = useMemo(() => {
|
|
152
|
+
const widest = Math.max(1, ...lines.map(measureLine))
|
|
153
|
+
return clamp(widest, minWidth, Math.min(maxWidth, Math.max(1, viewportWidth - 4)))
|
|
154
|
+
}, [lines, maxWidth, minWidth, viewportWidth])
|
|
155
|
+
const wrapped = useMemo(
|
|
156
|
+
() => lines.flatMap((line) => wrapLine(line, textWidth)),
|
|
157
|
+
[lines, textWidth],
|
|
158
|
+
)
|
|
159
|
+
const bodyHeight = Math.min(maxHeight, Math.max(1, wrapped.length))
|
|
160
|
+
const popoverWidth = Math.min(textWidth + 2, Math.max(1, viewportWidth - 2))
|
|
161
|
+
const popoverHeight = Math.min(bodyHeight + 2, Math.max(3, viewportHeight - 2))
|
|
162
|
+
const linesToRender = wrapped.slice(0, Math.max(0, popoverHeight - 2))
|
|
163
|
+
while (linesToRender.length < popoverHeight - 2) linesToRender.push("")
|
|
164
|
+
|
|
165
|
+
const borderColor = variantFg(variant)
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<box
|
|
169
|
+
position="absolute"
|
|
170
|
+
left={1}
|
|
171
|
+
top={Math.max(0, viewportHeight - popoverHeight - 2)}
|
|
172
|
+
width={popoverWidth}
|
|
173
|
+
height={popoverHeight}
|
|
174
|
+
zIndex={zIndex}
|
|
175
|
+
style={{
|
|
176
|
+
border: true,
|
|
177
|
+
borderColor,
|
|
178
|
+
backgroundColor: colors.backgroundPanel,
|
|
179
|
+
flexDirection: "column",
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
<text content="" />
|
|
183
|
+
{linesToRender.map((line, i) => (
|
|
184
|
+
<text key={i} content={line} wrapMode="none" style={{ fg: colors.text }} />
|
|
185
|
+
))}
|
|
186
|
+
<text content="" />
|
|
187
|
+
</box>
|
|
188
|
+
)
|
|
189
|
+
}
|
package/src/cli/argv.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { themeDefinitions } from "../theme/registry.ts"
|
|
|
4
4
|
export interface ParsedArgs {
|
|
5
5
|
/** First positional argument, or null if none was given. */
|
|
6
6
|
readonly path: string | null
|
|
7
|
+
/** Value of `--root <dir>`, or null. */
|
|
8
|
+
readonly root: string | null
|
|
7
9
|
/** Value of `--theme <id>`, or null. Validated by the boot layer against the registry. */
|
|
8
10
|
readonly theme: string | null
|
|
9
11
|
/** Value of `--tone dark|light`, or null. Validated by the boot layer. */
|
|
@@ -12,7 +14,7 @@ export interface ParsedArgs {
|
|
|
12
14
|
readonly width: string | null
|
|
13
15
|
/** Value of `--sort <mode>` (`dirs-first` or `files-first`), or null. Validated by the boot layer. */
|
|
14
16
|
readonly sort: string | null
|
|
15
|
-
/** True when `--serve` was passed: serve the
|
|
17
|
+
/** True when `--serve` was passed: serve the positional path as HTML, skip TUI. */
|
|
16
18
|
readonly serve: boolean
|
|
17
19
|
/** Value of `--port <N>`, or null. Validated by the boot layer. */
|
|
18
20
|
readonly port: string | null
|
|
@@ -58,6 +60,7 @@ const createProgram = () =>
|
|
|
58
60
|
.option("--no-mdx")
|
|
59
61
|
.option("--focus [mode]")
|
|
60
62
|
.option("--show [list]")
|
|
63
|
+
.option("--root [dir]")
|
|
61
64
|
.option("-h, --help")
|
|
62
65
|
.option("-v, --version")
|
|
63
66
|
.argument("[path]")
|
|
@@ -71,6 +74,7 @@ const VALUE_FLAGS: ReadonlySet<string> = new Set([
|
|
|
71
74
|
"--sidebar",
|
|
72
75
|
"--focus",
|
|
73
76
|
"--show",
|
|
77
|
+
"--root",
|
|
74
78
|
])
|
|
75
79
|
|
|
76
80
|
const BOOLEAN_FLAGS: ReadonlySet<string> = new Set([
|
|
@@ -115,6 +119,7 @@ export const parseArgv = (argv: readonly string[]): ParsedArgs => {
|
|
|
115
119
|
|
|
116
120
|
return {
|
|
117
121
|
path: typeof pathArg === "string" ? pathArg : null,
|
|
122
|
+
root: stringOrNull(opts["root"]),
|
|
118
123
|
theme: stringOrNull(opts["theme"]),
|
|
119
124
|
tone: stringOrNull(opts["tone"]),
|
|
120
125
|
width: stringOrNull(opts["width"]),
|
|
@@ -134,9 +139,11 @@ export const parseArgv = (argv: readonly string[]): ParsedArgs => {
|
|
|
134
139
|
|
|
135
140
|
const themeList = themeDefinitions.map((t) => t.id).join(", ")
|
|
136
141
|
|
|
137
|
-
export const usage = `usage:
|
|
142
|
+
export const usage = `usage:
|
|
143
|
+
house [query] [options]
|
|
144
|
+
house --serve <path> [--port N]
|
|
138
145
|
|
|
139
|
-
|
|
146
|
+
query initial filter query; omit to browse the full discovery root
|
|
140
147
|
|
|
141
148
|
options:
|
|
142
149
|
--theme <id> color theme: ${themeList} (default: opencode)
|
|
@@ -144,10 +151,11 @@ options:
|
|
|
144
151
|
--width <N> cap rendered markdown width at N columns
|
|
145
152
|
--show <list> reveal normally-skipped entries; comma-separated subset of:
|
|
146
153
|
hidden, gitignored. Use --show "" to clear.
|
|
154
|
+
--root <dir> discovery root to walk (overrides defaultRoot config/env)
|
|
147
155
|
--sort <mode> sidebar order: dirs-first (default) or files-first
|
|
148
156
|
--sidebar <m> initial sidebar visibility: auto (default), on, or off
|
|
149
157
|
--focus <m> startup focus: sidebar, reader, or filter (default: filter)
|
|
150
|
-
--serve serve the
|
|
158
|
+
--serve serve the positional path as HTML in the browser (skips TUI)
|
|
151
159
|
--port <N> port for --serve (default: OS-assigned)
|
|
152
160
|
-h, --help show this help and exit
|
|
153
161
|
-v, --version print version and exit
|
|
@@ -155,8 +163,13 @@ options:
|
|
|
155
163
|
--no-update-check suppress the "newer version available" check (also via NO_UPDATE_NOTIFIER=1)
|
|
156
164
|
--no-mdx exclude .mdx files from discovery (default: included)
|
|
157
165
|
|
|
166
|
+
examples:
|
|
167
|
+
house README.md
|
|
168
|
+
house --root docs
|
|
169
|
+
house --serve README.md
|
|
170
|
+
|
|
158
171
|
configuration:
|
|
159
172
|
file: $XDG_CONFIG_HOME/house/config.toml (default ~/.config/house/config.toml)
|
|
160
|
-
keys: theme, tone, mdx, show, focus
|
|
161
|
-
env: HOUSE_THEME, HOUSE_TONE, HOUSE_MDX, HOUSE_SHOW, HOUSE_FOCUS
|
|
173
|
+
keys: theme, tone, mdx, show, focus, defaultRoot
|
|
174
|
+
env: HOUSE_THEME, HOUSE_TONE, HOUSE_MDX, HOUSE_SHOW, HOUSE_FOCUS, HOUSE_DEFAULT_ROOT
|
|
162
175
|
precedence (high → low): flags → env → file → defaults`
|