mirror of
https://github.com/HeyPuter/puter.git
synced 2025-12-30 09:40:00 -06:00
devex: update notices and better ANSI handling
This commit is contained in:
@@ -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 () {}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*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 = {
|
||||
|
||||
Reference in New Issue
Block a user