Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tui-change-list-scroll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@noormdev/cli": patch
---

TUI: the Changes screen scrolls. It drew every change at once, so a project with more changes than the terminal had rows squashed the list, hid the newest changes and pushed the status bar off screen; it now windows around the cursor with `↑ N more` / `↓ N more` lines, keeps its detail box to three lines, and drops the box on a terminal too short to hold it. Every terminal-sized list (select lists, searchable lists, the file picker) now counts its scroll-indicator lines in its row budget instead of drawing one or two rows past it.
2 changes: 1 addition & 1 deletion .claude/rules/tui-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ It is **on** unless `ui.mouse` is false in `.noorm/settings.yml`. Off means iner
| API | What it covers |
|-----|----------------|
| `usePaste` | Bracketed paste delivered as a single string. `SqlInput` currently submits only the first line of a multi-line paste. |
| `useBoxMetrics` | Used for the height of `Form`'s status error and the width `TextInput` scrolls within. Still unused for measured box width/height/left/top instead of the hand-counted chrome constants at `SqlTerminalScreen.tsx:57` and `ConfigEditScreen.tsx:268`. |
| `useBoxMetrics` | Used for the height of `Form`'s status error, the width `TextInput` scrolls within, and the rows `ChangeListScreen`'s hint row wraps to. Still unused for measured box width/height/left/top instead of the hand-counted chrome constants at `SqlTerminalScreen.tsx:57` and `ConfigEditScreen.tsx:268`. |
| `useAnimation`, `suspendTerminal()`, `interactive` | No current need. |

`<Text>` no longer accepts `wrap="end"` or `wrap="middle"`. Both were undocumented no-ops on 6.8.0 and were dropped from the type in 7.0.0. This codebase uses `wrap="wrap"`, `wrap="truncate"`, and `wrap="truncate-start"` (`FilePicker` paths, where the end is what identifies a file), so nothing changed.
Expand Down
Binary file modified docs/public/image/tui/changes-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/tui/components/dialogs/FilePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type { ReactElement } from 'react';

import { useFocusScope } from '../../focus.js';
import { hoverBackground, useRowMouse } from '../../mouse.js';
import { useViewportRows } from '../../hooks/useViewportRows.js';
import { rowsThatFit, useViewportRows } from '../../hooks/useViewportRows.js';
import { Panel } from '../layout/Panel.js';
import { Hotkey } from '../layout/Hotkey.js';

