summaryrefslogtreecommitdiff
path: root/src/utils/ansi.ts
diff options
context:
space:
mode:
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 };
+};