@opentui/core 0.0.0-20250930-6541ec7f → 0.0.0-20250930-d50102aa

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.
Files changed (42) hide show
  1. package/3d.js +5 -3
  2. package/3d.js.map +2 -2
  3. package/README.md +5 -1
  4. package/highlights-eq9cgrbb.scm +604 -0
  5. package/highlights-ghv9g403.scm +205 -0
  6. package/{index-kvwmgj67.js → index-0p8687g8.js} +1092 -105
  7. package/{index-kvwmgj67.js.map → index-0p8687g8.js.map} +19 -8
  8. package/index-cc14z67g.js +3846 -0
  9. package/index-cc14z67g.js.map +12 -0
  10. package/index.js +394 -240
  11. package/index.js.map +6 -4
  12. package/lib/data-paths.d.ts +26 -0
  13. package/lib/debounce.d.ts +42 -0
  14. package/lib/env.d.ts +2 -1
  15. package/lib/hast-styled-text.d.ts +3 -23
  16. package/lib/index.d.ts +4 -0
  17. package/lib/queue.d.ts +15 -0
  18. package/lib/singleton.d.ts +2 -0
  19. package/lib/styled-text.d.ts +0 -15
  20. package/lib/syntax-style.d.ts +36 -0
  21. package/lib/tree-sitter/assets/update.d.ts +11 -0
  22. package/lib/tree-sitter/client.d.ts +42 -0
  23. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  24. package/lib/tree-sitter/download-utils.d.ts +21 -0
  25. package/lib/tree-sitter/index.d.ts +10 -0
  26. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  27. package/lib/tree-sitter/resolve-ft.d.ts +2 -0
  28. package/lib/tree-sitter/types.d.ts +64 -0
  29. package/lib/tree-sitter-styled-text.d.ts +7 -0
  30. package/lib/validate-dir-name.d.ts +1 -0
  31. package/package.json +12 -7
  32. package/parser.worker.d.ts +1 -0
  33. package/parser.worker.js +5 -0
  34. package/parser.worker.js.map +9 -0
  35. package/renderables/Code.d.ts +31 -0
  36. package/renderables/Text.d.ts +10 -67
  37. package/renderables/TextBufferRenderable.d.ts +81 -0
  38. package/renderables/index.d.ts +2 -0
  39. package/testing.js +3 -2
  40. package/testing.js.map +2 -2
  41. package/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
  42. package/tree-sitter-typescript-zxjzwt75.wasm +0 -0
@@ -0,0 +1,26 @@
1
+ import { EventEmitter } from "events";
2
+ export interface DataPaths {
3
+ globalConfigPath: string;
4
+ globalConfigFile: string;
5
+ localConfigFile: string;
6
+ globalDataPath: string;
7
+ }
8
+ export interface DataPathsEvents {
9
+ "paths:changed": [paths: DataPaths];
10
+ }
11
+ export declare class DataPathsManager extends EventEmitter<DataPathsEvents> {
12
+ private _appName;
13
+ private _globalConfigPath?;
14
+ private _globalConfigFile?;
15
+ private _localConfigFile?;
16
+ private _globalDataPath?;
17
+ constructor();
18
+ get appName(): string;
19
+ set appName(value: string);
20
+ get globalConfigPath(): string;
21
+ get globalConfigFile(): string;
22
+ get localConfigFile(): string;
23
+ get globalDataPath(): string;
24
+ toObject(): DataPaths;
25
+ }
26
+ export declare function getDataPaths(): DataPathsManager;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Debounce controller that manages debounce instances for a specific scope
3
+ */
4
+ export declare class DebounceController {
5
+ private scopeId;
6
+ constructor(scopeId: string | number);
7
+ /**
8
+ * Debounces the provided function with the given ID
9
+ *
10
+ * @param id Unique identifier within this scope
11
+ * @param ms Milliseconds to wait before executing
12
+ * @param fn Function to execute
13
+ */
14
+ debounce<R>(id: string | number, ms: number, fn: () => Promise<R>): Promise<R>;
15
+ /**
16
+ * Clear a specific debounce timer in this scope
17
+ *
18
+ * @param id The debounce ID to clear
19
+ */
20
+ clearDebounce(id: string | number): void;
21
+ /**
22
+ * Clear all debounce timers in this scope
23
+ */
24
+ clear(): void;
25
+ }
26
+ /**
27
+ * Creates a new debounce controller for a specific scope
28
+ *
29
+ * @param scopeId Unique identifier for this debounce scope
30
+ * @returns A DebounceController for the specified scope
31
+ */
32
+ export declare function createDebounce(scopeId: string | number): DebounceController;
33
+ /**
34
+ * Clears all debounce timers for a specific scope
35
+ *
36
+ * @param scopeId The scope identifier
37
+ */
38
+ export declare function clearDebounceScope(scopeId: string | number): void;
39
+ /**
40
+ * Clears all active debounce timers across all scopes
41
+ */
42
+ export declare function clearAllDebounces(): void;
package/lib/env.d.ts CHANGED
@@ -36,6 +36,7 @@ export interface EnvVarConfig {
36
36
  }
