Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add function to remove garbage on web dashboard
  • Loading branch information
scinorandex committed Apr 12, 2021
commit 0f05b5d6640e8844ac2749bb0494ff04df1cb899
2 changes: 1 addition & 1 deletion src/utils/libs/generateTable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import colors from "colors";
import { BoxArt, getBoxArt } from "./getBoxArt";

const removeANSI: (str: string) => string = (str) => {
export const removeANSI: (str: string) => string = (str) => {
while (str.includes("\x1B")) {
str = str.replace(/\u001b[^m]*?m/g, "");
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/routes/dashboard/blessedConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const blessedConfig: {
},
bar: {
position: [8, 0, 5, 5],
barXOffset: 3,
barXOffset: 1,
},
donut: {
position: [8, 5, 5, 4],
Expand All @@ -79,7 +79,7 @@ export const blessedConfig: {
},
bar: {
position: [4, 3, 5, 3],
barXOffset: 6,
barXOffset: 4,
},
donut: {
position: [4, 6, 5, 3],
Expand All @@ -103,7 +103,7 @@ export const blessedConfig: {
},
bar: {
position: [6, 3, 5, 3],
barXOffset: 8,
barXOffset: 5,
},
donut: {
position: [6, 6, 5, 3],
Expand Down
40 changes: 37 additions & 3 deletions src/utils/routes/dashboard/generateDashboardOutput.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import blessed from "blessed";
import contrib from "blessed-contrib";
import { removeANSI } from "../../libs/generateTable";
import { welcomeMessage } from "../../libs/getResponses";
import { blessedConfig } from "./blessedConfig";
import { DashboardSize } from "./dashboardHandlers";
Expand Down Expand Up @@ -137,8 +138,8 @@ export const generateDashboardOutput: (

let bar = grid.set(barStartY, barStartX, barSpanY, barSpanX, contrib.bar, {
label: "Information",
barWidth: 8,
barSpacing: 8,
barWidth: 9,
barSpacing: 9,
xOffset: sizeConfig.bar.barXOffset,
maxHeight: 9,
});
Expand Down Expand Up @@ -197,8 +198,41 @@ export const generateDashboardOutput: (

// Take a screenshot
const [screenshotX, screenshotY] = sizeConfig.screenshot;
const response = screen.screenshot(0, screenshotX, 0, screenshotY);
let response = screen.screenshot(0, screenshotX, 0, screenshotY);
screen.destroy();

response = removeUnneededLines(response);
return response;
};

const removeUnneededLines: (str: string) => string = (str) => {
// Split the input
let splitLines = str.split("\n");

// Lines with ansi removed
let rawLines = splitLines.map((line) => {
// If line contains a background color code then replace it with NON ansi string
// This is mostly to preserve bars since they are just whitespace
if (line.includes("\x1B[4")) line.replace("\x1B[4", "_");
return removeANSI(line);
});

// This array represents the indexes of the lines in splitLines that are good and should be kept
let goodLines: number[] = [];

rawLines.forEach((line, index) => {
// remove border
line = line.replace(/│/g, "");

// remove spaces
line = line.replace(/\s/g, "");
if (line.length !== 0) goodLines.push(index);
});

let response: string[] = [];
splitLines.forEach((line, index) => {
if (goodLines.includes(index)) response.push(line);
});

return response.join("\n");
};