@theia/console 1.45.1 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/ansi-console-item.d.ts +12 -12
  3. package/lib/browser/ansi-console-item.js +38 -38
  4. package/lib/browser/console-content-widget.d.ts +17 -17
  5. package/lib/browser/console-content-widget.js +93 -93
  6. package/lib/browser/console-contribution.d.ts +33 -33
  7. package/lib/browser/console-contribution.js +143 -143
  8. package/lib/browser/console-frontend-module.d.ts +4 -4
  9. package/lib/browser/console-frontend-module.js +31 -31
  10. package/lib/browser/console-history.d.ts +19 -19
  11. package/lib/browser/console-history.js +74 -74
  12. package/lib/browser/console-manager.d.ts +7 -7
  13. package/lib/browser/console-manager.js +48 -48
  14. package/lib/browser/console-session-manager.d.ts +31 -31
  15. package/lib/browser/console-session-manager.js +116 -116
  16. package/lib/browser/console-session.d.ts +27 -27
  17. package/lib/browser/console-session.js +56 -56
  18. package/lib/browser/console-widget.d.ts +67 -67
  19. package/lib/browser/console-widget.d.ts.map +1 -1
  20. package/lib/browser/console-widget.js +270 -271
  21. package/lib/browser/console-widget.js.map +1 -1
  22. package/lib/package.spec.js +25 -25
  23. package/package.json +6 -6
  24. package/src/browser/ansi-console-item.tsx +48 -48
  25. package/src/browser/console-content-widget.tsx +91 -91
  26. package/src/browser/console-contribution.ts +143 -143
  27. package/src/browser/console-frontend-module.ts +32 -32
  28. package/src/browser/console-history.ts +76 -76
  29. package/src/browser/console-manager.ts +37 -37
  30. package/src/browser/console-session-manager.ts +121 -121
  31. package/src/browser/console-session.ts +61 -61
  32. package/src/browser/console-widget.ts +298 -299
  33. package/src/browser/style/index.css +49 -49
  34. package/src/package.spec.ts +28 -28
