From 13a70f5394ab02e01192b1fccde88408c2d70e35 Mon Sep 17 00:00:00 2001 From: KernelDeimos <7225168+KernelDeimos@users.noreply.github.com> Date: Thu, 16 Oct 2025 12:54:19 -0400 Subject: [PATCH] devex: update notices and better ANSI handling --- .../src/services/NullDevConsoleService.js | 25 +++++++++++------ src/putility/src/libs/string.js | 28 +++++++++++++++++-- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/backend/src/services/NullDevConsoleService.js b/src/backend/src/services/NullDevConsoleService.js index f069ece7..6e449c0a 100644 --- a/src/backend/src/services/NullDevConsoleService.js +++ b/src/backend/src/services/NullDevConsoleService.js @@ -21,17 +21,15 @@ class NullDevConsoleService extends BaseService { }; // line length - let longest_lines_length = 0; + let longest = 0; for ( const line of lines ) { const this_lines_length = ansi_visible_length(line); - if ( this_lines_length > longest_lines_length ) { - longest_lines_length = this_lines_length; + if ( this_lines_length > longest ) { + longest = this_lines_length; } } - if ( title.length > longest_lines_length ) { - longest_lines_length = title.length; - } + const longestWithTitle = Math.max(longest, ansi_visible_length(title)); ({ highlighter: () => { @@ -40,8 +38,19 @@ class NullDevConsoleService extends BaseService { console.log(`\x1B[${colors.bginv}m▐▌\x1B[0m${line}\x1B[0m`); } }, + highlighter2: () => { + let top = ''; + for ( let i = title.length + 2; i < longest+3; i++ ) top += `\x1B[${colors.bginv}m▁\x1B[0m`; + console.log(`\x1B[${colors.bginv}m▐\x1B[0m\x1B[${colors.bg}m ${title}${top || ' '}\x1B[0m`); + for ( const line of lines ) { + const diff = line.length - ansi_visible_length(line); + console.log(`\x1B[${colors.bginv}m▐▌\x1B[0m${line.padEnd(longest + diff)}` + + `\x1B[${colors.bginv}m▐\x1B[0m`); + } + console.log(` \x1B[${colors.bginv}m${Array(longest + 2).fill('▔').join('')}\x1B[0m`); + }, stars: () => { - const len = longest_lines_length + 1; + const len = longestWithTitle + 1; const horiz = Array(len).fill('*').join(''); console.log(`\x1B[${colors.bginv}m**${horiz}**\x1B[0m`); console.log(`\x1B[${colors.bginv}m*\x1B[0m ${(title + ':').padEnd(len)} \x1B[${colors.bginv}m*\x1B[0m`); @@ -51,7 +60,7 @@ class NullDevConsoleService extends BaseService { } console.log(`\x1B[${colors.bginv}m**${horiz}**\x1B[0m`); }, - })[style ?? 'highlighter'](); + })[style ?? 'highlighter2'](); } turn_on_the_warning_lights () {} add_widget () {} diff --git a/src/putility/src/libs/string.js b/src/putility/src/libs/string.js index 1d60e9a0..3b2f1983 100644 --- a/src/putility/src/libs/string.js +++ b/src/putility/src/libs/string.js @@ -18,6 +18,8 @@ * along with this program. If not, see . */ +/*eslint no-control-regex: 'off'*/ + /** * Quotes a string value, handling special cases for undefined, null, functions, objects and numbers. * Escapes quotes and returns a JSON-stringified version with quote character normalization. @@ -101,8 +103,30 @@ const wrap_text = (text, width = 71) => { const ansi_visible_length = str => { // Regex that matches ANSI escape sequences - const ansiRegex = /\x1b\[[0-9;]*m/g; - return str.replace(ansiRegex, '').length; + const escape_regexes = [ + { + name: 'oscAll', + re: '/\x1B\][^\x07]*(?:\x07|\x1B\\)/g', + }, + { + name: 'osc8:start', + re: /\x1B\]8;[^\x07\x1B\\]*;[^\x07\x1B\\]*(?:\x07|\x1B\\)/g, + }, + { + name: 'osc8:end', + re: /\x1B\]8;;(?:\x07|\x1B\\)/g, + }, + { + name: 'csi', + re: /\x1B\[[0-?]*[ -/]*[@-~]/g, + }, + // /\x1b\[[0-9;]*m/g, + ]; + + /* eslint-disable */ + return escape_regexes.reduce( + (str, { re }) => str.replace(re, ''), str).length; + /* eslint-enable */ }; module.exports = {