makeColorCodesPrintable

This commit is contained in:
MeexReay 2025-03-21 23:00:36 +03:00
parent cdb49a2d54
commit d8425ab635
3 changed files with 8 additions and 6 deletions

View File

@ -20,7 +20,7 @@ async function cropToScreen(text, x, y, width, height) {
async function printScreen(screen_length, start_cursor, pos, content, mode, pos, x, y, width, height) {
trimTerminal(screen_length)
let screen = await cropToScreen(content, 0, 0, width, height - 1)
await writeStdout(screen)
await writeStdout(makeColorCodesPrintable(screen))
let status_line = `\nmode: ${mode} | size: ${content.length} | lines: ${content.split("\n").length} | x: ${pos[0]} | y: ${pos[1]}`
await writeStdout(status_line)
setCursor(start_cursor[0] + pos[0], start_cursor[1] + pos[1])
@ -113,12 +113,8 @@ async function main(args) {
} else if (event.type == "char") {
if (mode == "normal") {
if (event.char == ":") {
console.log(status_length)
trimTerminal(status_length)
console.log(getTerminal())
writeStdout(":")
setStdinFlag(RENDER_STDIN)

View File

@ -1,6 +1,6 @@
{
"name": "kfc",
"version": "0.1.0",
"version": "0.1.1",
"description": "Keep Files Customized",
"author": "MeexReay",
"apps": [ "kfc.js" ],

View File

@ -99,6 +99,12 @@ function stripColors(content) {
return convertColorCodes(content)
}
function makeColorCodesPrintable(input) {
return input.replace(/\$#([0-9a-fA-F]{6})/g, '$$##$1')
.replace(/\$([A-Z_]+)--/g, '$$#$1--')
.replace(/\$reset/g, '$$#reset');
}
function convertColorCodes(input) {
return input.replace(/\$#([0-9a-fA-F]{6})/g, '<span style="color: #$1">')
.replace(/\$##([0-9a-fA-F]{6})/g, '$#$1')