Skip to content

Commit 2cb845a

Browse files
committed
expose styles
1 parent c7671ce commit 2cb845a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

display/src/ansi.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ export const STYLES = [
7878
...BACKGROUND_COLOR_LIST,
7979
] as const
8080
export type Style = (typeof STYLES)[number]
81-
export const STYLE = {
81+
export const STYLE = Object.fromEntries(
82+
STYLES.map((style) => [style, style]),
83+
) as {
84+
[K in Style]: K
85+
}
86+
const STYLE_CODE = {
8287
RESET: 0,
8388
BOLD: 1,
8489
DIM: 2,
@@ -132,7 +137,7 @@ export function ansiCode(
132137
| { type: 'text' | 'background'; rgb: RGB },
133138
): string {
134139
if (data.type === 'style') {
135-
return `\x1b[${STYLE[data.style]}m`
140+
return `\x1b[${STYLE_CODE[data.style]}m`
136141
}
137142

138143
if (some(data.rgb, (v) => v > 255 || v < 0)) {

display/src/grapheme-image.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type Modifier,
1111
ansiCode,
1212
moveCursor,
13+
STYLE,
1314
} from './ansi'
1415

1516
export const BLANK_GRAPHEME = ' ' as $GraphemeString
@@ -108,7 +109,7 @@ function graphemeDiffCommands(
108109
}
109110

110111
return [
111-
...ansiCode({ type: 'style', style: 'RESET' }),
112+
...ansiCode({ type: 'style', style: STYLE.RESET }),
112113
...graphemeCommands(newGrapheme),
113114
]
114115
}
@@ -148,10 +149,8 @@ export function diffImageCommands(
148149
for (const [c, newGrapheme] of newRow.entries()) {
149150
const prevFrameGrapheme = oldRow[c]
150151
if (
151-
isEqual(
152-
{ textStyles: [], ...newGrapheme },
153-
{ textStyles: [], ...prevFrameGrapheme },
154-
)
152+
newGrapheme.grapheme === prevFrameGrapheme.grapheme &&
153+
equalStyles(newGrapheme, prevFrameGrapheme)
155154
) {
156155
skipped = true
157156
continue

0 commit comments

Comments
 (0)