tui: simplify theme selection API by renaming setSelectedTheme to set

This commit is contained in:
Dax Raad
2025-10-31 18:11:36 -04:00
parent 7a926b32ce
commit 3823d8d50e
3 changed files with 33 additions and 17 deletions

View File

@@ -59,7 +59,8 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
props.options,
filter((x) => x.disabled !== true),
take(props.limit ?? Infinity),
(x) => (!needle ? x : fuzzysort.go(needle, x, { keys: ["title", "category"] }).map((x) => x.obj)),
(x) =>
!needle ? x : fuzzysort.go(needle, x, { keys: ["title", "category"] }).map((x) => x.obj),
)
return result
})
@@ -128,8 +129,10 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
if (evt.name === "pagedown") move(10)
if (evt.name === "return") {
const option = selected()
if (option.onSelect) option.onSelect(dialog)
props.onSelect?.(option)
if (option) {
if (option.onSelect) option.onSelect(dialog)
props.onSelect?.(option)
}
}
for (const item of props.keybind ?? []) {
@@ -206,11 +209,15 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
props.onSelect?.(option)
}}
onMouseOver={() => {
const index = filtered().findIndex((x) => isDeepEqual(x.value, option.value))
const index = filtered().findIndex((x) =>
isDeepEqual(x.value, option.value),
)
if (index === -1) return
moveTo(index)
}}
backgroundColor={active() ? (option.bg ?? theme.primary) : RGBA.fromInts(0, 0, 0, 0)}
backgroundColor={
active() ? (option.bg ?? theme.primary) : RGBA.fromInts(0, 0, 0, 0)
}
paddingLeft={1}
paddingRight={1}
gap={1}
@@ -218,7 +225,9 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
<Option
title={option.title}
footer={option.footer}
description={option.description !== category ? option.description : undefined}
description={
option.description !== category ? option.description : undefined
}
active={active()}
current={isDeepEqual(option.value, props.current)}
/>
@@ -234,7 +243,9 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
<For each={props.keybind ?? []}>
{(item) => (
<text>
<span style={{ fg: theme.text, attributes: TextAttributes.BOLD }}>{Keybind.toString(item.keybind)}</span>
<span style={{ fg: theme.text, attributes: TextAttributes.BOLD }}>
{Keybind.toString(item.keybind)}
</span>
<span style={{ fg: theme.textMuted }}> {item.title}</span>
</text>
)}
@@ -263,7 +274,10 @@ function Option(props: {
wrapMode="none"
>
{Locale.truncate(props.title, 62)}
<span style={{ fg: props.active ? theme.background : theme.textMuted }}> {props.description}</span>
<span style={{ fg: props.active ? theme.background : theme.textMuted }}>
{" "}
{props.description}
</span>
</text>
<Show when={props.footer}>
<box flexShrink={0}>