@oh-my-pi/pi-tui 14.0.4 → 14.1.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/CHANGELOG.md +10 -0
- package/package.json +3 -3
- package/src/components/box.ts +8 -8
- package/src/components/markdown.ts +2 -3
- package/src/utils.ts +45 -15
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [14.0.5] - 2026-04-11
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Updated hash computation to use `Bun.hash()` instead of `Bun.hash.xxHash64()`, which may return `number` in addition to `bigint`
|
|
10
|
+
- Simplified cache key computation in Box component by removing intermediate hash updates and consolidating hash operations
|
|
11
|
+
- Wrapped native text utility functions (`sliceWithWidth`, `truncateToWidth`, `wrapTextWithAnsi`, `extractSegments`) to automatically pass the current default tab width, simplifying the API for consumers
|
|
12
|
+
- Added `getIndentationNoescape` wrapper that uses `process.cwd()` as the project root for relative file paths
|
|
13
|
+
- Re-export `getDefaultTabWidth`, `getIndentation`, and `setDefaultTabWidth` from `@oh-my-pi/pi-utils`; native text helpers still receive tab width via wrappers that read the JS default
|
|
14
|
+
|
|
5
15
|
## [13.16.1] - 2026-03-27
|
|
6
16
|
|
|
7
17
|
### Added
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/pi-tui",
|
|
4
|
-
"version": "14.0
|
|
4
|
+
"version": "14.1.0",
|
|
5
5
|
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
6
|
"homepage": "https://github.com/can1357/oh-my-pi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"fmt": "biome format --write ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@oh-my-pi/pi-natives": "14.0
|
|
41
|
-
"@oh-my-pi/pi-utils": "14.0
|
|
40
|
+
"@oh-my-pi/pi-natives": "14.1.0",
|
|
41
|
+
"@oh-my-pi/pi-utils": "14.1.0",
|
|
42
42
|
"marked": "^17.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
package/src/components/box.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Component } from "../tui";
|
|
|
2
2
|
import { applyBackgroundToLine, padding, visibleWidth } from "../utils";
|
|
3
3
|
|
|
4
4
|
type Cache = {
|
|
5
|
-
key: bigint;
|
|
5
|
+
key: bigint | number;
|
|
6
6
|
result: string[];
|
|
7
7
|
};
|
|
8
8
|
|
|
@@ -52,20 +52,20 @@ export class Box implements Component {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
static #tmp = new Uint32Array(2);
|
|
55
|
-
#computeCacheKey(width: number, childLines: string[], bgSample: string | undefined): bigint {
|
|
55
|
+
#computeCacheKey(width: number, childLines: string[], bgSample: string | undefined): bigint | number {
|
|
56
56
|
Box.#tmp[0] = width;
|
|
57
57
|
Box.#tmp[1] = childLines.length;
|
|
58
|
-
let h = Bun.hash
|
|
58
|
+
let h = Bun.hash(Box.#tmp);
|
|
59
59
|
for (const line of childLines) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
h = Bun.hash(line, h);
|
|
61
|
+
}
|
|
62
|
+
if (bgSample) {
|
|
63
|
+
h = Bun.hash(bgSample, h);
|
|
63
64
|
}
|
|
64
|
-
h = Bun.hash.xxHash64(bgSample ?? "", h);
|
|
65
65
|
return h;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
#matchCache(cacheKey: bigint): boolean {
|
|
68
|
+
#matchCache(cacheKey: bigint | number): boolean {
|
|
69
69
|
return this.#cached?.key === cacheKey;
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -45,10 +45,9 @@ export interface MarkdownTheme {
|
|
|
45
45
|
highlightCode?: (code: string, lang?: string) => string[];
|
|
46
46
|
/**
|
|
47
47
|
* Lookup a pre-rendered mermaid ASCII rendering by source hash.
|
|
48
|
-
* Hash is computed as `Bun.hash.xxHash64(source.trim())`.
|
|
49
48
|
* Return null to fall back to fenced code rendering.
|
|
50
49
|
*/
|
|
51
|
-
getMermaidAscii?: (sourceHash: bigint) => string | null;
|
|
50
|
+
getMermaidAscii?: (sourceHash: bigint | number) => string | null;
|
|
52
51
|
symbols: SymbolTheme;
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -325,7 +324,7 @@ export class Markdown implements Component {
|
|
|
325
324
|
case "code": {
|
|
326
325
|
// Handle mermaid diagrams with ASCII rendering when available
|
|
327
326
|
if (token.lang === "mermaid" && this.#theme.getMermaidAscii) {
|
|
328
|
-
const hash = Bun.hash
|
|
327
|
+
const hash = Bun.hash(token.text.trim());
|
|
329
328
|
const ascii = this.#theme.getMermaidAscii(hash);
|
|
330
329
|
|
|
331
330
|
if (ascii) {
|
package/src/utils.ts
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Ellipsis, ExtractSegmentsResult, SliceResult } from "@oh-my-pi/pi-natives";
|
|
2
|
+
import {
|
|
3
|
+
extractSegments as nativeExtractSegments,
|
|
4
|
+
sliceWithWidth as nativeSliceWithWidth,
|
|
5
|
+
truncateToWidth as nativeTruncateToWidth,
|
|
6
|
+
wrapTextWithAnsi as nativeWrapTextWithAnsi,
|
|
7
|
+
} from "@oh-my-pi/pi-natives";
|
|
8
|
+
import { getDefaultTabWidth, getIndentation } from "@oh-my-pi/pi-utils";
|
|
2
9
|
|
|
3
|
-
export { Ellipsis
|
|
10
|
+
export { Ellipsis } from "@oh-my-pi/pi-natives";
|
|
11
|
+
|
|
12
|
+
export { getDefaultTabWidth, getIndentation } from "@oh-my-pi/pi-utils";
|
|
13
|
+
|
|
14
|
+
export function sliceWithWidth(line: string, startCol: number, length: number, strict?: boolean | null): SliceResult {
|
|
15
|
+
return nativeSliceWithWidth(line, startCol, length, strict, getDefaultTabWidth());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function truncateToWidth(
|
|
19
|
+
text: string,
|
|
20
|
+
maxWidth: number,
|
|
21
|
+
ellipsisKind?: Ellipsis | null,
|
|
22
|
+
pad?: boolean | null,
|
|
23
|
+
): string {
|
|
24
|
+
return nativeTruncateToWidth(text, maxWidth, ellipsisKind, pad, getDefaultTabWidth());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function wrapTextWithAnsi(text: string, width: number): string[] {
|
|
28
|
+
return nativeWrapTextWithAnsi(text, width, getDefaultTabWidth());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function extractSegments(
|
|
32
|
+
line: string,
|
|
33
|
+
beforeEnd: number,
|
|
34
|
+
afterStart: number,
|
|
35
|
+
afterLen: number,
|
|
36
|
+
strictAfter: boolean,
|
|
37
|
+
): ExtractSegmentsResult {
|
|
38
|
+
return nativeExtractSegments(line, beforeEnd, afterStart, afterLen, strictAfter, getDefaultTabWidth());
|
|
39
|
+
}
|
|
4
40
|
|
|
5
41
|
// Pre-allocated space buffer for padding
|
|
6
42
|
const SPACE_BUFFER = " ".repeat(512);
|
|
7
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Tab width in columns for `file`, using `process.cwd()` as the project root for relative paths.
|
|
46
|
+
*/
|
|
47
|
+
export function getIndentationNoescape(file?: string): number {
|
|
48
|
+
return getIndentation(file, process.cwd());
|
|
49
|
+
}
|
|
50
|
+
|
|
8
51
|
/*
|
|
9
52
|
* Replace tabs with configured spacing for consistent rendering.
|
|
10
53
|
*/
|
|
@@ -31,19 +74,6 @@ export function getSegmenter(): Intl.Segmenter {
|
|
|
31
74
|
return segmenter;
|
|
32
75
|
}
|
|
33
76
|
|
|
34
|
-
/**
|
|
35
|
-
* Calculate the visible width of a string in terminal columns.
|
|
36
|
-
*/
|
|
37
|
-
function _isPrintableAscii(str: string): boolean {
|
|
38
|
-
for (let i = 0; i < str.length; i++) {
|
|
39
|
-
const code = str.charCodeAt(i);
|
|
40
|
-
if (code < 0x20 || code > 0x7e) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
77
|
export function visibleWidthRaw(str: string): number {
|
|
48
78
|
if (!str) {
|
|
49
79
|
return 0;
|