This commit is contained in:
75
src/commands/list.ts
Normal file
75
src/commands/list.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import { fileUtils } from '../utils/fileUtils';
|
||||||
|
import { Layout } from '../models/types';
|
||||||
|
|
||||||
|
interface ListOptions {
|
||||||
|
format?: 'table' | 'json';
|
||||||
|
verbose?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listLayouts(options: ListOptions): Promise<void> {
|
||||||
|
await fileUtils.initialize();
|
||||||
|
|
||||||
|
const layouts = await fileUtils.listLayouts();
|
||||||
|
if (layouts.length === 0) {
|
||||||
|
console.log('No layouts found. Use "save" command to create your first layout.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const layoutDetails: Array<{
|
||||||
|
name: string;
|
||||||
|
terminalType: string;
|
||||||
|
windows: number;
|
||||||
|
description: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
for (const layoutFile of layouts) {
|
||||||
|
try {
|
||||||
|
const layout = await fileUtils.readLayout(layoutFile) as Layout;
|
||||||
|
layoutDetails.push({
|
||||||
|
name: layoutFile.replace(/\.(json|yaml|yml)$/, ''),
|
||||||
|
terminalType: layout.terminalType,
|
||||||
|
windows: layout.session.windows.length,
|
||||||
|
description: layout.metadata?.description || '-',
|
||||||
|
updatedAt: layout.updatedAt,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
layoutDetails.push({
|
||||||
|
name: layoutFile,
|
||||||
|
terminalType: 'unknown',
|
||||||
|
windows: 0,
|
||||||
|
description: 'Error reading layout',
|
||||||
|
updatedAt: '-',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.format === 'json') {
|
||||||
|
console.log(JSON.stringify(layoutDetails, null, 2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const terminalTypeWidth = Math.max(12, ...layoutDetails.map((l) => l.terminalType.length));
|
||||||
|
const nameWidth = Math.max(20, ...layoutDetails.map((l) => l.name.length));
|
||||||
|
|
||||||
|
console.log('Saved Layouts');
|
||||||
|
console.log('='.repeat(nameWidth + terminalTypeWidth + 60));
|
||||||
|
console.log(
|
||||||
|
`Name${' '.repeat(nameWidth - 4)} | Type${' '.repeat(terminalTypeWidth - 4)} | Windows | Description`
|
||||||
|
);
|
||||||
|
console.log('-'.repeat(nameWidth + terminalTypeWidth + 60));
|
||||||
|
|
||||||
|
for (const layout of layoutDetails) {
|
||||||
|
const name = layout.name.padEnd(nameWidth);
|
||||||
|
const type = layout.terminalType.padEnd(terminalTypeWidth);
|
||||||
|
const windows = String(layout.windows).padEnd(7);
|
||||||
|
const desc = layout.description.substring(0, 30);
|
||||||
|
console.log(`${name} | ${type} | ${windows} | ${desc}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`\nTotal: ${layouts.length} layout(s)`);
|
||||||
|
|
||||||
|
if (options.verbose) {
|
||||||
|
console.log('\nLayout Directory:', fileUtils.getLayoutsDir());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user