@oclif/multi-stage-output
Version:
Terminal output for oclif commands with multiple stages
99 lines (98 loc) • 3.89 kB
TypeScript
import React from 'react';
import { RequiredDesign } from '../design.js';
import { StageTracker } from '../stage-tracker.js';
type Info<T extends Record<string, unknown>> = {
/**
* key-value: Display a key-value pair with a spinner.
* static-key-value: Display a key-value pair without a spinner.
* message: Display a message.
*/
type: 'dynamic-key-value' | 'static-key-value' | 'message';
/**
* Color of the value.
*/
color?: string;
/**
* Get the value to display. Takes the data property on the MultiStageComponent as an argument.
* Useful if you want to apply some logic (like rendering a link) to the data before displaying it.
*
* @param data The data property on the MultiStageComponent.
* @returns {string | undefined}
*/
get: (data?: T) => string | undefined;
/**
* Whether the value should be bold.
*/
bold?: boolean;
/**
* Set to `true` to prevent this key-value pair or message from being collapsed when the window is too short. Defaults to false.
*/
neverCollapse?: boolean;
/**
* Set to `true` to only show this key-value pair or message at the very end of the CI output. Defaults to false.
*/
onlyShowAtEndInCI?: boolean;
/**
* Set to `true` to always render this key-value pair or message in CI output (ignores throttling). Defaults to false.
*/
alwaysPrintInCI?: boolean;
};
export type KeyValuePair<T extends Record<string, unknown>> = Info<T> & {
/**
* Label of the key-value pair.
*/
label: string;
type: 'dynamic-key-value' | 'static-key-value';
};
export type SimpleMessage<T extends Record<string, unknown>> = Info<T> & {
type: 'message';
};
export type InfoBlock<T extends Record<string, unknown>> = Array<KeyValuePair<T> | SimpleMessage<T>>;
export type StageInfoBlock<T extends Record<string, unknown>> = Array<(KeyValuePair<T> & {
stage: string;
}) | (SimpleMessage<T> & {
stage: string;
})>;
export type FormattedKeyValue = {
readonly color?: string;
readonly isBold?: boolean;
readonly label?: string;
readonly value: string | undefined;
readonly stage?: string;
readonly type: 'dynamic-key-value' | 'static-key-value' | 'message';
readonly neverCollapse?: boolean;
};
export type StagesProps = {
readonly compactionLevel?: number;
readonly design?: RequiredDesign;
readonly error?: Error | undefined;
readonly hasElapsedTime?: boolean;
readonly hasStageTime?: boolean;
readonly postStagesBlock?: FormattedKeyValue[];
readonly preStagesBlock?: FormattedKeyValue[];
readonly stageSpecificBlock?: FormattedKeyValue[];
readonly stageTracker: StageTracker;
readonly timerUnit?: 'ms' | 's';
readonly title?: string;
};
/**
* Determine the level of compaction required to render the stages component within the terminal height.
*
* Compaction levels:
* 0 - hide nothing
* 1 - only show one stage at a time, with stage specific info nested under the stage
* 2 - hide the elapsed time
* 3 - hide the title
* 4 - hide the pre-stages block
* 5 - hide the post-stages block
* 6 - put the stage specific info directly next to the stage
* 7 - hide the stage-specific block
* 8 - reduce the padding between boxes
* @returns the compaction level based on the number of lines that will be displayed
*/
export declare function determineCompactionLevel({ design, hasElapsedTime, hasStageTime, postStagesBlock, preStagesBlock, stageSpecificBlock, stageTracker, title, }: StagesProps, rows: number, columns: number): {
compactionLevel: number;
totalHeight: number;
};
export declare function Stages({ compactionLevel, design, error, hasElapsedTime, hasStageTime, postStagesBlock, preStagesBlock, stageSpecificBlock, stageTracker, timerUnit, title, }: StagesProps): React.ReactNode;
export {};