Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Support]: Is there a way to clear output per task? #703

Open
1 task done
tommy-mitchell opened this issue Jan 23, 2024 · 3 comments · May be fixed by #704
Open
1 task done

[Support]: Is there a way to clear output per task? #703

tommy-mitchell opened this issue Jan 23, 2024 · 3 comments · May be fixed by #704
Assignees

Comments

@tommy-mitchell
Copy link

tommy-mitchell commented Jan 23, 2024

Support Request

Can a task clear its own output? It can be controlled ahead of time via the persistentOutput option, but I want to clear the output if some condition is met:

const tasks = new Listr([{
  title: 'foo',
  task: async (ctx, task) => {
    const someCondition = await thing();

    if (someCondition) {
      task.title = "Condition met!"
      task.clearOutput();
      return;
    }

    // do other stuff...
  },
  rendererOptions: {
    persistentOutput: true, // output persists by default
  },
}]);

Preflight

@cenk1cenk2
Copy link
Collaborator

Dear @tommy-mitchell,

Since I have offloaded output handling to the renderers themselves with one of the recent major versions, there is no easy way to do this. However, task can forward an event to the renderer to do that since there are mechanisms in place if this is supposed to be implemented.

You can try to drop the output of the task like task.output = [] or task.output = '' but it might ignore them since they are empty and default renderer does not like empty outputs. This would only work in the case where there is only one output line outputted.

I do not think these days I have time to implement this, but it should be possible at least.

@tommy-mitchell
Copy link
Author

Are these the events you're talking about?

export declare class ListrTaskEventMap extends BaseEventMap implements EventMap<ListrTaskEventType> {
[ListrTaskEventType.STATE]: ListrTaskState;
[ListrTaskEventType.ENABLED]: boolean;
[ListrTaskEventType.SUBTASK]: Task<any, any, any>[];
[ListrTaskEventType.TITLE]: string;
[ListrTaskEventType.OUTPUT]: string;
[ListrTaskEventType.MESSAGE]: ListrTaskMessage;
[ListrTaskEventType.PROMPT]: string;
[ListrTaskEventType.CLOSED]: never
}

@cenk1cenk2
Copy link
Collaborator

cenk1cenk2 commented Jan 29, 2024

Yes exactly and if it fires a certain event and renderer implements it, then it can clear output for that task. Because this is only valid in default renderer context.

and handling of the event goes here

private setupBuffer (task: ListrDefaultRendererTask): void {

@tommy-mitchell tommy-mitchell linked a pull request Jan 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants