|
1 | 1 | import blessed from "blessed"; |
2 | 2 | import contrib from "blessed-contrib"; |
| 3 | +import { removeANSI } from "../../libs/generateTable"; |
3 | 4 | import { welcomeMessage } from "../../libs/getResponses"; |
4 | 5 | import { blessedConfig } from "./blessedConfig"; |
5 | 6 | import { DashboardSize } from "./dashboardHandlers"; |
@@ -137,8 +138,8 @@ export const generateDashboardOutput: ( |
137 | 138 |
|
138 | 139 | let bar = grid.set(barStartY, barStartX, barSpanY, barSpanX, contrib.bar, { |
139 | 140 | label: "Information", |
140 | | - barWidth: 8, |
141 | | - barSpacing: 8, |
| 141 | + barWidth: 9, |
| 142 | + barSpacing: 9, |
142 | 143 | xOffset: sizeConfig.bar.barXOffset, |
143 | 144 | maxHeight: 9, |
144 | 145 | }); |
@@ -197,8 +198,41 @@ export const generateDashboardOutput: ( |
197 | 198 |
|
198 | 199 | // Take a screenshot |
199 | 200 | const [screenshotX, screenshotY] = sizeConfig.screenshot; |
200 | | - const response = screen.screenshot(0, screenshotX, 0, screenshotY); |
| 201 | + let response = screen.screenshot(0, screenshotX, 0, screenshotY); |
201 | 202 | screen.destroy(); |
202 | 203 |
|
| 204 | + response = removeUnneededLines(response); |
203 | 205 | return response; |
204 | 206 | }; |
| 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