Skip to content

Commit 2dceadc

Browse files
authored
feat: add support for ANSI bold, dim, italic, underline and strike-through (#1001)
1 parent fcad2aa commit 2dceadc

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

src/main/frontend/pipeline-console-view/pipeline-console/main/Ansi.tsx

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export interface Result {
55
setBG?: number | false; // 0-7 if a background color is specified
66
resetFG?: boolean; // true if contains a reset back to default foreground
77
resetBG?: boolean; // true if contains a reset back to default background
8+
setBold?: boolean; // true if contains a bold font style
9+
setFaint?: boolean; // true if contains a faint font style
10+
setItalic?: boolean; // true if contains an italic font style
11+
setUnderline?: boolean; // true if contains an underline font style
12+
setStrikeThrough?: boolean; // true if contains a strike-through font style
813
}
914

1015
/**
@@ -20,6 +25,11 @@ export interface Result {
2025
* setBG: integer | false, // 0-7 if a background color is specified
2126
* resetFG: bool, // true if contains a reset back to default foreground
2227
* resetBG: bool // true if contains a reset back to default background
28+
* setBold: boolean, // true if contains a bold font style
29+
* setFaint: boolean; // true if contains a faint font style
30+
* setItalic: boolean; // true if contains an italic font style
31+
* setUnderline: boolean, // true if contains an underline font style
32+
* setStrikeThrough: boolean, // true if contains a strike-through font style
2333
* }
2434
*
2535
* // Unsupported or malformed code:
@@ -62,6 +72,25 @@ export function parseEscapeCode(escapeCode: string): Result {
6272
result.setFG = num - 90 + 8; // Bright FG set
6373
} else if (num >= 100 && num <= 107) {
6474
result.setBG = num - 100 + 8; // Bright BG set
75+
} else if (num === 1) {
76+
result.setBold = true;
77+
} else if (num === 2) {
78+
result.setFaint = true;
79+
} else if (num === 22) {
80+
result.setBold = false;
81+
result.setFaint = false;
82+
} else if (num === 3) {
83+
result.setItalic = true;
84+
} else if (num === 23) {
85+
result.setItalic = false;
86+
} else if (num === 4) {
87+
result.setUnderline = true;
88+
} else if (num === 24) {
89+
result.setUnderline = false;
90+
} else if (num === 9) {
91+
result.setStrikeThrough = true;
92+
} else if (num === 29) {
93+
result.setStrikeThrough = false;
6594
} else {
6695
if (num === 39 || num === 0) {
6796
result.resetFG = true;
@@ -190,13 +219,26 @@ export function makeReactChildren(
190219
let currentState: Result = {
191220
setFG: false,
192221
setBG: false,
222+
setBold: false,
223+
setFaint: false,
224+
setItalic: false,
225+
setUnderline: false,
226+
setStrikeThrough: false,
193227
};
194228

195229
for (let i = 0; i < tokenizedInput.length; i++) {
196230
const codeOrString = tokenizedInput[i];
197231
if (typeof codeOrString === "string") {
198232
// Need to output a <span> or plain text if there's no interesting current state
199-
if (!currentState.setFG && !currentState.setBG) {
233+
if (
234+
!currentState.setFG &&
235+
!currentState.setBG &&
236+
!currentState.setBold &&
237+
!currentState.setFaint &&
238+
!currentState.setItalic &&
239+
!currentState.setUnderline &&
240+
!currentState.setStrikeThrough
241+
) {
200242
result.push(
201243
<div
202244
dangerouslySetInnerHTML={{ __html: codeOrString }}
@@ -212,6 +254,21 @@ export function makeReactChildren(
212254
if (typeof currentState.setBG === "number") {
213255
classNames.push(`ansi-bg-${currentState.setBG}`);
214256
}
257+
if (currentState.setBold) {
258+
classNames.push("ansi-bold");
259+
}
260+
if (currentState.setFaint) {
261+
classNames.push("ansi-faint");
262+
}
263+
if (currentState.setItalic) {
264+
classNames.push("ansi-italic");
265+
}
266+
if (currentState.setUnderline) {
267+
classNames.push("ansi-underline");
268+
}
269+
if (currentState.setStrikeThrough) {
270+
classNames.push("ansi-strikethrough");
271+
}
215272

216273
result.push(
217274
<span className={classNames.join(" ")}>{codeOrString}</span>,
@@ -235,6 +292,26 @@ export function makeReactChildren(
235292
nextState.setBG = codeOrString.setBG;
236293
}
237294

295+
if (codeOrString.setBold !== undefined) {
296+
nextState.setBold = codeOrString.setBold;
297+
}
298+
299+
if (codeOrString.setFaint !== undefined) {
300+
nextState.setFaint = codeOrString.setFaint;
301+
}
302+
303+
if (codeOrString.setItalic !== undefined) {
304+
nextState.setItalic = codeOrString.setItalic;
305+
}
306+
307+
if (codeOrString.setUnderline !== undefined) {
308+
nextState.setUnderline = codeOrString.setUnderline;
309+
}
310+
311+
if (codeOrString.setStrikeThrough !== undefined) {
312+
nextState.setStrikeThrough = codeOrString.setStrikeThrough;
313+
}
314+
238315
currentState = nextState;
239316
}
240317
}

src/main/frontend/pipeline-console-view/pipeline-console/main/pipeline-console.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,30 @@
148148
background: var(--ansi-15);
149149
}
150150

151+
.ansi-bold {
152+
font-weight: bold;
153+
}
154+
155+
.ansi-faint {
156+
opacity: 0.5;
157+
}
158+
159+
.ansi-italic {
160+
font-style: italic;
161+
}
162+
163+
.ansi-underline {
164+
text-decoration-line: underline;
165+
}
166+
167+
.ansi-strikethrough {
168+
text-decoration-line: line-through;
169+
}
170+
171+
.ansi-underline.ansi-strikethrough {
172+
text-decoration-line: underline line-through;
173+
}
174+
151175
.pgv-sticky-sidebar {
152176
position: sticky;
153177
top: calc(var(--pgv-header-height) + var(--section-padding));

0 commit comments

Comments
 (0)