better LSing

stable
Valerie 2021-12-13 00:14:09 -05:00
parent c23d25f5db
commit 4a74b36961
2 changed files with 20 additions and 7 deletions

View File

@ -1,15 +1,20 @@
import { system, autoColorString } from '@kernel:base'; import { system, autoColorString, reverseAliasMap } from '@kernel:base';
import chalk from 'chalk'; import chalk from 'chalk';
export default function ls(flags: any) { export default function ls(flags: any) {
// if(flags) console.log(flags) // if(flags) console.log(flags)
console.log('Instances', chalk.ansi256(242)('(' + system.instances.size + ')')); console.log('Instances', chalk.ansi256(242)('(' + system.instances.size + ')'));
for(const [k, v] of system.instances) { const aliases = reverseAliasMap();
console.log( for(const [id, instance] of system.instances) {
' ' if(aliases.has(id)) {
+ autoColorString(k.substring(0, 4)) console.log(' ' + autoColorString(aliases.get(id)) + chalk.ansi256(242)(' (' + id + ')'));
+ ':', JSON.stringify(v.config, null, 2).replace('\n', '\n ').trim() } else {
); console.log(' ' + autoColorString(id.substring(0, 8)) + chalk.ansi256(242)(' (' + instance.module + ')'));
}
for(const [configKey, configVal] of Object.entries(instance.config)) {
console.log(' ' + chalk.ansi256(240)(configKey + ': ' + configVal));
}
} }
} }

View File

@ -28,6 +28,14 @@ export const system = {
aliases: new Map<string, string>() aliases: new Map<string, string>()
} }
export function reverseAliasMap() {
const map = new Map<string, string>();
for(const [u, v] of system.aliases.entries()) {
map.set(v, u)
}
return map;
}
function checkpoint(string: string) { function checkpoint(string: string) {
console.log(chalk.black.bgAnsi256(204)(' ' + string + ' ')); console.log(chalk.black.bgAnsi256(204)(' ' + string + ' '));
} }