MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / formatTable

Function formatTable

apps/kimi-code/src/cli/sub/server/ps.ts:108–129  ·  view source on GitHub ↗
(connections: ConnectionInfo[])

Source from the content-addressed store, hash-verified

106}
107
108function formatTable(connections: ConnectionInfo[]): string {
109 if (connections.length === 0) {
110 return 'No active clients.\n';
111 }
112
113 const header = ['ID', 'CONNECTED', 'REMOTE', 'USER_AGENT', 'SESSIONS', 'HELLO'];
114 const rows = connections.map((c) => [
115 c.id,
116 formatAge(c.connected_at),
117 c.remote_address ?? '-',
118 truncate(c.user_agent ?? '-', USER_AGENT_MAX_WIDTH),
119 String(c.subscriptions.length),
120 c.has_client_hello ? 'yes' : 'no',
121 ]);
122
123 const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i]!.length)));
124 const formatRow = (cells: string[]): string =>
125 cells.map((cell, i) => cell + ' '.repeat(Math.max(0, widths[i]! - cell.length))).join(' ');
126
127 const lines = [chalk.bold(formatRow(header)), ...rows.map(formatRow)];
128 return `${lines.join('\n')}\n`;
129}
130
131function formatAge(iso: string): string {
132 const ms = Date.now() - Date.parse(iso);

Callers 1

handlePsCommandFunction · 0.85

Calls 4

formatAgeFunction · 0.85
formatRowFunction · 0.85
boldMethod · 0.80
truncateFunction · 0.70

Tested by

no test coverage detected