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 presentation.showReuseMessage & clear in task config #7454

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/task/src/browser/task-schema-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,9 @@ const presentation: IJSONSchema = {
default: {
reveal: 'always',
focus: false,
panel: 'shared'
panel: 'shared',
showReuseMessage: true,
clear: false
},
description: 'Configures the panel that is used to present the task\'s output and reads its input.',
additionalProperties: true,
Expand Down Expand Up @@ -572,6 +574,16 @@ const presentation: IJSONSchema = {
],
default: 'shared',
description: 'Controls if the panel is shared between tasks, dedicated to this task or a new one is created on every run.'
},
showReuseMessage: {
type: 'boolean',
default: true,
description: 'Controls whether to show the "Terminal will be reused by tasks" message.'
},
clear: {
type: 'boolean',
default: false,
description: 'Controls whether the terminal is cleared before this task is run.'
}
}
};
Expand Down
24 changes: 16 additions & 8 deletions packages/task/src/browser/task-terminal-widget-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ApplicationShell, WidgetOpenerOptions } from '@theia/core/lib/browser';
import { TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
import { TerminalWidgetFactoryOptions } from '@theia/terminal/lib/browser/terminal-widget-impl';
import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
import { PanelKind, TaskConfiguration, TaskWatcher, TaskExitedEvent, TaskServer } from '../common';
import { PanelKind, TaskConfiguration, TaskWatcher, TaskExitedEvent, TaskServer, TaskOutputPresentation } from '../common';
import { TaskDefinitionRegistry } from './task-definition-registry';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';

Expand Down Expand Up @@ -83,7 +83,8 @@ export class TaskTerminalWidgetManager {
// find the terminal where the task ran, and mark it as "idle"
for (const terminal of this.getTaskTerminalWidgets()) {
if (terminal.taskId === finishedTaskId) {
this.notifyTaskFinished(terminal);
const showReuseMessage = !!event.config && TaskOutputPresentation.shouldShowReuseMessage(event.config);
this.notifyTaskFinished(terminal, showReuseMessage);
break;
}
}
Expand All @@ -103,11 +104,11 @@ export class TaskTerminalWidgetManager {
terminal.taskConfig = taskConfig;
terminal.busy = true;
} else {
this.notifyTaskFinished(terminal);
this.notifyTaskFinished(terminal, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with being explicit and setting the reuse to true despite it being the default.

}
});
const didConnectFailureListener = terminal.onDidOpenFailure(async () => {
this.notifyTaskFinished(terminal);
this.notifyTaskFinished(terminal, true);
});
terminal.onDidDispose(() => {
didConnectListener.dispose();
Expand All @@ -127,8 +128,13 @@ export class TaskTerminalWidgetManager {
if (isNew) {
this.shell.addWidget(widget, { area: options.widgetOptions ? options.widgetOptions.area : 'bottom' });
widget.resetTerminal();
} else if (options.title) {
widget.setTitle(options.title);
} else {
if (options.title) {
widget.setTitle(options.title);
}
if (options.taskConfig && TaskOutputPresentation.shouldClearTerminalBeforeRun(options.taskConfig)) {
widget.clearOutput();
}
}
this.terminalService.open(widget, options);

Expand Down Expand Up @@ -178,9 +184,11 @@ export class TaskTerminalWidgetManager {
return this.terminalService.all.filter(TaskTerminalWidget.is);
}

private notifyTaskFinished(terminal: TaskTerminalWidget): void {
private notifyTaskFinished(terminal: TaskTerminalWidget, showReuseMessage: boolean): void {
terminal.busy = false;
terminal.scrollToBottom();
terminal.writeLine('\x1b[1m\n\rTerminal will be reused by tasks. \x1b[0m\n');
if (showReuseMessage) {
terminal.writeLine('\x1b[1m\n\rTerminal will be reused by tasks. \x1b[0m\n');
}
}
}
25 changes: 23 additions & 2 deletions packages/task/src/common/task-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface TaskOutputPresentation {
focus?: boolean;
reveal?: RevealKind;
panel?: PanelKind;
showReuseMessage?: boolean;
clear?: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[name: string]: any;
}
Expand All @@ -52,7 +54,9 @@ export namespace TaskOutputPresentation {
let outputPresentation = {
reveal: RevealKind.Always,
focus: false,
panel: PanelKind.Shared
panel: PanelKind.Shared,
showReuseMessage: true,
clear: false
};
if (task && task.presentation) {
if (task.presentation.reveal) {
Expand All @@ -73,10 +77,27 @@ export namespace TaskOutputPresentation {
}
outputPresentation = { ...outputPresentation, panel };
}
outputPresentation = { ...outputPresentation, focus: !!task.presentation.focus };
outputPresentation = {
...outputPresentation,
focus: shouldSetFocusToTerminal(task),
showReuseMessage: shouldShowReuseMessage(task),
clear: shouldClearTerminalBeforeRun(task)
};
}
return outputPresentation;
}

export function shouldSetFocusToTerminal(task: TaskCustomization): boolean {
return !!task.presentation && !!task.presentation.focus;
}

export function shouldClearTerminalBeforeRun(task: TaskCustomization): boolean {
return !!task.presentation && !!task.presentation.clear;
}

export function shouldShowReuseMessage(task: TaskCustomization): boolean {
return !task.presentation || task.presentation.showReuseMessage === undefined || !!task.presentation.showReuseMessage;
}
}

export interface TaskCustomization {
Expand Down