task-wrapper.d.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /// <reference types="node" />
  2. import { ListrError, ListrErrorTypes } from '../interfaces/listr-error.interface';
  3. import { ListrBaseClassOptions, ListrSubClassOptions, ListrTask } from '../interfaces/listr.interface';
  4. import { ListrRendererFactory } from '../interfaces/renderer.interface';
  5. import { Task } from './task';
  6. import { Listr } from '../listr';
  7. import { PromptOptions } from '../utils/prompt.interface';
  8. /**
  9. * Extend the task to have more functionality while accesing from the outside.
  10. */
  11. export declare class TaskWrapper<Ctx, Renderer extends ListrRendererFactory> {
  12. task: Task<Ctx, ListrRendererFactory>;
  13. errors: ListrError<Ctx>[];
  14. private options;
  15. constructor(task: Task<Ctx, ListrRendererFactory>, errors: ListrError<Ctx>[], options: ListrBaseClassOptions<Ctx, any, any>);
  16. /** Change the title of the current task. */
  17. set title(data: string);
  18. /** Get the title of the current task. */
  19. get title(): string;
  20. /** Send a output to the output channel. */
  21. set output(data: string);
  22. /** Get the output from the output channel. */
  23. get output(): string;
  24. /** Create a new subtask with given renderer selection from the parent task. */
  25. newListr<NewCtx = Ctx>(task: ListrTask<NewCtx, Renderer> | ListrTask<NewCtx, Renderer>[] | ((parent: Omit<this, 'skip' | 'enabled'>) => ListrTask<NewCtx, Renderer> | ListrTask<NewCtx, Renderer>[]), options?: ListrSubClassOptions<NewCtx, Renderer>): Listr<NewCtx, any, any>;
  26. /** Report a error in process for error collection. */
  27. report(error: Error, type: ListrErrorTypes): void;
  28. /** Skip current task. */
  29. skip(message?: string): void;
  30. /** Get the number of retrying, else returns false */
  31. isRetrying(): Task<Ctx, Renderer>['retry'];
  32. /**
  33. * Create a new Enquirer prompt using prompt options.
  34. *
  35. * Since process.stdout is controlled by Listr, this will passthrough all Enquirer data through internal stdout.
  36. */
  37. prompt<T = any>(options: PromptOptions | PromptOptions<true>[]): Promise<T>;
  38. /** Cancels the current prompt attach to this task. */
  39. cancelPrompt(throwError?: boolean): void;
  40. /**
  41. * Pass stream of data to internal stdout.
  42. *
  43. * Since Listr2 takes control of process.stdout utilizing the default renderer, any data outputted to process.stdout
  44. * will corupt its looks.
  45. *
  46. * This returns a fake stream to pass any stream inside Listr as task data.
  47. */
  48. stdout(): NodeJS.WriteStream & NodeJS.WritableStream;
  49. /** Run this task. */
  50. run(ctx: Ctx): Promise<void>;
  51. }