@tooee/layout 0.12.0 → 0.14.0
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/README.md +46 -0
- package/dist/app-layout.d.ts +3 -1
- package/dist/app-layout.d.ts.map +1 -1
- package/dist/app-layout.js +1 -3
- package/dist/app-layout.js.map +1 -1
- package/dist/app-layout.public-contract.typecheck.d.ts.map +1 -1
- package/dist/cell-text.d.ts +11 -0
- package/dist/cell-text.d.ts.map +1 -0
- package/dist/cell-text.js +55 -0
- package/dist/cell-text.js.map +1 -0
- package/dist/close-button.d.ts.map +1 -1
- package/dist/close-button.js.map +1 -1
- package/dist/fit-status-bar.d.ts +78 -0
- package/dist/fit-status-bar.d.ts.map +1 -0
- package/dist/fit-status-bar.js +182 -0
- package/dist/fit-status-bar.js.map +1 -0
- package/dist/fit-title-bar.d.ts +13 -0
- package/dist/fit-title-bar.d.ts.map +1 -0
- package/dist/fit-title-bar.js +20 -0
- package/dist/fit-title-bar.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/overlay-panel.d.ts.map +1 -1
- package/dist/overlay-panel.js.map +1 -1
- package/dist/react-content.d.ts.map +1 -1
- package/dist/react-content.js.map +1 -1
- package/dist/status-bar.d.ts +13 -8
- package/dist/status-bar.d.ts.map +1 -1
- package/dist/status-bar.js +30 -5
- package/dist/status-bar.js.map +1 -1
- package/dist/title-bar.d.ts +7 -1
- package/dist/title-bar.d.ts.map +1 -1
- package/dist/title-bar.js +17 -4
- package/dist/title-bar.js.map +1 -1
- package/package.json +6 -6
- package/src/app-layout.public-contract.typecheck.ts +6 -0
- package/src/app-layout.tsx +9 -5
- package/src/cell-text.ts +79 -0
- package/src/close-button.tsx +1 -0
- package/src/fit-status-bar.ts +307 -0
- package/src/fit-title-bar.ts +36 -0
- package/src/index.ts +34 -1
- package/src/overlay-panel.tsx +3 -0
- package/src/react-content.ts +2 -0
- package/src/status-bar.tsx +72 -15
- package/src/title-bar.tsx +28 -6
package/dist/status-bar.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-bar.d.ts","sourceRoot":"","sources":["../src/status-bar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"status-bar.d.ts","sourceRoot":"","sources":["../src/status-bar.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE3E,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IAChC,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC/B;AAoBD;;;GAGG;AACH,eAAO,MAAM,SAAS,oCAInB,cAAc,KAAG,SA+CnB,CAAC"}
|
package/dist/status-bar.js
CHANGED
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
|
+
import { useTerminalDimensions } from "@opentui/react";
|
|
2
3
|
import { useTheme } from "@tooee/themes";
|
|
3
|
-
|
|
4
|
+
import { fitStatusBar, STATUS_BAR_GAP } from "./fit-status-bar.js";
|
|
5
|
+
const PADDING_X = 1;
|
|
6
|
+
const StatusText = function StatusText({ item, first }) {
|
|
4
7
|
const { theme } = useTheme();
|
|
5
|
-
|
|
8
|
+
const gap = item.label !== "" && item.value !== "" ? " " : "";
|
|
9
|
+
return (_jsxs("text", { wrapMode: "none", style: { flexShrink: 0, marginLeft: first ? 0 : STATUS_BAR_GAP }, children: [_jsx("span", { fg: theme.textMuted, children: item.label }), gap, _jsx("span", { fg: theme.text, children: item.value })] }));
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* One-row status bar. Items that do not fit use their compact form, shorten,
|
|
13
|
+
* or hide, lowest priority first. The bar never wraps.
|
|
14
|
+
*/
|
|
15
|
+
export const StatusBar = function StatusBar({ items, width, hiddenMarker, }) {
|
|
16
|
+
const { theme } = useTheme();
|
|
17
|
+
const terminal = useTerminalDimensions();
|
|
18
|
+
const inner = Math.max(0, (width ?? terminal.width) - PADDING_X * 2);
|
|
19
|
+
const layout = fitStatusBar(items, inner, { hiddenMarker });
|
|
20
|
+
return (_jsxs("box", { style: {
|
|
6
21
|
backgroundColor: theme.backgroundPanel,
|
|
7
22
|
flexDirection: "row",
|
|
8
23
|
flexShrink: 0,
|
|
24
|
+
height: 1,
|
|
25
|
+
overflow: "hidden",
|
|
9
26
|
padding: 0,
|
|
10
|
-
paddingLeft:
|
|
11
|
-
paddingRight:
|
|
12
|
-
|
|
27
|
+
paddingLeft: PADDING_X,
|
|
28
|
+
paddingRight: PADDING_X,
|
|
29
|
+
width,
|
|
30
|
+
}, children: [layout.start.map((item, index) => (_jsx(StatusText, { item: item, first: index === 0 }, item.key))), layout.marker !== null && (_jsx("text", { wrapMode: "none", content: layout.marker, style: {
|
|
31
|
+
fg: theme.textMuted,
|
|
32
|
+
flexShrink: 0,
|
|
33
|
+
marginLeft: layout.start.length > 0 ? STATUS_BAR_GAP : 0,
|
|
34
|
+
} })), layout.end.length > 0 && (_jsx("box", { style: {
|
|
35
|
+
flexGrow: 1,
|
|
36
|
+
minWidth: layout.start.length > 0 || layout.marker !== null ? STATUS_BAR_GAP : 0,
|
|
37
|
+
} })), layout.end.map((item, index) => (_jsx(StatusText, { item: item, first: index === 0 }, item.key)))] }));
|
|
13
38
|
};
|
|
14
39
|
//# sourceMappingURL=status-bar.js.map
|
package/dist/status-bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-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EACA,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAa,EAAE,CAAC,CAC1C,KAAC,UAAU,IAAgB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,CAAC,IAAxC,IAAI,CAAC,GAAG,CAAoC,CAC9D,CAAC,IACE,CACP,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/title-bar.d.ts
CHANGED
|
@@ -2,7 +2,13 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
interface TitleBarProps {
|
|
3
3
|
title: string;
|
|
4
4
|
subtitle?: string;
|
|
5
|
+
/** Bar width in cells. Defaults to the terminal width. */
|
|
6
|
+
width?: number;
|
|
5
7
|
}
|
|
6
|
-
|
|
8
|
+
/**
|
|
9
|
+
* One-row title bar. When the bar is narrow, the subtitle shortens, then
|
|
10
|
+
* hides, then the title shortens. The bar never wraps.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TitleBar: ({ title, subtitle, width }: TitleBarProps) => ReactNode;
|
|
7
13
|
export {};
|
|
8
14
|
//# sourceMappingURL=title-bar.d.ts.map
|
package/dist/title-bar.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"title-bar.d.ts","sourceRoot":"","sources":["../src/title-bar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"title-bar.d.ts","sourceRoot":"","sources":["../src/title-bar.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvC,UAAU,aAAa;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,+BAAiD,aAAa,KAAG,SA8BrF,CAAC"}
|
package/dist/title-bar.js
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
|
+
import { useTerminalDimensions } from "@opentui/react";
|
|
2
3
|
import { useTheme } from "@tooee/themes";
|
|
3
|
-
|
|
4
|
+
import { fitTitleBar, TITLE_BAR_SEPARATOR } from "./fit-title-bar.js";
|
|
5
|
+
const PADDING_X = 1;
|
|
6
|
+
/**
|
|
7
|
+
* One-row title bar. When the bar is narrow, the subtitle shortens, then
|
|
8
|
+
* hides, then the title shortens. The bar never wraps.
|
|
9
|
+
*/
|
|
10
|
+
export const TitleBar = function TitleBar({ title, subtitle, width }) {
|
|
4
11
|
const { theme } = useTheme();
|
|
12
|
+
const terminal = useTerminalDimensions();
|
|
13
|
+
const inner = Math.max(0, (width ?? terminal.width) - PADDING_X * 2);
|
|
14
|
+
const fitted = fitTitleBar(title, subtitle, inner);
|
|
5
15
|
return (_jsxs("box", { style: {
|
|
6
16
|
backgroundColor: theme.backgroundPanel,
|
|
7
17
|
flexDirection: "row",
|
|
8
18
|
flexShrink: 0,
|
|
19
|
+
height: 1,
|
|
20
|
+
overflow: "hidden",
|
|
9
21
|
padding: 0,
|
|
10
|
-
paddingLeft:
|
|
11
|
-
paddingRight:
|
|
12
|
-
|
|
22
|
+
paddingLeft: PADDING_X,
|
|
23
|
+
paddingRight: PADDING_X,
|
|
24
|
+
width,
|
|
25
|
+
}, children: [_jsx("text", { wrapMode: "none", content: fitted.title, style: { fg: theme.primary, flexShrink: 0 } }), fitted.subtitle !== "" && (_jsx("text", { wrapMode: "none", content: `${TITLE_BAR_SEPARATOR}${fitted.subtitle}`, style: { fg: theme.textMuted, flexShrink: 0 } }))] }));
|
|
13
26
|
};
|
|
14
27
|
//# sourceMappingURL=title-bar.js.map
|
package/dist/title-bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"title-bar.js","sourceRoot":"","sources":["../src/title-bar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,E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OAAO,EAAE,GAAG,mBAAmB,GAAG,MAAM,CAAC,QAAQ,EAAE,EACnD,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,EAAE,GAC7C,CACH,IACG,CACP,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tooee/layout",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Standard app chrome (title bar, status bar) for Tooee",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"typecheck": "tsc --noEmit"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@tooee/commands": "0.
|
|
42
|
-
"@tooee/overlays": "0.
|
|
43
|
-
"@tooee/search": "0.
|
|
44
|
-
"@tooee/themes": "0.
|
|
45
|
-
"@tooee/toasts": "0.
|
|
41
|
+
"@tooee/commands": "0.14.0",
|
|
42
|
+
"@tooee/overlays": "0.14.0",
|
|
43
|
+
"@tooee/search": "0.14.0",
|
|
44
|
+
"@tooee/themes": "0.14.0",
|
|
45
|
+
"@tooee/toasts": "0.14.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@opentui/core": "^0.5.12",
|
|
@@ -2,13 +2,19 @@
|
|
|
2
2
|
import type { AppLayoutProps, AppLayoutScroll } from "./app-layout.js";
|
|
3
3
|
|
|
4
4
|
type Assert<T extends true> = T;
|
|
5
|
+
|
|
5
6
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
7
|
+
|
|
6
8
|
type Has<TKeys, TName> = [Extract<TKeys, TName>] extends [never] ? false : true;
|
|
7
9
|
|
|
8
10
|
type LayoutKeys = keyof AppLayoutProps;
|
|
11
|
+
|
|
9
12
|
type ScrollKeys = keyof AppLayoutScroll;
|
|
13
|
+
|
|
10
14
|
type RetainedScrollProp = Assert<Has<LayoutKeys, "scroll">>;
|
|
15
|
+
|
|
11
16
|
type RemovedScrollAliases = Assert<IsNever<Extract<LayoutKeys, "scrollProps" | "scrollRef">>>;
|
|
17
|
+
|
|
12
18
|
type NestedScrollOptions = Assert<
|
|
13
19
|
Has<ScrollKeys, "focused" | "ref" | "stickyScroll" | "stickyStart">
|
|
14
20
|
>;
|
package/src/app-layout.tsx
CHANGED
|
@@ -19,7 +19,11 @@ export interface AppLayoutScroll {
|
|
|
19
19
|
|
|
20
20
|
export interface AppLayoutProps {
|
|
21
21
|
titleBar?: { title: string; subtitle?: string };
|
|
22
|
-
statusBar: {
|
|
22
|
+
statusBar: {
|
|
23
|
+
items: readonly StatusBarItem[];
|
|
24
|
+
/** Glyph that shows when items hide. `false` turns it off. Default `"⋯"`. */
|
|
25
|
+
hiddenMarker?: string | false;
|
|
26
|
+
};
|
|
23
27
|
/** Configure the optional scrollbox used for the main content. */
|
|
24
28
|
scroll?: AppLayoutScroll;
|
|
25
29
|
searchBar?: SearchState;
|
|
@@ -52,12 +56,15 @@ export const AppLayout = function AppLayout({
|
|
|
52
56
|
}: AppLayoutProps): ReactNode {
|
|
53
57
|
const { theme } = useTheme();
|
|
54
58
|
const contextOverlay = useCurrentOverlay();
|
|
59
|
+
|
|
55
60
|
const handleSearchQueryChange = (query: string): void => {
|
|
56
61
|
searchBar?.setSearchQuery(query);
|
|
57
62
|
};
|
|
63
|
+
|
|
58
64
|
const handleSearchSubmit = (): void => {
|
|
59
65
|
searchBar?.submitSearch();
|
|
60
66
|
};
|
|
67
|
+
|
|
61
68
|
return (
|
|
62
69
|
<box flexDirection="column" width="100%" height="100%" backgroundColor={theme.background}>
|
|
63
70
|
{titleBar && <TitleBar title={titleBar.title} subtitle={titleBar.subtitle} />}
|
|
@@ -88,14 +95,11 @@ export const AppLayout = function AppLayout({
|
|
|
88
95
|
query={searchBar.searchQuery}
|
|
89
96
|
onQueryChange={handleSearchQueryChange}
|
|
90
97
|
onSubmit={handleSearchSubmit}
|
|
91
|
-
onCancel={() => {
|
|
92
|
-
searchBar.setSearchQuery("");
|
|
93
|
-
}}
|
|
94
98
|
matchCount={searchBar.matchingLines.length}
|
|
95
99
|
currentMatch={searchBar.currentMatchIndex}
|
|
96
100
|
/>
|
|
97
101
|
) : (
|
|
98
|
-
<StatusBar items={statusBar.items} />
|
|
102
|
+
<StatusBar items={statusBar.items} hiddenMarker={statusBar.hiddenMarker} />
|
|
99
103
|
)}
|
|
100
104
|
</box>
|
|
101
105
|
);
|
package/src/cell-text.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Cell-width text helpers shared by the title bar and the status bar. */
|
|
2
|
+
|
|
3
|
+
export type TruncateMode = "end" | "middle" | "start";
|
|
4
|
+
|
|
5
|
+
const ELLIPSIS = "…";
|
|
6
|
+
|
|
7
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
8
|
+
|
|
9
|
+
/** Terminal cell width of `text`. Wide characters count as two cells. */
|
|
10
|
+
export const cellWidth = function cellWidth(text: string): number {
|
|
11
|
+
return Bun.stringWidth(text);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const graphemes = function graphemes(text: string): string[] {
|
|
15
|
+
return Array.from(segmenter.segment(text), (part) => part.segment);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** The longest run of whole graphemes from the front of `parts` that fits in `max` cells. */
|
|
19
|
+
const takeCells = function takeCells(parts: readonly string[], max: number): string[] {
|
|
20
|
+
const taken: string[] = [];
|
|
21
|
+
let used = 0;
|
|
22
|
+
|
|
23
|
+
for (const part of parts) {
|
|
24
|
+
const width = cellWidth(part);
|
|
25
|
+
|
|
26
|
+
if (used + width > max) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
taken.push(part);
|
|
31
|
+
used += width;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return taken;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Shorten `text` to at most `max` cells. The ellipsis goes at the end, at the
|
|
39
|
+
* start, or in the middle. A wide character never splits, so the result can be
|
|
40
|
+
* one cell shorter than `max`.
|
|
41
|
+
*/
|
|
42
|
+
export const truncateCells = function truncateCells(
|
|
43
|
+
text: string,
|
|
44
|
+
max: number,
|
|
45
|
+
mode: TruncateMode = "end"
|
|
46
|
+
): string {
|
|
47
|
+
if (cellWidth(text) <= max) {
|
|
48
|
+
return text;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (max <= 0) {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (max === 1) {
|
|
56
|
+
return ELLIPSIS;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const parts = graphemes(text);
|
|
60
|
+
const room = max - 1;
|
|
61
|
+
|
|
62
|
+
if (mode === "end") {
|
|
63
|
+
return takeCells(parts, room).join("") + ELLIPSIS;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const reversed = parts.toReversed();
|
|
67
|
+
|
|
68
|
+
if (mode === "start") {
|
|
69
|
+
return ELLIPSIS + takeCells(reversed, room).toReversed().join("");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const head = takeCells(parts, Math.ceil(room / 2)).join("");
|
|
73
|
+
|
|
74
|
+
const tail = takeCells(reversed, room - cellWidth(head))
|
|
75
|
+
.toReversed()
|
|
76
|
+
.join("");
|
|
77
|
+
|
|
78
|
+
return head + ELLIPSIS + tail;
|
|
79
|
+
};
|
package/src/close-button.tsx
CHANGED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fit status bar items into a fixed cell width. The function is pure, so the
|
|
3
|
+
* same items and width always give the same bar.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { cellWidth, truncateCells } from "./cell-text.js";
|
|
7
|
+
import type { TruncateMode } from "./cell-text.js";
|
|
8
|
+
|
|
9
|
+
export type StatusBarTruncate = TruncateMode;
|
|
10
|
+
|
|
11
|
+
export type StatusBarAlign = "end" | "start";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Suggested priorities for status bar items. Higher values stay longer when
|
|
15
|
+
* the bar is narrow. Any number works; these names give apps a shared scale.
|
|
16
|
+
*/
|
|
17
|
+
export const StatusPriority = {
|
|
18
|
+
/** Background facts, such as the theme name. The default. */
|
|
19
|
+
background: 0,
|
|
20
|
+
/** Content facts, such as format or line count. */
|
|
21
|
+
content: 1,
|
|
22
|
+
/** Must always show, such as a session phase or an error state. */
|
|
23
|
+
critical: 4,
|
|
24
|
+
/** State the user acts on, such as a selection, a search query, or the current file. */
|
|
25
|
+
focus: 2,
|
|
26
|
+
/** Key hints. They go first. */
|
|
27
|
+
hint: -1,
|
|
28
|
+
/** Current mode and position. */
|
|
29
|
+
position: 3,
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
export interface StatusBarItem {
|
|
33
|
+
label: string;
|
|
34
|
+
value?: string;
|
|
35
|
+
/** Stable React key. Falls back to the position and label. */
|
|
36
|
+
id?: string;
|
|
37
|
+
/** Higher values stay longer. Default 0. See `StatusPriority`. */
|
|
38
|
+
priority?: number;
|
|
39
|
+
/** `"end"` items sit at the right edge. Default `"start"`. */
|
|
40
|
+
align?: StatusBarAlign;
|
|
41
|
+
/** Shorter form. The bar uses it before any item shortens or hides. */
|
|
42
|
+
compact?: { label?: string; value?: string };
|
|
43
|
+
/** The value can shorten with an ellipsis. Default: no truncation. */
|
|
44
|
+
truncate?: StatusBarTruncate;
|
|
45
|
+
/** Smallest value width in cells after truncation. Default 8. */
|
|
46
|
+
minValueWidth?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface PlacedStatusItem {
|
|
50
|
+
key: string;
|
|
51
|
+
label: string;
|
|
52
|
+
value: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface StatusBarLayout {
|
|
56
|
+
start: PlacedStatusItem[];
|
|
57
|
+
end: PlacedStatusItem[];
|
|
58
|
+
/** Number of items that did not fit. */
|
|
59
|
+
hidden: number;
|
|
60
|
+
/** The glyph to show after the start group, or null when no marker shows. */
|
|
61
|
+
marker: string | null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface FitStatusBarOptions {
|
|
65
|
+
/** Glyph that shows when items hide. `false` turns it off. Default `"⋯"`. */
|
|
66
|
+
hiddenMarker?: string | false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Cells between items, and the least space between the start and end groups. */
|
|
70
|
+
export const STATUS_BAR_GAP = 2;
|
|
71
|
+
|
|
72
|
+
/** Default glyph that shows when items hide. */
|
|
73
|
+
export const STATUS_BAR_HIDDEN_MARKER = "⋯";
|
|
74
|
+
|
|
75
|
+
const DEFAULT_MIN_VALUE_WIDTH = 8;
|
|
76
|
+
|
|
77
|
+
interface ItemState {
|
|
78
|
+
item: StatusBarItem;
|
|
79
|
+
index: number;
|
|
80
|
+
compact: boolean;
|
|
81
|
+
/** Value width cap after truncation, or null for the full value. */
|
|
82
|
+
valueCap: number | null;
|
|
83
|
+
visible: boolean;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface FitState {
|
|
87
|
+
items: ItemState[];
|
|
88
|
+
marker: string;
|
|
89
|
+
markerOn: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const alignOf = function alignOf(state: ItemState): StatusBarAlign {
|
|
93
|
+
return state.item.align ?? "start";
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const labelOf = function labelOf(state: ItemState): string {
|
|
97
|
+
return state.compact ? (state.item.compact?.label ?? state.item.label) : state.item.label;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const rawValueOf = function rawValueOf(state: ItemState): string {
|
|
101
|
+
const full = state.item.value ?? "";
|
|
102
|
+
|
|
103
|
+
return state.compact ? (state.item.compact?.value ?? full) : full;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const valueOf = function valueOf(state: ItemState): string {
|
|
107
|
+
const raw = rawValueOf(state);
|
|
108
|
+
|
|
109
|
+
if (state.valueCap === null) {
|
|
110
|
+
return raw;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return truncateCells(raw, state.valueCap, state.item.truncate);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** Cells between the label and the value: one space when both show. */
|
|
117
|
+
const labelGap = function labelGap(label: string, value: string): number {
|
|
118
|
+
return label !== "" && value !== "" ? 1 : 0;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const itemWidth = function itemWidth(state: ItemState): number {
|
|
122
|
+
const label = labelOf(state);
|
|
123
|
+
const value = valueOf(state);
|
|
124
|
+
|
|
125
|
+
return cellWidth(label) + labelGap(label, value) + cellWidth(value);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const groupWidth = function groupWidth(widths: readonly number[]): number {
|
|
129
|
+
const content = widths.reduce((sum, width) => sum + width, 0);
|
|
130
|
+
|
|
131
|
+
return content + Math.max(0, widths.length - 1) * STATUS_BAR_GAP;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const hiddenCount = function hiddenCount(fit: FitState): number {
|
|
135
|
+
return fit.items.filter((state) => !state.visible).length;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const showsMarker = function showsMarker(fit: FitState): boolean {
|
|
139
|
+
return fit.markerOn && fit.marker !== "" && hiddenCount(fit) > 0;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const barWidth = function barWidth(fit: FitState): number {
|
|
143
|
+
const visible = fit.items.filter((state) => state.visible);
|
|
144
|
+
const start = visible.filter((state) => alignOf(state) === "start").map(itemWidth);
|
|
145
|
+
const end = visible.filter((state) => alignOf(state) === "end").map(itemWidth);
|
|
146
|
+
|
|
147
|
+
if (showsMarker(fit)) {
|
|
148
|
+
start.push(cellWidth(fit.marker));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const between = start.length > 0 && end.length > 0 ? STATUS_BAR_GAP : 0;
|
|
152
|
+
|
|
153
|
+
return groupWidth(start) + between + groupWidth(end);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** Lowest priority first. On a tie, the item further right gives way first. */
|
|
157
|
+
const reductionOrder = function reductionOrder(items: readonly ItemState[]): ItemState[] {
|
|
158
|
+
return items.toSorted(
|
|
159
|
+
(a, b) => (a.item.priority ?? 0) - (b.item.priority ?? 0) || b.index - a.index
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const applyCompactForms = function applyCompactForms(
|
|
164
|
+
order: readonly ItemState[],
|
|
165
|
+
overflow: () => number
|
|
166
|
+
): void {
|
|
167
|
+
for (const state of order) {
|
|
168
|
+
if (overflow() <= 0) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (state.item.compact !== undefined) {
|
|
173
|
+
state.compact = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const shortenOrHide = function shortenOrHide(
|
|
179
|
+
fit: FitState,
|
|
180
|
+
order: readonly ItemState[],
|
|
181
|
+
overflow: () => number
|
|
182
|
+
): void {
|
|
183
|
+
for (const state of order) {
|
|
184
|
+
if (overflow() <= 0) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const raw = rawValueOf(state);
|
|
189
|
+
|
|
190
|
+
if (state.item.truncate !== undefined && raw !== "") {
|
|
191
|
+
const rawWidth = cellWidth(raw);
|
|
192
|
+
const min = Math.min(rawWidth, state.item.minValueWidth ?? DEFAULT_MIN_VALUE_WIDTH);
|
|
193
|
+
state.valueCap = Math.max(min, rawWidth - overflow());
|
|
194
|
+
|
|
195
|
+
if (overflow() <= 0) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const visibleCount = fit.items.filter((item) => item.visible).length;
|
|
201
|
+
|
|
202
|
+
if (visibleCount > 1) {
|
|
203
|
+
state.visible = false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/** Cells left for the value when the item has `room` cells. */
|
|
209
|
+
const valueRoom = function valueRoom(state: ItemState, room: number): number {
|
|
210
|
+
const label = labelOf(state);
|
|
211
|
+
|
|
212
|
+
return Math.max(0, room - cellWidth(label) - (label === "" ? 0 : 1));
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/** The last item never hides. Shorten its value, then drop the marker if needed. */
|
|
216
|
+
const squeezeLastItem = function squeezeLastItem(
|
|
217
|
+
fit: FitState,
|
|
218
|
+
width: number,
|
|
219
|
+
overflow: () => number
|
|
220
|
+
): void {
|
|
221
|
+
const last = fit.items.find((state) => state.visible);
|
|
222
|
+
|
|
223
|
+
if (last === undefined || overflow() <= 0) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const markerRoom = showsMarker(fit) ? cellWidth(fit.marker) + STATUS_BAR_GAP : 0;
|
|
228
|
+
|
|
229
|
+
last.valueCap = valueRoom(last, width - markerRoom);
|
|
230
|
+
|
|
231
|
+
if (overflow() > 0 && showsMarker(fit)) {
|
|
232
|
+
fit.markerOn = false;
|
|
233
|
+
last.valueCap = valueRoom(last, width);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/** Visible compact items try their full form again, highest priority first. */
|
|
238
|
+
const restoreFullForms = function restoreFullForms(
|
|
239
|
+
order: readonly ItemState[],
|
|
240
|
+
overflow: () => number
|
|
241
|
+
): void {
|
|
242
|
+
for (const state of order.toReversed()) {
|
|
243
|
+
if (state.visible && state.compact) {
|
|
244
|
+
state.compact = false;
|
|
245
|
+
|
|
246
|
+
if (overflow() > 0) {
|
|
247
|
+
state.compact = true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const place = function place(state: ItemState): PlacedStatusItem {
|
|
254
|
+
return {
|
|
255
|
+
key: state.item.id ?? `${state.index}:${state.item.label}`,
|
|
256
|
+
label: labelOf(state),
|
|
257
|
+
value: valueOf(state),
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Fit `items` into `width` cells:
|
|
263
|
+
*
|
|
264
|
+
* 1. Use full forms if every item fits.
|
|
265
|
+
* 2. Switch items to compact forms, lowest priority first.
|
|
266
|
+
* 3. Lowest priority first: shorten a truncatable value to its minimum, then hide the item.
|
|
267
|
+
* 4. Never hide the last item. Shorten its value if it still overflows.
|
|
268
|
+
* 5. Give full forms back to visible items, highest priority first, where they fit.
|
|
269
|
+
*
|
|
270
|
+
* When items hide, a marker glyph shows after the start group.
|
|
271
|
+
*/
|
|
272
|
+
export const fitStatusBar = function fitStatusBar(
|
|
273
|
+
items: readonly StatusBarItem[],
|
|
274
|
+
width: number,
|
|
275
|
+
options: FitStatusBarOptions = {}
|
|
276
|
+
): StatusBarLayout {
|
|
277
|
+
const fit: FitState = {
|
|
278
|
+
items: items.map((item, index) => ({
|
|
279
|
+
compact: false,
|
|
280
|
+
index,
|
|
281
|
+
item,
|
|
282
|
+
valueCap: null,
|
|
283
|
+
visible: true,
|
|
284
|
+
})),
|
|
285
|
+
marker:
|
|
286
|
+
options.hiddenMarker === false ? "" : (options.hiddenMarker ?? STATUS_BAR_HIDDEN_MARKER),
|
|
287
|
+
markerOn: true,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const order = reductionOrder(fit.items);
|
|
291
|
+
|
|
292
|
+
const overflow = (): number => barWidth(fit) - width;
|
|
293
|
+
|
|
294
|
+
applyCompactForms(order, overflow);
|
|
295
|
+
shortenOrHide(fit, order, overflow);
|
|
296
|
+
squeezeLastItem(fit, width, overflow);
|
|
297
|
+
restoreFullForms(order, overflow);
|
|
298
|
+
|
|
299
|
+
const visible = fit.items.filter((state) => state.visible);
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
end: visible.filter((state) => alignOf(state) === "end").map(place),
|
|
303
|
+
hidden: hiddenCount(fit),
|
|
304
|
+
marker: showsMarker(fit) ? fit.marker : null,
|
|
305
|
+
start: visible.filter((state) => alignOf(state) === "start").map(place),
|
|
306
|
+
};
|
|
307
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { cellWidth, truncateCells } from "./cell-text.js";
|
|
2
|
+
|
|
3
|
+
export interface TitleBarText {
|
|
4
|
+
title: string;
|
|
5
|
+
/** Empty when the subtitle does not show. */
|
|
6
|
+
subtitle: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Text between the title and the subtitle. */
|
|
10
|
+
export const TITLE_BAR_SEPARATOR = " — ";
|
|
11
|
+
|
|
12
|
+
const MIN_SUBTITLE_WIDTH = 8;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Fit a title and subtitle into `width` cells. The subtitle shortens first,
|
|
16
|
+
* down to 8 cells, then hides. Then the title shortens with an end ellipsis.
|
|
17
|
+
*/
|
|
18
|
+
export const fitTitleBar = function fitTitleBar(
|
|
19
|
+
title: string,
|
|
20
|
+
subtitle: string | undefined,
|
|
21
|
+
width: number
|
|
22
|
+
): TitleBarText {
|
|
23
|
+
const sub = subtitle ?? "";
|
|
24
|
+
|
|
25
|
+
if (sub === "") {
|
|
26
|
+
return { subtitle: "", title: truncateCells(title, width) };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const room = width - cellWidth(title) - cellWidth(TITLE_BAR_SEPARATOR);
|
|
30
|
+
|
|
31
|
+
if (room >= Math.min(cellWidth(sub), MIN_SUBTITLE_WIDTH)) {
|
|
32
|
+
return { subtitle: truncateCells(sub, room), title };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { subtitle: "", title: truncateCells(title, width) };
|
|
36
|
+
};
|