-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(text-canvas): major update/rewrite, format support
- use Uint32Array as backing buffer - add support for arbitrary format IDs (highest 16bit) - add configurable string formatting - add ANSI & HTML format presets - add color & format constants - re-org source files
- Loading branch information
1 parent
0587a66
commit 57a7487
Showing
12 changed files
with
775 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { memoize1 } from "@thi.ng/memoize"; | ||
import { StringFormat } from "./api"; | ||
|
||
const ANSI_RESET = `\u001B[0m`; | ||
|
||
const ANSI_FLAGS = ["", "1", "2", "1;2", "4", "1;4", "2;4", "1;2;4"]; | ||
|
||
/** | ||
* String format preset, translating canvas format info to ANSI 4bit | ||
* control sequences. | ||
*/ | ||
export const FMT_ANSI16: StringFormat = { | ||
start: memoize1((x: number) => { | ||
let res = []; | ||
let y = x & 0xf; | ||
y && res.push(29 + ((x >> 4) & 1) * 60 + y); | ||
y = (x >> 5) & 0xf; | ||
y && res.push(39 + ((x >> 9) & 1) * 60 + y); | ||
y = x >> 10; | ||
y && res.push(ANSI_FLAGS[y]); | ||
return "\u001b[" + res.join(";") + "m"; | ||
}), | ||
end: ANSI_RESET, | ||
prefix: ANSI_RESET, | ||
suffix: "\n" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.