import * as plugins from '../../../plugins.js'; import { tspmIpcClient } from '../../../classes.ipcclient.js'; import type { CliArguments } from '../../types.js'; import { registerIpcCommand } from '../../registration/index.js'; import { pad } from '../../helpers/formatting.js'; import { formatMemory } from '../../helpers/memory.js'; export function registerListCommand(smartcli: plugins.smartcli.Smartcli) { registerIpcCommand(smartcli, 'list', async (_argvArg: CliArguments) => { const response = await tspmIpcClient.request('list', {}); const processes = response.processes; if (processes.length === 0) { console.log('No processes running.'); return; } console.log('Process List:'); console.log('┌─────────┬─────────────┬───────────┬───────────┬──────────┬──────────┐'); console.log('│ ID │ Name │ Status │ PID │ Memory │ Restarts │'); console.log('├─────────┼─────────────┼───────────┼───────────┼──────────┼──────────┤'); for (const proc of processes) { const statusColor = proc.status === 'online' ? '\x1b[32m' : proc.status === 'errored' ? '\x1b[31m' : '\x1b[33m'; const resetColor = '\x1b[0m'; console.log( `│ ${pad(proc.id, 7)} │ ${pad(proc.id, 11)} │ ${statusColor}${pad(proc.status, 9)}${resetColor} │ ${pad((proc.pid || '-').toString(), 9)} │ ${pad(formatMemory(proc.memory), 8)} │ ${pad(proc.restarts.toString(), 8)} │`, ); } console.log('└─────────┴─────────────┴───────────┴───────────┴──────────┴──────────┘'); }, { actionLabel: 'list processes' }); }