From b27452970771ef1f220b816be48a5755e19684ad Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Thu, 17 Oct 2024 21:52:17 -0400 Subject: [PATCH] Add view output action Signed-off-by: Sanjula Ganepola --- package.json | 22 +++++++++++++++++--- src/act.ts | 12 +++++++++++ src/views/history/historyTreeDataProvider.ts | 3 +++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7689925..a12c06e 100644 --- a/package.json +++ b/package.json @@ -202,6 +202,13 @@ "title": "Refresh", "icon": "$(refresh)" }, + { + "category": "GitHub Local Actions", + "command": "githubLocalActions.viewOutput", + "title": "View Output", + "enablement": "viewItem =~ /^githubLocalActions.history_(Success|Failed|Cancelled).*/", + "icon": "$(book)" + }, { "category": "GitHub Local Actions", "command": "githubLocalActions.restart", @@ -280,6 +287,10 @@ "command": "githubLocalActions.refreshHistory", "when": "never" }, + { + "command": "githubLocalActions.viewOutput", + "when": "never" + }, { "command": "githubLocalActions.restart", "when": "never" @@ -366,19 +377,24 @@ "group": "inline@0" }, { - "command": "githubLocalActions.restart", + "command": "githubLocalActions.viewOutput", "when": "view == history && viewItem =~ /^githubLocalActions.history.*/", "group": "inline@0" }, { - "command": "githubLocalActions.stop", + "command": "githubLocalActions.restart", "when": "view == history && viewItem =~ /^githubLocalActions.history.*/", "group": "inline@1" }, { - "command": "githubLocalActions.remove", + "command": "githubLocalActions.stop", "when": "view == history && viewItem =~ /^githubLocalActions.history.*/", "group": "inline@2" + }, + { + "command": "githubLocalActions.remove", + "when": "view == history && viewItem =~ /^githubLocalActions.history.*/", + "group": "inline@3" } ] }, diff --git a/src/act.ts b/src/act.ts index a15b2f5..0283b26 100644 --- a/src/act.ts +++ b/src/act.ts @@ -240,6 +240,14 @@ export class Act { const writeEmitter = new EventEmitter(); const closeEmitter = new EventEmitter(); + writeEmitter.event(data => { + if (!this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].output) { + this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].output = data; + } else { + this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].output += data; + } + }); + const exec = child_process.spawn(command, { cwd: commandArgs.workspaceFolder.uri.fsPath, shell: env.shell }); const handleIO = (data: any) => { const lines: string[] = data.toString().split('\n').filter((line: string) => line != ''); @@ -354,6 +362,10 @@ export class Act { } } + async viewOutput(history: History) { + await workspace.openTextDocument({ content: history.output }); + } + async stop(history: History) { history.taskExecution?.terminate(); historyTreeDataProvider.refresh(); diff --git a/src/views/history/historyTreeDataProvider.ts b/src/views/history/historyTreeDataProvider.ts index 280d55b..5ab5fdd 100644 --- a/src/views/history/historyTreeDataProvider.ts +++ b/src/views/history/historyTreeDataProvider.ts @@ -21,6 +21,9 @@ export default class HistoryTreeDataProvider implements TreeDataProvider { this.refresh(); }), + commands.registerCommand('githubLocalActions.viewOutput', async (historyTreeItem: HistoryTreeItem) => { + await act.viewOutput(historyTreeItem.history); + }), commands.registerCommand('githubLocalActions.restart', async (historyTreeItem: HistoryTreeItem) => { await act.runCommand(historyTreeItem.history.commandArgs); }),