37
37
  export declare const envRegistry: Record<string, EnvVarConfig>;
38
38
  export declare function registerEnvVar(config: EnvVarConfig): void;
39
+ export declare function clearEnvCache(): void;
39
40
  export declare function generateEnvMarkdown(): string;
40
41
  export declare function generateEnvColored(): string;
41
- export declare const env: Record<string, string | number | boolean>;
42
+ export declare const env: Record<string, any>;
@@ -1,5 +1,5 @@
1
- import { RGBA } from "./RGBA";
2
1
  import { StyledText } from "./styled-text";
2
+ import { SyntaxStyle } from "./syntax-style";
3
3
  export interface HASTText {
4
4
  type: "text";
5
5
  value: string;
@@ -13,26 +13,6 @@ export interface HASTElement {
13
13
  children: HASTNode[];
14
14
  }
15
15
  export type HASTNode = HASTText | HASTElement;
16
- export interface StyleDefinition {
17
- fg?: RGBA;
18
- bg?: RGBA;
19
- bold?: boolean;
20
- italic?: boolean;
21
- underline?: boolean;
22
- dim?: boolean;
23
- }
24
- interface MergedStyle {
25
- fg?: RGBA;
26
- bg?: RGBA;
27
- attributes: number;
28
- }
29
- export declare class SyntaxStyle {
30
- private styles;
31
- private mergedStyleCache;
32
- constructor(styles: Record<string, StyleDefinition>);
33
- mergeStyles(...styleNames: string[]): MergedStyle;
34
- clearCache(): void;
35
- getCacheSize(): number;
36
- }
16
+ export { SyntaxStyle } from "./syntax-style";
17
+ export type { StyleDefinition } from "./syntax-style";
37
18
  export declare function hastToStyledText(hast: HASTNode, syntaxStyle: SyntaxStyle): StyledText;
38
- export {};
package/lib/index.d.ts CHANGED
@@ -9,3 +9,7 @@ export * from "./yoga.options";
9
9
  export * from "./parse.mouse";
10
10
  export * from "./selection";
11
11
  export * from "./env";
12
+ export * from "./tree-sitter-styled-text";
13
+ export * from "./tree-sitter";
14
+ export * from "./syntax-style";
15
+ export * from "./data-paths";
package/lib/queue.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Generic processing queue that handles asynchronous job processing
3
+ */
4
+ export declare class ProcessQueue<T> {
5
+ private processor;
6
+ private queue;
7
+ private processing;
8
+ private autoProcess;
9
+ constructor(processor: (item: T) => Promise<void> | void, autoProcess?: boolean);
10
+ enqueue(item: T): void;
11
+ private processQueue;
12
+ clear(): void;
13
+ isProcessing(): boolean;
14
+ size(): number;
15
+ }
@@ -3,3 +3,5 @@
3
3
  * persists across Bun hot reloads, and is type-safe.
4
4
  */
5
5
  export declare function singleton<T>(key: string, factory: () => T): T;
6
+ export declare function destroySingleton(key: string): void;
7
+ export declare function hasSingleton(key: string): boolean;
@@ -1,4 +1,3 @@
1
- import type { TextRenderable } from "../renderables/Text";
2
1
  import type { TextChunk } from "../text-buffer";
3
2
  import { type ColorInput } from "./RGBA";
4
3
  declare const BrandedStyledText: unique symbol;
@@ -18,21 +17,7 @@ export declare function isStyledText(obj: any): obj is StyledText;
18
17
  export declare class StyledText {
19
18
  [BrandedStyledText]: boolean;
20
19
  chunks: TextChunk[];
21
- textRenderable?: TextRenderable;
22
20
  constructor(chunks: TextChunk[]);
23
- mount(textRenderable: TextRenderable): void;
24
- /**
25
- * @deprecated: Use textRenderable.insertChunk instead
26
- */
27
- insert(chunk: TextChunk, index?: number): StyledText;
28
- /**
29
- * @deprecated: Use textRenderable.removeChunk instead
30
- */
31
- remove(chunk: TextChunk): StyledText;
32
- /**
33
- * @deprecated: Use textRenderable.replaceChunk instead
34
- */
35
- replace(chunk: TextChunk, oldChunk: TextChunk): StyledText;
36
21
  }
37
22
  export declare function stringToStyledText(content: string): StyledText;
38
23
  export type StylableInput = string | number | boolean | TextChunk;
@@ -0,0 +1,36 @@
1
+ import { RGBA, type ColorInput } from "./RGBA";
2
+ export interface StyleDefinition {
3
+ fg?: RGBA;
4
+ bg?: RGBA;
5
+ bold?: boolean;
6
+ italic?: boolean;
7
+ underline?: boolean;
8
+ dim?: boolean;
9
+ }
10
+ export interface MergedStyle {
11
+ fg?: RGBA;
12
+ bg?: RGBA;
13
+ attributes: number;
14
+ }
15
+ export interface ThemeTokenStyle {
16
+ scope: string[];
17
+ style: {
18
+ foreground?: ColorInput;
19
+ background?: ColorInput;
20
+ bold?: boolean;
21
+ italic?: boolean;
22
+ underline?: boolean;
23
+ dim?: boolean;
24
+ };
25
+ }
26
+ export declare function convertThemeToStyles(theme: ThemeTokenStyle[]): Record<string, StyleDefinition>;
27
+ export declare class SyntaxStyle {
28
+ private styles;
29
+ private mergedStyleCache;
30
+ constructor(styles: Record<string, StyleDefinition>);
31
+ static fromTheme(theme: ThemeTokenStyle[]): SyntaxStyle;
32
+ mergeStyles(...styleNames: string[]): MergedStyle;
33
+ getStyle(name: string): StyleDefinition | undefined;
34
+ clearCache(): void;
35
+ getCacheSize(): number;
36
+ }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bun
2
+ export interface UpdateOptions {
3
+ /** Path to parsers-config.json */
4
+ configPath: string;
5
+ /** Directory where .wasm and .scm files will be downloaded */
6
+ assetsDir: string;
7
+ /** Path where the generated TypeScript file will be written */
8
+ outputPath: string;
9
+ }
10
+ declare function main(options?: Partial<UpdateOptions>): Promise<void>;
11
+ export { main as updateAssets };
@@ -0,0 +1,42 @@
1
+ import { EventEmitter } from "events";
2
+ import type { TreeSitterClientOptions, TreeSitterClientEvents, BufferState, FiletypeParserOptions, Edit, PerformanceStats, SimpleHighlight } from "./types";
3
+ export declare function addDefaultParsers(parsers: FiletypeParserOptions[]): void;
4
+ export declare class TreeSitterClient extends EventEmitter<TreeSitterClientEvents> {
5
+ private initialized;
6
+ private worker;
7
+ private buffers;
8
+ private initializePromise;
9
+ private initializeResolvers;
10
+ private messageCallbacks;
11
+ private messageIdCounter;
12
+ private editQueues;
13
+ private debouncer;
14
+ private options;
15
+ constructor(options: TreeSitterClientOptions);
16
+ private emitError;
17
+ private emitWarning;
18
+ private startWorker;
19
+ private stopWorker;
20
+ private handleReset;
21
+ initialize(): Promise<void>;
22
+ private registerDefaultParsers;
23
+ addFiletypeParser(filetypeParser: FiletypeParserOptions): void;
24
+ getPerformance(): Promise<PerformanceStats>;
25
+ highlightOnce(content: string, filetype: string): Promise<{
26
+ highlights?: SimpleHighlight[];
27
+ warning?: string;
28
+ error?: string;
29
+ }>;
30
+ private handleWorkerMessage;
31
+ preloadParser(filetype: string): Promise<boolean>;
32
+ createBuffer(id: number, content: string, filetype: string, version?: number, autoInitialize?: boolean): Promise<boolean>;
33
+ updateBuffer(id: number, edits: Edit[], newContent: string, version: number): Promise<void>;
34
+ private processEdit;
35
+ removeBuffer(bufferId: number): Promise<void>;
36
+ destroy(): Promise<void>;
37
+ resetBuffer(bufferId: number, version: number, content: string): Promise<void>;
38
+ getBuffer(bufferId: number): BufferState | undefined;
39
+ getAllBuffers(): BufferState[];
40
+ isInitialized(): boolean;
41
+ setDataPath(dataPath: string): Promise<void>;
42
+ }
@@ -0,0 +1,2 @@
1
+ import type { FiletypeParserOptions } from "./types";
2
+ export declare function getParsers(): FiletypeParserOptions[];
@@ -0,0 +1,21 @@
1
+ export interface DownloadResult {
2
+ content?: ArrayBuffer;
3
+ filePath?: string;
4
+ error?: string;
5
+ }
6
+ export declare class DownloadUtils {
7
+ private static hashUrl;
8
+ /**
9
+ * Download a file from URL or load from local path, with caching support
10
+ */
11
+ static downloadOrLoad(source: string, cacheDir: string, cacheSubdir: string, fileExtension: string, useHashForCache?: boolean, filetype?: string): Promise<DownloadResult>;
12
+ /**
13
+ * Download and save a file to a specific target path
14
+ */
15
+ static downloadToPath(source: string, targetPath: string): Promise<DownloadResult>;
16
+ /**
17
+ * Fetch multiple highlight queries and concatenate them
18
+ */
19
+ static fetchHighlightQueries(sources: string[], cacheDir: string, filetype: string): Promise<string>;
20
+ private static fetchHighlightQuery;
21
+ }
@@ -0,0 +1,10 @@
1
+ import { TreeSitterClient } from "./client";
2
+ export * from "./client";
3
+ export * from "../tree-sitter-styled-text";
4
+ export * from "../syntax-style";
5
+ export * from "./types";
6
+ export * from "../syntax-style";
7
+ export * from "./resolve-ft";
8
+ export type { UpdateOptions } from "./assets/update";
9
+ export { updateAssets } from "./assets/update";
10
+ export declare function getTreeSitterClient(): TreeSitterClient;
@@ -0,0 +1 @@
1
+ export default __filename;
@@ -0,0 +1,2 @@
1
+ export declare function extToFiletype(extension: string): string | undefined;
2
+ export declare function pathToFiletype(path: string): string | undefined;
@@ -0,0 +1,64 @@
1
+ export interface HighlightRange {
2
+ startCol: number;
3
+ endCol: number;
4
+ group: string;
5
+ }
6
+ export interface HighlightResponse {
7
+ line: number;
8
+ highlights: HighlightRange[];
9
+ droppedHighlights: HighlightRange[];
10
+ }
11
+ export type SimpleHighlight = [number, number, string];
12
+ export interface FiletypeParserOptions {
13
+ filetype: string;
14
+ queries: {
15
+ highlights: string[];
16
+ };
17
+ wasm: string;
18
+ }
19
+ export interface BufferState {
20
+ id: number;
21
+ version: number;
22
+ content: string;
23
+ filetype: string;
24
+ hasParser: boolean;
25
+ }
26
+ export interface ParsedBuffer extends BufferState {
27
+ hasParser: true;
28
+ }
29
+ export interface TreeSitterClientEvents {
30
+ "highlights:response": [bufferId: number, version: number, highlights: HighlightResponse[]];
31
+ "buffer:initialized": [bufferId: number, hasParser: boolean];
32
+ "buffer:disposed": [bufferId: number];
33
+ "worker:log": [logType: "log" | "error", message: string];
34
+ error: [error: string, bufferId?: number];
35
+ warning: [warning: string, bufferId?: number];
36
+ }
37
+ export interface TreeSitterClientOptions {
38
+ dataPath: string;
39
+ workerPath?: string | URL;
40
+ initTimeout?: number;
41
+ }
42
+ export interface Edit {
43
+ startIndex: number;
44
+ oldEndIndex: number;
45
+ newEndIndex: number;
46
+ startPosition: {
47
+ row: number;
48
+ column: number;
49
+ };
50
+ oldEndPosition: {
51
+ row: number;
52
+ column: number;
53
+ };
54
+ newEndPosition: {
55
+ row: number;
56
+ column: number;
57
+ };
58
+ }
59
+ export interface PerformanceStats {
60
+ averageParseTime: number;
61
+ parseTimes: number[];
62
+ averageQueryTime: number;
63
+ queryTimes: number[];
64
+ }
@@ -0,0 +1,7 @@
1
+ import type { TextChunk } from "../text-buffer";
2
+ import { StyledText } from "./styled-text";
3
+ import { SyntaxStyle } from "./syntax-style";
4
+ import { TreeSitterClient } from "./tree-sitter/client";
5
+ import type { SimpleHighlight } from "./tree-sitter/types";
6
+ export declare function treeSitterToTextChunks(content: string, highlights: SimpleHighlight[], syntaxStyle: SyntaxStyle): TextChunk[];
7
+ export declare function treeSitterToStyledText(content: string, filetype: string, syntaxStyle: SyntaxStyle, client: TreeSitterClient): Promise<StyledText>;
@@ -0,0 +1 @@
1
+ export declare function isValidDirectoryName(name: string): boolean;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
7
- "version": "0.0.0-20250930-6541ec7f",
7
+ "version": "0.0.0-20250930-d50102aa",
8
8
  "description": "OpenTUI is a TypeScript library for building terminal user interfaces (TUIs)",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -27,6 +27,11 @@
27
27
  "import": "./testing.js",
28
28
  "require": "./testing.js",
29
29
  "types": "./testing.d.ts"
30
+ },
31
+ "./parser.worker": {
32
+ "import": "./parser.worker.js",
33
+ "require": "./parser.worker.js",
34
+ "types": "./parser.worker.d.ts"
30
35
  }
