mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 13:07:58 +00:00
Add option to save shell output
This commit is contained in:
parent
82b8f1e300
commit
773bcf65fd
@ -3,7 +3,7 @@
|
||||
import CodeEditor from '$components/editors/codeeditor.svelte';
|
||||
import Icon from '$components/icon.svelte';
|
||||
import environment from '$lib/stores/environment.js';
|
||||
import { OpenShellScript, SaveShellScript } from '$wails/go/app/App.js';
|
||||
import { OpenShellScript, SaveShellScript, SaveShellOuput } from '$wails/go/app/App.js';
|
||||
import { BrowserOpenURL } from '$wails/runtime/runtime.js';
|
||||
import { javascript } from '@codemirror/lang-javascript';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
@ -73,6 +73,10 @@
|
||||
);
|
||||
}
|
||||
|
||||
async function saveOutput() {
|
||||
await SaveShellOuput(result.output + '\n' + result.stderr);
|
||||
}
|
||||
|
||||
async function copyErrorDescription() {
|
||||
await navigator.clipboard.writeText(result.errorDescription);
|
||||
copySucceeded = true;
|
||||
@ -155,6 +159,10 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button class="button secondary" disabled={!result.output} on:click={saveOutput}>
|
||||
<Icon name="upload" /> Save output as…
|
||||
</button>
|
||||
|
||||
<button class="button viewtoggle" title="Toggle horizontal/vertical view" on:click={toggleView}>
|
||||
<Icon name="columns" rotation={horizontal ? 90 : 0} />
|
||||
</button>
|
||||
|
2
frontend/wailsjs/go/app/App.d.ts
generated
vendored
2
frontend/wailsjs/go/app/App.d.ts
generated
vendored
@ -72,6 +72,8 @@ export function ReportSharedStateVariable(arg1:string,arg2:string):Promise<void>
|
||||
|
||||
export function SaveQuery(arg1:string):Promise<string>;
|
||||
|
||||
export function SaveShellOuput(arg1:string):Promise<void>;
|
||||
|
||||
export function SaveShellScript(arg1:string,arg2:string,arg3:string,arg4:string,arg5:boolean):Promise<app.SaveShellScriptResult>;
|
||||
|
||||
export function SavedQueries():Promise<map[string]app.SavedQuery>;
|
||||
|
4
frontend/wailsjs/go/app/App.js
generated
4
frontend/wailsjs/go/app/App.js
generated
@ -134,6 +134,10 @@ export function SaveQuery(arg1) {
|
||||
return window['go']['app']['App']['SaveQuery'](arg1);
|
||||
}
|
||||
|
||||
export function SaveShellOuput(arg1) {
|
||||
return window['go']['app']['App']['SaveShellOuput'](arg1);
|
||||
}
|
||||
|
||||
export function SaveShellScript(arg1, arg2, arg3, arg4, arg5) {
|
||||
return window['go']['app']['App']['SaveShellScript'](arg1, arg2, arg3, arg4, arg5);
|
||||
}
|
||||
|
@ -182,3 +182,30 @@ func (a *App) OpenShellScript() string {
|
||||
|
||||
return string(script)
|
||||
}
|
||||
|
||||
func (a *App) SaveShellOuput(output string) {
|
||||
fname, err := runtime.SaveFileDialog(a.ctx, runtime.SaveDialogOptions{
|
||||
DefaultFilename: "mongosh-output.txt",
|
||||
DefaultDirectory: a.Env.DownloadDirectory,
|
||||
Title: "Save mongosh output",
|
||||
CanCreateDirectories: true,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
runtime.LogWarningf(a.ctx, "Shell: error exporting output to %s: %s", fname, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Error exporting output",
|
||||
Message: err.Error(),
|
||||
Type: runtime.ErrorDialog,
|
||||
})
|
||||
}
|
||||
|
||||
if err := os.WriteFile(fname, []byte(output), os.ModePerm); err != nil {
|
||||
runtime.LogWarningf(a.ctx, "Shell: error writing shell output to %s: %s", fname, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Error writing shell output",
|
||||
Message: err.Error(),
|
||||
Type: runtime.ErrorDialog,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user