Skip to content

Commit

Permalink
add copy to clipboard button for command/script output
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jul 12, 2024
1 parent e1dc75e commit 0c89e58
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/components/checks/ScriptOutput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
</div>
<br />
<div v-if="scriptInfo.stdout">
Standard Output
<script-output-copy-clip
label="Standard Output"
:data="scriptInfo.stdout"
/>
<q-separator />
<pre>{{ scriptInfo.stdout }}</pre>
</div>
<div v-if="scriptInfo.stderr">
Standard Error
<script-output-copy-clip
label="Standard Error"
:data="scriptInfo.stderr"
/>
<q-separator />
<pre>{{ scriptInfo.stderr }}</pre>
</div>
Expand All @@ -43,8 +49,13 @@ import { computed } from "vue";
import { useStore } from "vuex";
import { useDialogPluginComponent } from "quasar";
import ScriptOutputCopyClip from "@/components/scripts/ScriptOutputCopyClip.vue";
export default {
name: "ScriptOutput",
components: {
ScriptOutputCopyClip,
},
emits: [...useDialogPluginComponent.emits],
props: { scriptInfo: !Object },
setup() {
Expand Down
3 changes: 3 additions & 0 deletions src/components/modals/agents/RunScript.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
class="q-pl-md q-pr-md q-pt-none q-ma-none scroll"
style="max-height: 50vh"
>
<script-output-copy-clip label="Output" :data="ret" />
<q-separator />
<pre>{{ ret }}</pre>
</q-card-section>
</q-form>
Expand All @@ -195,6 +197,7 @@ import { formatScriptSyntax } from "@/utils/format";
//ui imports
import TacticalDropdown from "@/components/ui/TacticalDropdown.vue";
import ScriptOutputCopyClip from "@/components/scripts/ScriptOutputCopyClip.vue";
// types
import type { Agent } from "@/types/agents";
Expand Down
8 changes: 8 additions & 0 deletions src/components/modals/agents/SendCommand.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
type="submit"
/>
</q-card-actions>
<q-card-section v-if="ret !== null"
><script-output-copy-clip label="Output" :data="ret" /> <q-separator
/></q-card-section>
<q-card-section
v-if="ret !== null"
class="q-pl-md q-pr-md q-pt-none q-ma-none scroll"
Expand All @@ -124,8 +127,13 @@ import { sendAgentCommand } from "@/api/agents";
import { cmdPlaceholder } from "@/composables/agents";
import { runAsUserToolTip } from "@/constants/constants";
import ScriptOutputCopyClip from "@/components/scripts/ScriptOutputCopyClip.vue";
export default {
name: "SendCommand",
components: {
ScriptOutputCopyClip,
},
emits: [...useDialogPluginComponent.emits],
props: {
agent: !Object,
Expand Down
26 changes: 26 additions & 0 deletions src/components/scripts/ScriptOutputCopyClip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<div class="row q-gutter-sm items-center">
<div class="col-auto">{{ label }}</div>
<div class="col-auto">
<q-btn dense flat size="md" icon="content_copy" @click="copyText">
<q-tooltip>Copy to Clipboard</q-tooltip>
</q-btn>
</div>
</div>
</template>

<script setup lang="ts">
import { copyOutput } from "@/utils/helpers";
const props = defineProps({
label: String,
data: {
type: String,
required: true,
},
});
const copyText = () => {
copyOutput(props.data);
};
</script>
8 changes: 6 additions & 2 deletions src/components/scripts/TestScriptModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
</div>
<br />
<div v-if="ret.stdout">
Standard Output
<script-output-copy-clip label="Standard Output" :data="ret.stdout" />
<q-separator />
<pre>{{ ret.stdout }}</pre>
</div>
<div v-if="ret.stderr">
Standard Error
<script-output-copy-clip label="Standard Error" :data="ret.stderr" />
<q-separator />
<pre>{{ ret.stderr }}</pre>
</div>
Expand All @@ -38,9 +38,13 @@
import { ref, onMounted } from "vue";
import { testScript, testScriptOnServer } from "@/api/scripts";
import { useDialogPluginComponent } from "quasar";
import ScriptOutputCopyClip from "@/components/scripts/ScriptOutputCopyClip.vue";
export default {
name: "TestScriptModal",
components: {
ScriptOutputCopyClip,
},
emits: [...useDialogPluginComponent.emits],
props: {
script: !Object,
Expand Down
8 changes: 8 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { copyToClipboard } from "quasar";
import { notifySuccess } from "@/utils/notify";

export function copyOutput(val: string) {
copyToClipboard(val).then(() => {
notifySuccess("Copied to clipboard");
});
}

0 comments on commit 0c89e58

Please sign in to comment.