31
36
  },
32
37
  "devDependencies": {
@@ -40,11 +45,11 @@
40
45
  "bun-webgpu": "0.1.3",
41
46
  "planck": "^1.4.2",
42
47
  "three": "0.177.0",
43
- "@opentui/core-darwin-x64": "0.0.0-20250930-6541ec7f",
44
- "@opentui/core-darwin-arm64": "0.0.0-20250930-6541ec7f",
45
- "@opentui/core-linux-x64": "0.0.0-20250930-6541ec7f",
46
- "@opentui/core-linux-arm64": "0.0.0-20250930-6541ec7f",
47
- "@opentui/core-win32-x64": "0.0.0-20250930-6541ec7f",
48
- "@opentui/core-win32-arm64": "0.0.0-20250930-6541ec7f"
48
+ "@opentui/core-darwin-x64": "0.0.0-20250930-d50102aa",
49
+ "@opentui/core-darwin-arm64": "0.0.0-20250930-d50102aa",
50
+ "@opentui/core-linux-x64": "0.0.0-20250930-d50102aa",
51
+ "@opentui/core-linux-arm64": "0.0.0-20250930-d50102aa",
52
+ "@opentui/core-win32-x64": "0.0.0-20250930-d50102aa",
53
+ "@opentui/core-win32-arm64": "0.0.0-20250930-d50102aa"
49
54
  }
