Skip to content

Commit 0f05b5d

Browse files
author
scinorandex
committed
Add function to remove garbage on web dashboard
1 parent a9eeb1b commit 0f05b5d

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

src/utils/libs/generateTable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import colors from "colors";
22
import { BoxArt, getBoxArt } from "./getBoxArt";
33

4-
const removeANSI: (str: string) => string = (str) => {
4+
export const removeANSI: (str: string) => string = (str) => {
55
while (str.includes("\x1B")) {
66
str = str.replace(/\u001b[^m]*?m/g, "");
77
}

src/utils/routes/dashboard/blessedConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const blessedConfig: {
5555
},
5656
bar: {
5757
position: [8, 0, 5, 5],
58-
barXOffset: 3,
58+
barXOffset: 1,
5959
},
6060
donut: {
6161
position: [8, 5, 5, 4],
@@ -79,7 +79,7 @@ export const blessedConfig: {
7979
},
8080
bar: {
8181
position: [4, 3, 5, 3],
82-
barXOffset: 6,
82+
barXOffset: 4,
8383
},
8484
donut: {
8585
position: [4, 6, 5, 3],
@@ -103,7 +103,7 @@ export const blessedConfig: {
103103
},
104104
bar: {
105105
position: [6, 3, 5, 3],
106-
barXOffset: 8,
106+
barXOffset: 5,
107107
},
108108
donut: {
109109
position: [6, 6, 5, 3],

src/utils/routes/dashboard/generateDashboardOutput.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import blessed from "blessed";
22
import contrib from "blessed-contrib";
3+
import { removeANSI } from "../../libs/generateTable";
34
import { welcomeMessage } from "../../libs/getResponses";
45
import { blessedConfig } from "./blessedConfig";
56
import { DashboardSize } from "./dashboardHandlers";
@@ -137,8 +138,8 @@ export const generateDashboardOutput: (
137138

138139
let bar = grid.set(barStartY, barStartX, barSpanY, barSpanX, contrib.bar, {
139140
label: "Information",
140-
barWidth: 8,
141-
barSpacing: 8,
141+
barWidth: 9,
142+
barSpacing: 9,
142143
xOffset: sizeConfig.bar.barXOffset,
143144
maxHeight: 9,
144145
});
@@ -197,8 +198,41 @@ export const generateDashboardOutput: (
197198

198199
// Take a screenshot
199200
const [screenshotX, screenshotY] = sizeConfig.screenshot;
200-
const response = screen.screenshot(0, screenshotX, 0, screenshotY);
201+
let response = screen.screenshot(0, screenshotX, 0, screenshotY);
201202
screen.destroy();
202203

204+
response = removeUnneededLines(response);
203205
return response;
204206
};
207+
208+
const removeUnneededLines: (str: string) => string = (str) => {
209+
// Split the input
210+
let splitLines = str.split("\n");
211+
212+
// Lines with ansi removed
213+
let rawLines = splitLines.map((line) => {
214+
// If line contains a background color code then replace it with NON ansi string
215+
// This is mostly to preserve bars since they are just whitespace
216+
if (line.includes("\x1B[4")) line.replace("\x1B[4", "_");
217+
return removeANSI(line);
218+
});
219+
220+
// This array represents the indexes of the lines in splitLines that are good and should be kept
221+
let goodLines: number[] = [];
222+
223+
rawLines.forEach((line, index) => {
224+
// remove border
225+
line = line.replace(//g, "");
226+
227+
// remove spaces
228+
line = line.replace(/\s/g, "");
229+
if (line.length !== 0) goodLines.push(index);
230+
});
231+
232+
let response: string[] = [];
233+
splitLines.forEach((line, index) => {
234+
if (goodLines.includes(index)) response.push(line);
235+
});
236+
237+
return response.join("\n");
238+
};

0 commit comments

Comments
 (0)