summaryrefslogtreecommitdiff
path: root/src/utils/ansi.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-10-05 16:42:02 -0700
committerElizabeth Hunt <me@liz.coffee>2025-10-05 23:11:41 -0700
commitde43eb05d2e43ab31effce3dcca62ad91a556b26 (patch)
tree47a62b61bfc97dda639dea70627ecf3005ba7b02 /src/utils/ansi.ts
parent35add63ec4dce39710095f17abd86777de9e5b49 (diff)
downloadansicolor-de43eb05d2e43ab31effce3dcca62ad91a556b26.tar.gz
ansicolor-de43eb05d2e43ab31effce3dcca62ad91a556b26.zip
Diffstat (limited to 'src/utils/ansi.ts')
-rw-r--r--src/utils/ansi.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utils/ansi.ts b/src/utils/ansi.ts
index 551a365..e57c075 100644
--- a/src/utils/ansi.ts
+++ b/src/utils/ansi.ts
@@ -66,3 +66,15 @@ export const getStyleForAnsiColor = (color: AnsiTermColor): CSSProperties => {
color: foreground ? ansiRgbToHex(foreground) : undefined,
};
};
+
+export const parseAnsiColorCode = (code: number): AnsiRgb | null => {
+ // Only handle 216 color cube (16-231)
+ if (code < 16 || code > 231) return null;
+
+ const adjusted = code - 16;
+ const r = Math.floor(adjusted / 36) as AnsiColorVal;
+ const g = Math.floor((adjusted % 36) / 6) as AnsiColorVal;
+ const b = (adjusted % 6) as AnsiColorVal;
+
+ return { r, g, b };
+};