Expand Down Expand Up @@ -116,7 +116,6 @@ export function FilePicker({
}: FilePickerProps): ReactElement {

const availableRows = useViewportRows(PICKER_CHROME_ROWS + reserveRows);
const visibleCount = pinnedVisibleCount ?? availableRows;

const { isFocused } = useFocusScope(focusLabel);

Expand All @@ -129,6 +128,7 @@ export function FilePicker({

// Filtered files based on search
const filteredFiles = useMemo(() => filterFiles(files, search), [files, search]);
const visibleCount = pinnedVisibleCount ?? rowsThatFit(filteredFiles.length, availableRows);

// Visible files window
const visibleFiles = useMemo(
Expand Down
9 changes: 2 additions & 7 deletions src/tui/components/lists/SearchableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { TextInput } from '../forms/TextInput.js';
import type { ReactElement } from 'react';

import { useFocusScope } from '../../focus.js';
import { useViewportRows } from '../../hooks/useViewportRows.js';
import { SelectList } from './SelectList.js';
import { Hotkey, KeyTarget } from '../layout/Hotkey.js';

Expand Down Expand Up @@ -130,11 +129,6 @@ export function SearchableList<T = unknown>({
renderItem,
}: SearchableListProps<T>): ReactElement {

// The wrapped SelectList is handed a resolved number, so it never
// double-counts this component's search and hint rows.
const availableRows = useViewportRows(SEARCH_CHROME_ROWS + reserveRows);
const visibleCount = pinnedVisibleCount ?? availableRows;

// Focus management
const hasExternalFocus = externalFocused !== undefined;
const internalFocus = useFocusScope({
Expand Down Expand Up @@ -346,7 +340,8 @@ export function SearchableList<T = unknown>({
items={filteredItems}
onSelect={onSelect}
onHighlight={handleHighlightChange}
visibleCount={visibleCount}
visibleCount={pinnedVisibleCount}
reserveRows={SEARCH_CHROME_ROWS + reserveRows}
isFocused={isFocused && !searchMode}
numberNav={numberNav}
defaultValue={currentHighlightedKey}
Expand Down
7 changes: 5 additions & 2 deletions src/tui/components/lists/SelectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useFocusScope } from '../../focus.js';
import { hoverBackground, useRowMouse } from '../../mouse.js';
import { useOptionalRouter } from '../../router.js';
import { listMemoryKey, recallListPosition, rememberListPosition } from '../../list-memory.js';
import { useViewportRows } from '../../hooks/useViewportRows.js';
import { rowsThatFit, useViewportRows } from '../../hooks/useViewportRows.js';

/**
* Item in a SelectList.
Expand Down Expand Up @@ -176,7 +176,6 @@ export function SelectList<T = unknown>({
// under-fills a mixed list rather than running it off the bottom.
const availableRows = useViewportRows(reserveRows);
const rowsPerItem = showDescriptionBelow ? 2 : 1;
const visibleCount = pinnedVisibleCount ?? Math.max(1, Math.floor(availableRows / rowsPerItem));

// Use external focus if provided, otherwise manage own focus scope
const hasExternalFocus = externalFocused !== undefined;
Expand All @@ -189,6 +188,10 @@ export function SelectList<T = unknown>({
// Filter enabled items
const enabledItems = useMemo(() => items.filter((item) => !item.disabled), [items]);

// A pinned count is an item count by contract, so the indicators stay on top of it.
const itemRows = rowsThatFit(enabledItems.length * rowsPerItem, availableRows);
const visibleCount = pinnedVisibleCount ?? Math.max(1, Math.floor(itemRows / rowsPerItem));

// Refs for latest values - useInput handler reads these to avoid stale closures
const enabledItemsRef = useRef(enabledItems);
const onSelectRef = useRef(onSelect);
Expand Down
12 changes: 3 additions & 9 deletions src/tui/components/terminal/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@
*/
import type { Key } from 'ink';

import { SCROLL_INDICATOR_ROWS } from '../../hooks/useViewportRows.js';

/** Columns a Panel spends on its border and horizontal padding. */
const PANEL_CHROME_COLUMNS = 4;

/** Narrowest row worth planning for. Below it the terminal is unusable anyway. */
const MIN_ROW_COLUMNS = 24;

/**
* Rows the two scroll indicators claim once the content overflows.
*
* Held back as a pair rather than per-indicator so the viewport keeps one
* height for the whole scroll, instead of growing a row at each end.
*/
const INDICATOR_ROWS = 2;

/**
* Columns a row inside a Panel actually gets.
*
Expand Down Expand Up @@ -83,7 +77,7 @@ export function rowWindow(total: number, offset: number, budget: number): RowWin

}

const count = Math.max(1, budget - INDICATOR_ROWS);
const count = Math.max(1, budget - SCROLL_INDICATOR_ROWS);
const start = Math.min(Math.max(offset, 0), total - count);

return { start, count, above: start, below: total - start - count };
Expand Down
36 changes: 35 additions & 1 deletion src/tui/hooks/useViewportRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,37 @@ export function viewportRows(terminalRows: number, reserveRows = 0): number {

}

/**
* Rows the `↑ N more` and `↓ N more` lines claim once a list overflows.
*
* Held back as a pair rather than per indicator, so the list keeps one height
* for the whole scroll instead of growing a row at each end.
*/
export const SCROLL_INDICATOR_ROWS = 2;

/**
* Rows a list's items may take once its scroll indicators are paid for, or its
* indicators push the screen's footer off the bottom. Below
* `MIN_VIEWPORT_ROWS + SCROLL_INDICATOR_ROWS` the indicators overflow instead
* of shrinking the list under the floor.
*
* @example
* rowsThatFit(4, 20); // 20 — fits, no indicators
* rowsThatFit(60, 20); // 18 — two rows go to the indicators
* rowsThatFit(60, 5); // 5 — the floor
*/
export function rowsThatFit(itemRows: number, budget: number): number {

if (itemRows <= budget) {

return budget;

}

return Math.max(budget - SCROLL_INDICATOR_ROWS, MIN_VIEWPORT_ROWS);

}

/**
* Rows the calling component may draw, recomputed whenever the terminal resizes.
*
Expand All @@ -83,9 +114,12 @@ export function viewportRows(terminalRows: number, reserveRows = 0): number {
* size. Call it above any early return, or the hook count changes across an
* async load boundary.
*
* Pass a list's chrome as `reserveRows` rather than pinning this as its
* `visibleCount`: a pinned count is an item count, so the list's scroll
* indicators would be drawn on top of the budget.
*
* @example
* const rows = useViewportRows(bannerRows);
* <SelectList items={items} visibleCount={rows} />
*/
export function useViewportRows(reserveRows = 0): number {

Expand Down
Loading
Loading