@@ -1,26 +1,26 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
- /* note: this bogus test file is required so that
17
- we are able to run mocha unit tests on this
18
- package, without having any actual unit tests in it.
19
- This way a coverage report will be generated,
20
- showing 0% coverage, instead of no report.
21
- This file can be removed once we have real unit
22
- tests in place. */
23
- describe('console package', () => {
24
- it('support code coverage statistics', () => true);
25
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+ /* note: this bogus test file is required so that
17
+ we are able to run mocha unit tests on this
18
+ package, without having any actual unit tests in it.
19
+ This way a coverage report will be generated,
20
+ showing 0% coverage, instead of no report.
21
+ This file can be removed once we have real unit
22
+ tests in place. */
23
+ describe('console package', () => {
24
+ it('support code coverage statistics', () => true);
25
+ });
26
26
  //# sourceMappingURL=package.spec.js.map
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@theia/console",
3
- "version": "1.45.1",
3
+ "version": "1.46.0-next.72+4a275b29d",
4
4
  "description": "Theia - Console Extension",
5
5
  "dependencies": {
6
- "@theia/core": "1.45.1",
7
- "@theia/monaco": "1.45.1",
8
- "@theia/monaco-editor-core": "1.72.3",
6
+ "@theia/core": "1.46.0-next.72+4a275b29d",
7
+ "@theia/monaco": "1.46.0-next.72+4a275b29d",
8
+ "@theia/monaco-editor-core": "1.83.101",
9
9
  "anser": "^2.0.1"
10
10
  },
11
11
  "publishConfig": {
@@ -41,10 +41,10 @@
41
41
  "watch": "theiaext watch"
42
42
  },
43
43
  "devDependencies": {
44
- "@theia/ext-scripts": "1.45.1"
44
+ "@theia/ext-scripts": "1.46.0"
45
45
  },
46
46
  "nyc": {
47
47
  "extends": "../../configs/nyc.json"
48
48
  },
49
- "gitHead": "3837c50544190b80d0ad8e87aa9fa9f286c70fcc"
49
+ "gitHead": "4a275b29d0db6c81190488c7f76cb667da05ef19"
50
50
  }
@@ -1,48 +1,48 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import * as React from '@theia/core/shared/react';
18
- import * as DOMPurify from '@theia/core/shared/dompurify';
19
- import { ConsoleItem } from './console-session';
20
- import { Severity } from '@theia/core/lib/common/severity';
21
- import Anser = require('anser');
22
-
23
- export class AnsiConsoleItem implements ConsoleItem {
24
-
25
- protected readonly htmlContent: string;
26
-
27
- constructor(
28
- public readonly content: string,
29
- public readonly severity?: Severity
30
- ) {
31
- this.htmlContent = new Anser().ansiToHtml(this.content, {
32
- use_classes: true,
33
- remove_empty: true
34
- });
35
- }
36
-
37
- get visible(): boolean {
38
- return !!this.htmlContent;
39
- }
40
-
41
- render(): React.ReactNode {
42
- return <div
43
- className='theia-console-ansi-console-item'
44
- dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(this.htmlContent) }} // eslint-disable-line react/no-danger
45
- />;
46
- }
47
-
48
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as React from '@theia/core/shared/react';
18
+ import * as DOMPurify from '@theia/core/shared/dompurify';
19
+ import { ConsoleItem } from './console-session';
20
+ import { Severity } from '@theia/core/lib/common/severity';
21
+ import Anser = require('anser');
22
+
23
+ export class AnsiConsoleItem implements ConsoleItem {
24
+
25
+ protected readonly htmlContent: string;
26
+
27
+ constructor(
28
+ public readonly content: string,
29
+ public readonly severity?: Severity
30
+ ) {
31
+ this.htmlContent = new Anser().ansiToHtml(this.content, {
32
+ use_classes: true,
33
+ remove_empty: true
34
+ });
35
+ }
36
+
37
+ get visible(): boolean {
38
+ return !!this.htmlContent;
39
+ }
40
+
41
+ render(): React.ReactNode {
42
+ return <div
43
+ className='theia-console-ansi-console-item'
44
+ dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(this.htmlContent) }} // eslint-disable-line react/no-danger
45
+ />;
46
+ }
47
+
48
+ }
@@ -1,91 +1,91 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Message } from '@theia/core/shared/@phosphor/messaging';
18
- import { interfaces, Container, injectable } from '@theia/core/shared/inversify';
19
- import { MenuPath } from '@theia/core';
20
- import { TreeProps } from '@theia/core/lib/browser/tree';
21
- import { SourceTreeWidget, TreeSourceNode, TreeElementNode } from '@theia/core/lib/browser/source-tree';
22
- import { ConsoleItem } from './console-session';
23
- import { Severity } from '@theia/core/lib/common/severity';
24
-
25
- @injectable()
26
- export class ConsoleContentWidget extends SourceTreeWidget {
27
-
28
- static CONTEXT_MENU: MenuPath = ['console-context-menu'];
29
-
30
- protected _shouldScrollToEnd = true;
31
-
32
- protected set shouldScrollToEnd(shouldScrollToEnd: boolean) {
33
- this._shouldScrollToEnd = shouldScrollToEnd;
34
- this.shouldScrollToRow = this._shouldScrollToEnd;
35
- }
36
-
37
- protected get shouldScrollToEnd(): boolean {
38
- return this._shouldScrollToEnd;
39
- }
40
-
41
- static override createContainer(parent: interfaces.Container, props?: Partial<TreeProps>): Container {
42
- const child = SourceTreeWidget.createContainer(parent, {
43
- contextMenuPath: ConsoleContentWidget.CONTEXT_MENU,
44
- ...props
45
- });
46
- child.unbind(SourceTreeWidget);
47
- child.bind(ConsoleContentWidget).toSelf();
48
- return child;
49
- }
50
-
51
- protected override onAfterAttach(msg: Message): void {
52
- super.onAfterAttach(msg);
53
- this.toDisposeOnDetach.push(this.onScrollUp(() => this.shouldScrollToEnd = false));
54
- this.toDisposeOnDetach.push(this.onScrollYReachEnd(() => this.shouldScrollToEnd = true));
55
- this.toDisposeOnDetach.push(this.model.onChanged(() => this.revealLastOutputIfNeeded()));
56
- }
57
-
58
- protected revealLastOutputIfNeeded(): void {
59
- const { root } = this.model;
60
- if (this.shouldScrollToEnd && TreeSourceNode.is(root)) {
61
- this.model.selectNode(root.children[root.children.length - 1]);
62
- }
63
- }
64
-
65
- protected override createTreeElementNodeClassNames(node: TreeElementNode): string[] {
66
- const classNames = super.createTreeElementNodeClassNames(node);
67
- if (node.element) {
68
- const className = this.toClassName((node.element as ConsoleItem));
69
- if (className) {
70
- classNames.push(className);
71
- }
72
- }
73
- return classNames;
74
- }
75
- protected toClassName(item: ConsoleItem): string | undefined {
76
- if (item.severity === Severity.Error) {
77
- return ConsoleItem.errorClassName;
78
- }
79
- if (item.severity === Severity.Warning) {
80
- return ConsoleItem.warningClassName;
81
- }
82
- if (item.severity === Severity.Info) {
83
- return ConsoleItem.infoClassName;
84
- }
85
- if (item.severity === Severity.Log) {
86
- return ConsoleItem.logClassName;
87
- }
88
- return undefined;
89
- }
90
-
91
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Message } from '@theia/core/shared/@phosphor/messaging';
18
+ import { interfaces, Container, injectable } from '@theia/core/shared/inversify';
19
+ import { MenuPath } from '@theia/core';
20
+ import { TreeProps } from '@theia/core/lib/browser/tree';
21
+ import { SourceTreeWidget, TreeSourceNode, TreeElementNode } from '@theia/core/lib/browser/source-tree';
22
+ import { ConsoleItem } from './console-session';
23
+ import { Severity } from '@theia/core/lib/common/severity';
24
+
25
+ @injectable()
26
+ export class ConsoleContentWidget extends SourceTreeWidget {
27
+
28
+ static CONTEXT_MENU: MenuPath = ['console-context-menu'];
29
+
30
+ protected _shouldScrollToEnd = true;
31
+
32
+ protected set shouldScrollToEnd(shouldScrollToEnd: boolean) {
33
+ this._shouldScrollToEnd = shouldScrollToEnd;
34
+ this.shouldScrollToRow = this._shouldScrollToEnd;
35
+ }
36
+
37
+ protected get shouldScrollToEnd(): boolean {
38
+ return this._shouldScrollToEnd;
39
+ }
40
+
41
+ static override createContainer(parent: interfaces.Container, props?: Partial<TreeProps>): Container {
42
+ const child = SourceTreeWidget.createContainer(parent, {
43
+ contextMenuPath: ConsoleContentWidget.CONTEXT_MENU,
44
+ ...props
45
+ });
46
+ child.unbind(SourceTreeWidget);
47
+ child.bind(ConsoleContentWidget).toSelf();
48
+ return child;
49
+ }
50
+
51
+ protected override onAfterAttach(msg: Message): void {
52
+ super.onAfterAttach(msg);
53
+ this.toDisposeOnDetach.push(this.onScrollUp(() => this.shouldScrollToEnd = false));
54
+ this.toDisposeOnDetach.push(this.onScrollYReachEnd(() => this.shouldScrollToEnd = true));
55
+ this.toDisposeOnDetach.push(this.model.onChanged(() => this.revealLastOutputIfNeeded()));
56
+ }
57
+
58
+ protected revealLastOutputIfNeeded(): void {
59
+ const { root } = this.model;
60
+ if (this.shouldScrollToEnd && TreeSourceNode.is(root)) {
61
+ this.model.selectNode(root.children[root.children.length - 1]);
62
+ }
63
+ }
64
+
65
+ protected override createTreeElementNodeClassNames(node: TreeElementNode): string[] {
66
+ const classNames = super.createTreeElementNodeClassNames(node);
67
+ if (node.element) {
68
+ const className = this.toClassName((node.element as ConsoleItem));
69
+ if (className) {
70
+ classNames.push(className);
71
+ }
72
+ }
73
+ return classNames;
74
+ }
75
+ protected toClassName(item: ConsoleItem): string | undefined {
76
+ if (item.severity === Severity.Error) {
77
+ return ConsoleItem.errorClassName;
78
+ }
79
+ if (item.severity === Severity.Warning) {
80
+ return ConsoleItem.warningClassName;
81
+ }
82
+ if (item.severity === Severity.Info) {
83
+ return ConsoleItem.infoClassName;
84
+ }
85
+ if (item.severity === Severity.Log) {
86
+ return ConsoleItem.logClassName;
87
+ }
88
+ return undefined;
89
+ }
90
+
91
+ }
@@ -1,143 +1,143 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable, inject } from '@theia/core/shared/inversify';
18
- import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry, CommandHandler } from '@theia/core';
19
- import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegistry, CommonCommands } from '@theia/core/lib/browser';
20
- import { ConsoleManager } from './console-manager';
21
- import { ConsoleWidget } from './console-widget';
22
- import { ConsoleContentWidget } from './console-content-widget';
23
- import { nls } from '@theia/core/lib/common/nls';
24
-
25
- export namespace ConsoleCommands {
26
- export const SELECT_ALL: Command = {
27
- id: 'console.selectAll'
28
- };
29
- export const COLLAPSE_ALL: Command = {
30
- id: 'console.collapseAll'
31
- };
32
- export const CLEAR: Command = {
33
- id: 'console.clear'
34
- };
35
- export const EXECUTE: Command = {
36
- id: 'console.execute'
37
- };
38
- export const NAVIGATE_BACK: Command = {
39
- id: 'console.navigatePrevious'
40
- };
41
- export const NAVIGATE_FORWARD: Command = {
42
- id: 'console.navigateNext'
43
- };
44
- }
45
-
46
- export namespace ConsoleContextMenu {
47
- export const CLIPBOARD = [...ConsoleContentWidget.CONTEXT_MENU, '1_clipboard'];
48
- export const CLEAR = [...ConsoleContentWidget.CONTEXT_MENU, '2_clear'];
49
- }
50
-
51
- @injectable()
52
- export class ConsoleContribution implements FrontendApplicationContribution, CommandContribution, KeybindingContribution, MenuContribution {
53
-
54
- @inject(ConsoleManager)
55
- protected readonly manager: ConsoleManager;
56
-
57
- initialize(): void { }
58
-
59
- registerCommands(commands: CommandRegistry): void {
60
- commands.registerCommand(ConsoleCommands.SELECT_ALL, this.newCommandHandler(console => console.selectAll()));
61
- commands.registerCommand(ConsoleCommands.COLLAPSE_ALL, this.newCommandHandler(console => console.collapseAll()));
62
- commands.registerCommand(ConsoleCommands.CLEAR, this.newCommandHandler(console => console.clear()));
63
- commands.registerCommand(ConsoleCommands.EXECUTE, this.newCommandHandler(console => console.execute()));
64
- commands.registerCommand(ConsoleCommands.NAVIGATE_BACK, this.newCommandHandler(console => console.navigateBack()));
65
- commands.registerCommand(ConsoleCommands.NAVIGATE_FORWARD, this.newCommandHandler(console => console.navigateForward()));
66
- }
67
-
68
- registerKeybindings(keybindings: KeybindingRegistry): void {
69
- keybindings.registerKeybinding({
70
- command: ConsoleCommands.SELECT_ALL.id,
71
- keybinding: 'ctrlcmd+a',
72
- when: 'consoleContentFocus'
73
- });
74
- keybindings.registerKeybinding({
75
- command: ConsoleCommands.EXECUTE.id,
76
- keybinding: 'enter',
77
- when: 'consoleInputFocus'
78
- });
79
- keybindings.registerKeybinding({
80
- command: ConsoleCommands.NAVIGATE_BACK.id,
81
- keybinding: 'up',
82
- when: 'consoleInputFocus && consoleNavigationBackEnabled'
83
- });
84
- keybindings.registerKeybinding({
85
- command: ConsoleCommands.NAVIGATE_FORWARD.id,
86
- keybinding: 'down',
87
- when: 'consoleInputFocus && consoleNavigationForwardEnabled'
88
- });
89
- }
90
-
91
- registerMenus(menus: MenuModelRegistry): void {
92
- menus.registerMenuAction(ConsoleContextMenu.CLIPBOARD, {
93
- commandId: CommonCommands.COPY.id,
94
- label: CommonCommands.COPY.label,
95
- order: 'a1',
96
- });
97
- menus.registerMenuAction(ConsoleContextMenu.CLIPBOARD, {
98
- commandId: ConsoleCommands.SELECT_ALL.id,
99
- label: CommonCommands.SELECT_ALL.label,
100
- order: 'a2'
101
- });
102
- menus.registerMenuAction(ConsoleContextMenu.CLIPBOARD, {
103
- commandId: ConsoleCommands.COLLAPSE_ALL.id,
104
- label: nls.localizeByDefault('Collapse All'),
105
- order: 'a3'
106
- });
107
- menus.registerMenuAction(ConsoleContextMenu.CLEAR, {
108
- commandId: ConsoleCommands.CLEAR.id,
109
- label: nls.localizeByDefault('Clear Console')
110
- });
111
- }
112
-
113
- protected newCommandHandler(execute: ConsoleExecuteFunction): ConsoleCommandHandler {
114
- return new ConsoleCommandHandler(this.manager, execute);
115
- }
116
-
117
- }
118
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
119
- export type ConsoleExecuteFunction = (console: ConsoleWidget, ...args: any[]) => any;
120
- export class ConsoleCommandHandler implements CommandHandler {
121
-
122
- constructor(
123
- protected readonly manager: ConsoleManager,
124
- protected readonly doExecute: ConsoleExecuteFunction
125
- ) { }
126
-
127
- isEnabled(): boolean {
128
- return !!this.manager.currentConsole;
129
- }
130
-
131
- isVisible(): boolean {
132
- return !!this.manager.currentConsole;
133
- }
134
-
135
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
- execute(...args: any[]): any {
137
- const { currentConsole } = this.manager;
138
- if (currentConsole) {
139
- return this.doExecute(currentConsole, ...args);
140
- }
141
- }
142
-
143
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject } from '@theia/core/shared/inversify';
18
+ import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry, CommandHandler } from '@theia/core';
19
+ import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegistry, CommonCommands } from '@theia/core/lib/browser';
20
+ import { ConsoleManager } from './console-manager';
21
+ import { ConsoleWidget } from './console-widget';
22
+ import { ConsoleContentWidget } from './console-content-widget';
23
+ import { nls } from '@theia/core/lib/common/nls';
24
+
25
+ export namespace ConsoleCommands {
26
+ export const SELECT_ALL: Command = {
27
+ id: 'console.selectAll'
28
+ };
29
+ export const COLLAPSE_ALL: Command = {
30
+ id: 'console.collapseAll'
31
+ };
32
+ export const CLEAR: Command = {
33
+ id: 'console.clear'
34
+ };
35
+ export const EXECUTE: Command = {
36
+ id: 'console.execute'
37
+ };
38
+ export const NAVIGATE_BACK: Command = {
39
+ id: 'console.navigatePrevious'
40
+ };
41
+ export const NAVIGATE_FORWARD: Command = {
42
+ id: 'console.navigateNext'
43
+ };
44
+ }
45
+
46
+ export namespace ConsoleContextMenu {
47
+ export const CLIPBOARD = [...ConsoleContentWidget.CONTEXT_MENU, '1_clipboard'];
48
+ export const CLEAR = [...ConsoleContentWidget.CONTEXT_MENU, '2_clear'];
49
+ }
50
+
51
+ @injectable()
52
+ export class ConsoleContribution implements FrontendApplicationContribution, CommandContribution, KeybindingContribution, MenuContribution {
53
+
54
+ @inject(ConsoleManager)
55
+ protected readonly manager: ConsoleManager;
56
+
57
+ initialize(): void { }
58
+
59
+ registerCommands(commands: CommandRegistry): void {
60
+ commands.registerCommand(ConsoleCommands.SELECT_ALL, this.newCommandHandler(console => console.selectAll()));
61
+ commands.registerCommand(ConsoleCommands.COLLAPSE_ALL, this.newCommandHandler(console => console.collapseAll()));
62
+ commands.registerCommand(ConsoleCommands.CLEAR, this.newCommandHandler(console => console.clear()));
63
+ commands.registerCommand(ConsoleCommands.EXECUTE, this.newCommandHandler(console => console.execute()));
64
+ commands.registerCommand(ConsoleCommands.NAVIGATE_BACK, this.newCommandHandler(console => console.navigateBack()));
65
+ commands.registerCommand(ConsoleCommands.NAVIGATE_FORWARD, this.newCommandHandler(console => console.navigateForward()));
66
+ }
67
+
68
+ registerKeybindings(keybindings: KeybindingRegistry): void {
69
+ keybindings.registerKeybinding({
70
+ command: ConsoleCommands.SELECT_ALL.id,
71
+ keybinding: 'ctrlcmd+a',
72
+ when: 'consoleContentFocus'
73
+ });
74
+ keybindings.registerKeybinding({
75
+ command: ConsoleCommands.EXECUTE.id,
76
+ keybinding: 'enter',
77
+ when: 'consoleInputFocus'
78
+ });
79
+ keybindings.registerKeybinding({
80
+ command: ConsoleCommands.NAVIGATE_BACK.id,
81
+ keybinding: 'up',
82
+ when: 'consoleInputFocus && consoleNavigationBackEnabled'
83
+ });
84
+ keybindings.registerKeybinding({
85
+ command: ConsoleCommands.NAVIGATE_FORWARD.id,
86
+ keybinding: 'down',
87
+ when: 'consoleInputFocus && consoleNavigationForwardEnabled'
88
+ });
89
+ }
90
+
91
+ registerMenus(menus: MenuModelRegistry): void {
92
+ menus.registerMenuAction(ConsoleContextMenu.CLIPBOARD, {
93
+ commandId: CommonCommands.COPY.id,
94
+ label: CommonCommands.COPY.label,
95
+ order: 'a1',
96
+ });
97
+ menus.registerMenuAction(ConsoleContextMenu.CLIPBOARD, {
98
+ commandId: ConsoleCommands.SELECT_ALL.id,
99
+ label: CommonCommands.SELECT_ALL.label,
100
+ order: 'a2'
101
+ });
102
+ menus.registerMenuAction(ConsoleContextMenu.CLIPBOARD, {
103
+ commandId: ConsoleCommands.COLLAPSE_ALL.id,
104
+ label: nls.localizeByDefault('Collapse All'),
105
+ order: 'a3'
106
+ });
107
+ menus.registerMenuAction(ConsoleContextMenu.CLEAR, {
108
+ commandId: ConsoleCommands.CLEAR.id,
109
+ label: nls.localizeByDefault('Clear Console')
110
+ });
111
+ }
112
+
113
+ protected newCommandHandler(execute: ConsoleExecuteFunction): ConsoleCommandHandler {
114
+ return new ConsoleCommandHandler(this.manager, execute);
115
+ }
116
+
117
+ }
118
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
119
+ export type ConsoleExecuteFunction = (console: ConsoleWidget, ...args: any[]) => any;
120
+ export class ConsoleCommandHandler implements CommandHandler {
121
+
122
+ constructor(
123
+ protected readonly manager: ConsoleManager,
124
+ protected readonly doExecute: ConsoleExecuteFunction
125
+ ) { }
126
+
127
+ isEnabled(): boolean {
128
+ return !!this.manager.currentConsole;
129
+ }
130
+
131
+ isVisible(): boolean {
132
+ return !!this.manager.currentConsole;
133
+ }
134
+
135
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
+ execute(...args: any[]): any {
137
+ const { currentConsole } = this.manager;
138
+ if (currentConsole) {
139
+ return this.doExecute(currentConsole, ...args);
140
+ }
141
+ }
142
+
143
+ }