50
55
  }
@@ -0,0 +1 @@
1
+ export * from "./lib/tree-sitter/parser.worker";
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ import"./index-cc14z67g.js";
3
+
4
+ //# debugId=5819917521D6E01464756E2164756E21
5
+ //# sourceMappingURL=parser.worker.js.map
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "5819917521D6E01464756E2164756E21",
8
+ "names": []
9
+ }
@@ -0,0 +1,31 @@
1
+ import { type RenderContext } from "../types";
2
+ import { SyntaxStyle } from "../lib/syntax-style";
3
+ import { TreeSitterClient } from "../lib/tree-sitter";
4
+ import { TextBufferRenderable, type TextBufferOptions } from "./TextBufferRenderable";
5
+ export interface CodeOptions extends TextBufferOptions {
6
+ content?: string;
7
+ filetype?: string;
8
+ syntaxStyle: SyntaxStyle;
9
+ treeSitterClient?: TreeSitterClient;
10
+ }
11
+ export declare class CodeRenderable extends TextBufferRenderable {
12
+ private _content;
13
+ private _filetype?;
14
+ private _syntaxStyle;
15
+ private _isHighlighting;
16
+ private _treeSitterClient;
17
+ private _pendingRehighlight;
18
+ protected _contentDefaultOptions: {
19
+ content: string;
20
+ };
21
+ constructor(ctx: RenderContext, options: CodeOptions);
22
+ get content(): string;
23
+ set content(value: string);
24
+ get filetype(): string | undefined;
25
+ set filetype(value: string);
26
+ get syntaxStyle(): SyntaxStyle;
27
+ set syntaxStyle(value: SyntaxStyle);
28
+ private updateContent;
29
+ private fallback;
30
+ private createFallbackStyledText;
31
+ }
@@ -1,96 +1,39 @@
1
- import { BaseRenderable, Renderable, type RenderableOptions } from "../Renderable";
2
- import { Selection } from "../lib/selection";
1
+ import { BaseRenderable } from "../Renderable";
3
2
  import { StyledText } from "../lib/styled-text";
