Skip to content

Commit

Permalink
chore: support terminal sizes of < 100 columns (80columns is min)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Sep 9, 2024
1 parent b3bb36c commit d7ae261
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/commands/runs/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,16 @@ const ShortDurationFormatter = new SapphireDurationFormatter({
// END of TODO

const multilineTimestampFormatter = new Timestamp(`YYYY-MM-DD[\n]HH:mm:ss`);
const terminalColumns = process.stdout.columns ?? 100;
const tableFactory = (compact = false) => {
const head =
terminalColumns < 100
? // Smaller terminals should show less data
['ID', 'Status', 'Results', 'Usage', 'Started At', 'Took']
: ['ID', 'Status', 'Results', 'Usage', 'Started At', 'Took', 'Build No.', 'Origin'];

const options: Record<string, unknown> = {
head: ['ID', 'Status', 'Results', 'Usage', 'Start Date', 'Took', 'Build Number', 'Origin'],
head,
style: {
head: ['cyan', 'cyan', 'cyan', 'cyan', 'cyan', 'cyan', 'cyan', 'cyan'],
compact,
Expand All @@ -162,7 +169,12 @@ const tableFactory = (compact = false) => {
};
}

return new Table<[string, string, string, string, string, string, string, string]>(options);
return new Table<
// Small terminal (drop origin and build number)
| [string, string, string, string, string, string]
// large enough terminal
| [string, string, string, string, string, string, string, string]
>(options);
};

export class RunsLsCommand extends ApifyCommand<typeof RunsLsCommand> {
Expand Down Expand Up @@ -246,15 +258,15 @@ export class RunsLsCommand extends ApifyCommand<typeof RunsLsCommand> {

for (const run of allRuns.items) {
// 'ID', 'Status', 'Results', 'Usage', 'Took', 'Build Number', 'Origin'
const tableRow: [string, string, string, string, string, string, string, string] = [
const tableRow:
| [string, string, string, string, string, string]
| [string, string, string, string, string, string, string, string] = [
chalk.gray(run.id),
prettyPrintStatus(run.status),
chalk.gray('N/A'),
chalk.cyan(`$${(run.usageTotalUsd ?? 0).toFixed(3)}`),
multilineTimestampFormatter.display(run.startedAt),
'',
run.buildNumber,
run.meta.origin ?? 'UNKNOWN',
];

if (run.finishedAt) {
Expand All @@ -269,6 +281,10 @@ export class RunsLsCommand extends ApifyCommand<typeof RunsLsCommand> {

tableRow[2] = datasetInfos.get(run.id) || chalk.gray('N/A');

if (terminalColumns >= 100) {
tableRow.push(run.buildNumber, run.meta.origin ?? 'UNKNOWN');
}

table.push(tableRow);
}

Expand Down

0 comments on commit d7ae261

Please sign in to comment.