[READ-ONLY] Mirror of https://github.com/CanadaHonk/porffor. An ahead-of-time JavaScript compiler porffor.dev
10

Configure Feed

Select the types of activity you want to include in your feed.

byg: general clean up

CanadaHonk (May 14, 2024, 11:38 AM +0100) 6bc63ef7 36c4e1b5

+3 -24
+3 -24
byg/index.js
··· 2 2 3 3 const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, ''); 4 4 const printLine = (line, number, breakpoint = false, current = false, selected = false) => { 5 - // console.log(`\x1b[${breakpoint ? (selected ? '106' : '46') : (selected ? '47' : '100')}m\x1b[${selected ? '30' : '97'}m${number.toFixed(0).padStart(4, ' ')}\x1b[${breakpoint ? (selected ? '96' : '36') : (selected ? '37' : '90')}m\x1b[${current ? '47' : '40'}m▌ \x1b[${current ? '47' : '40'}m\x1b[${current ? '30' : '37'}m${current ? noAnsi(line) : line}\x1b[0K`); 6 5 console.log(`\x1b[${breakpoint ? (selected ? '43' : '103') : (selected ? '47' : '100')}m\x1b[${selected || breakpoint ? '30' : '97'}m${number.toFixed(0).padStart(4, ' ')}\x1b[${breakpoint ? (selected ? '33' : '93') : (selected ? '37' : '90')}m\x1b[${current ? '47' : '40'}m▌ \x1b[${current ? '47' : '40'}m\x1b[${current ? '30' : '37'}m${current ? noAnsi(line) : line}\x1b[0K`); 7 6 }; 8 7 ··· 13 12 14 13 // top 15 14 process.stdout.write(`\x1b[48m\x1b[${y + 1};${x + 1}H\x1b[${color[0]}m` + '▄'.repeat(width)); 16 - 17 15 // bottom 18 16 process.stdout.write(`\x1b[${y + height + 1};${x + 1}H▝` + '▀'.repeat(width - 1) + '▘'); 19 - 20 17 // left 21 18 process.stdout.write(`\x1b[${y + 1};${x + 1}H▗` + '\x1b[1B\x1b[1D▐'.repeat(height - 1)); 22 - 23 19 // right 24 20 process.stdout.write(`\x1b[${y + 1};${x + width + 1}H▖` + '\x1b[1B\x1b[1D▌'.repeat(height - 1)); 25 21 ··· 33 29 process.stdout.write(`\x1b[${y + 1};${x + 1}H\x1b[${color[1]}m` + ' '.repeat(width) + (`\x1b[1B\x1b[${width}D` + ' '.repeat(width)).repeat(Math.max(0, height - 1))); 34 30 35 31 // title 36 - // if (title) process.stdout.write(`\x1b[${y + 1};${x + ((width - title.length) / 2 | 0) + 1}H\x1b[${color[1]}m\x1b[${color[2]}m\x1b[1m${title}\x1b[22m`); 37 - // if (title) process.stdout.write(`\x1b[${y};${x}H\x1b[${color[3]}▗\x1b[${color[4]}m\x1b[${color[2]}m\x1b[1m${' '.repeat((width - title.length) / 2 | 0)}${title}${' '.repeat(width - (((width - title.length) / 2 | 0)) - title.length)}\x1b[0m\x1b[${color[4]}m▖`); 38 32 if (title) process.stdout.write(`\x1b[${y};${x}H\x1b[0m\x1b[${color[3]}m▐\x1b[${color[4]}m\x1b[${color[2]}m\x1b[1m${' '.repeat((width - title.length) / 2 | 0)}${title}${' '.repeat(width - (((width - title.length) / 2 | 0)) - title.length)}\x1b[0m\x1b[${color[3]}m▌`); 39 33 40 34 // content ··· 66 60 process.exit(); 67 61 } 68 62 69 - // process.stdout.write(s); 70 - 71 63 if (!paused) pause(); 72 64 }); 73 65 ··· 83 75 84 76 process.on('exit', () => { 85 77 process.stdout.write('\x1b[0m'); 86 - // console.clear(); 87 78 }); 88 79 89 80 console.clear(); ··· 130 121 131 122 for (const x of boxes) { 132 123 const y = x.y({ currentLinePos }); 133 - const height = x.height; 134 124 if (y < 0 || y >= termHeight) continue; 135 125 136 - // crop box if > termHeight 137 - // if (y + height >= termHeight) { 138 - // const excess = y + height - termHeight; 139 - // height -= excess; 140 - 141 - // content = content.slice(0, height - 2); 142 - // } 143 - 144 - box(x.x, y, x.width, height, x.title, x.content); 126 + box(x.x, y, x.width, x.height, x.title, x.content); 145 127 } 146 128 147 129 // text += ` | rss: ${(process.memoryUsage.rss() / 1024 / 1024).toFixed(2)}mb`; ··· 179 161 } 180 162 181 163 case 'b': { 182 - if (!lastSpecial) { // b pressed normally 164 + if (!lastSpecial) { 165 + // b pressed normally 183 166 breakpoints[currentLine + scrollOffset] = !breakpoints[currentLine + scrollOffset]; 184 167 draw(); 185 168 ··· 188 171 } 189 172 190 173 // arrow down 191 - // if (screenOffset + termHeight <= lines.length) scrollOffset++; 192 174 if (scrollOffset < lines.length - currentLine - 1) scrollOffset++; 193 175 draw(); 194 176 break; ··· 198 180 if (!lastSpecial) break; 199 181 200 182 // arrow up 201 - // if (screenOffset > 0) scrollOffset--; 202 183 if (scrollOffset > -currentLine) scrollOffset--; 203 184 draw(); 204 185 ··· 209 190 if (!lastSpecial) break; 210 191 211 192 // page up 212 - // scrollOffset -= Math.min(screenOffset, termHeight - 1); 213 193 scrollOffset -= Math.min(scrollOffset + currentLine, termHeight - 1); 214 194 draw(); 215 195 break; ··· 219 199 if (!lastSpecial) break; 220 200 221 201 // page down 222 - // scrollOffset += Math.min((lines.length + 1) - (screenOffset + termHeight), termHeight - 1); 223 202 scrollOffset += Math.min(lines.length - (scrollOffset + currentLine) - 1, termHeight - 1); 224 203 draw(); 225 204 break;