4
3
  import { type TextChunk } from "../text-buffer";
5
4
  import { RGBA } from "../lib/RGBA";
6
5
  import { type RenderContext } from "../types";
7
- import type { OptimizedBuffer } from "../buffer";
8
6
  import { RootTextNodeRenderable, TextNodeRenderable } from "./TextNode";
9
- export interface TextOptions extends RenderableOptions<TextRenderable> {
7
+ import { TextBufferRenderable, type TextBufferOptions } from "./TextBufferRenderable";
8
+ export interface TextOptions extends TextBufferOptions {
10
9
  content?: StyledText | string;
11
- fg?: string | RGBA;
12
- bg?: string | RGBA;
13
- selectionBg?: string | RGBA;
14
- selectionFg?: string | RGBA;
15
- selectable?: boolean;
16
- attributes?: number;
17
- wrap?: boolean;
18
- wrapMode?: "char" | "word";
19
10
  }
20
- export declare class TextRenderable extends Renderable {
21
- selectable: boolean;
11
+ export declare class TextRenderable extends TextBufferRenderable {
22
12
  private _text;
23
13
  private _hasManualStyledText;
24
- private _defaultFg;
25
- private _defaultBg;
26
- private _defaultAttributes;
27
- private _selectionBg;
28
- private _selectionFg;
29
- private _wrap;
30
- private _wrapMode;
31
- private lastLocalSelection;
32
- private textBuffer;
33
- private _lineInfo;
34
14
  protected rootTextNode: RootTextNodeRenderable;
35
- protected _defaultOptions: {
15
+ protected _contentDefaultOptions: {
36
16
  content: string;
37
- fg: RGBA;
38
- bg: RGBA;
39
- selectionBg: undefined;
40
- selectionFg: undefined;
41
- selectable: true;
42
- attributes: number;
43
- wrap: true;
44
- wrapMode: "char" | "word";
45
17
  };
46
18
  constructor(ctx: RenderContext, options: TextOptions);
47
19
  private updateTextBuffer;
48
20
  private clearChunks;
49
21
  get content(): StyledText;
50
- get plainText(): string;
51
- get textLength(): number;
52
22
  get chunks(): TextChunk[];
53
23
  get textNode(): RootTextNodeRenderable;
54
24
  set content(value: StyledText | string);
55
- get fg(): RGBA;
56
- set fg(value: RGBA | string | undefined);
57
- get selectionBg(): RGBA | undefined;
58
- set selectionBg(value: RGBA | string | undefined);
59
- get selectionFg(): RGBA | undefined;
60
- set selectionFg(value: RGBA | string | undefined);
61
- get bg(): RGBA;
62
- set bg(value: RGBA | string | undefined);
63
- get attributes(): number;
64
- set attributes(value: number);
65
- get wrap(): boolean;
66
- set wrap(value: boolean);
67
- get wrapMode(): "char" | "word";
68
- set wrapMode(value: "char" | "word");
69
- protected onResize(width: number, height: number): void;
70
- private updateLocalSelection;
71
- private updateTextInfo;
72
- private updateLineInfo;
73
- private updateWrapWidth;
74
- private setupMeasureFunc;
75
25
  insertChunk(chunk: TextChunk, index?: number): void;
76
- removeChunk(chunk: TextChunk): void;
77
- replaceChunk(chunk: TextChunk, oldChunk: TextChunk): void;
26
+ removeChunkByObject(chunk: TextChunk): void;
27
+ replaceChunkByObject(chunk: TextChunk, oldChunk: TextChunk): void;
78
28
  private updateTextFromNodes;
79
29
  add(obj: TextNodeRenderable | StyledText | string, index?: number): number;
80
30
  remove(id: string): void;
81
31
  insertBefore(obj: BaseRenderable | any, anchor?: TextNodeRenderable): number;
82
32
  getTextChildren(): BaseRenderable[];
83
33
  clear(): void;
84
- shouldStartSelection(x: number, y: number): boolean;
85
- onSelectionChanged(selection: Selection | null): boolean;
86
- getSelectedText(): string;
87
- hasSelection(): boolean;
88
- getSelection(): {
89
- start: number;
90
- end: number;
91
- } | null;
92
34
  onLifecyclePass: () => void;
93
- render(buffer: OptimizedBuffer, deltaTime: number): void;
94
- protected renderSelf(buffer: OptimizedBuffer): void;
35
+ protected onFgChanged(newColor: RGBA): void;
36
+ protected onBgChanged(newColor: RGBA): void;
37
+ protected onAttributesChanged(newAttributes: number): void;
95
38
  destroy(): void;
96
39
  }
@@ -0,0 +1,81 @@
1
+ import { Renderable, type RenderableOptions } from "../Renderable";
2
+ import { Selection, type LocalSelectionBounds } from "../lib/selection";
3
+ import { TextBuffer, type TextChunk } from "../text-buffer";
4
+ import { RGBA } from "../lib/RGBA";
5
+ import { type RenderContext } from "../types";
6
+ import type { OptimizedBuffer } from "../buffer";
7
+ import type { LineInfo } from "../zig";
8
+ export interface TextBufferOptions extends RenderableOptions<TextBufferRenderable> {
9
+ fg?: string | RGBA;
10
+ bg?: string | RGBA;
11
+ selectionBg?: string | RGBA;
12
+ selectionFg?: string | RGBA;
13
+ selectable?: boolean;
14
+ attributes?: number;
15
+ wrap?: boolean;
16
+ wrapMode?: "char" | "word";
17
+ }
18
+ export declare abstract class TextBufferRenderable extends Renderable {
19
+ selectable: boolean;
20
+ protected _defaultFg: RGBA;
21
+ protected _defaultBg: RGBA;
22
+ protected _defaultAttributes: number;
23
+ protected _selectionBg: RGBA | undefined;
24
+ protected _selectionFg: RGBA | undefined;
25
+ protected _wrap: boolean;
26
+ protected _wrapMode: "char" | "word";
27
+ protected lastLocalSelection: LocalSelectionBounds | null;
28
+ protected textBuffer: TextBuffer;
29
+ protected _lineInfo: LineInfo;
30
+ protected _defaultOptions: {
31
+ fg: RGBA;
32
+ bg: RGBA;
33
+ selectionBg: undefined;
34
+ selectionFg: undefined;
35
+ selectable: true;
36
+ attributes: number;
37
+ wrap: true;
38
+ wrapMode: "char" | "word";
39
+ };
40
+ constructor(ctx: RenderContext, options: TextBufferOptions);
41
+ get plainText(): string;
42
+ get textLength(): number;
43
+ get fg(): RGBA;
44
+ set fg(value: RGBA | string | undefined);
45
+ get selectionBg(): RGBA | undefined;
46
+ set selectionBg(value: RGBA | string | undefined);
47
+ get selectionFg(): RGBA | undefined;
48
+ set selectionFg(value: RGBA | string | undefined);
49
+ get bg(): RGBA;
50
+ set bg(value: RGBA | string | undefined);
51
+ get attributes(): number;
52
+ set attributes(value: number);
53
+ get wrap(): boolean;
54
+ set wrap(value: boolean);
55
+ get wrapMode(): "char" | "word";
56
+ set wrapMode(value: "char" | "word");
57
+ protected onResize(width: number, height: number): void;
58
+ protected refreshLocalSelection(): boolean;
59
+ private updateLocalSelection;
60
+ protected updateTextInfo(): void;
61
+ private updateLineInfo;
62
+ private updateWrapWidth;
63
+ private setupMeasureFunc;
64
+ insertChunk(chunk: TextChunk, index?: number): void;
65
+ removeChunk(index: number): void;
66
+ replaceChunk(index: number, chunk: TextChunk): void;
67
+ shouldStartSelection(x: number, y: number): boolean;
68
+ onSelectionChanged(selection: Selection | null): boolean;
69
+ getSelectedText(): string;
70
+ hasSelection(): boolean;
71
+ getSelection(): {
72
+ start: number;
73
+ end: number;
74
+ } | null;
75
+ render(buffer: OptimizedBuffer, deltaTime: number): void;
76
+ protected renderSelf(buffer: OptimizedBuffer): void;
77
+ destroy(): void;
78
+ protected onFgChanged(newColor: RGBA): void;
79
+ protected onBgChanged(newColor: RGBA): void;
80
+ protected onAttributesChanged(newAttributes: number): void;
81
+ }