-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import nested from 'postcss-nested' | ||
import postcssScss from 'postcss-scss' | ||
|
||
export default { | ||
parser: postcssScss, | ||
plugins: [nested], | ||
} |
24 changes: 24 additions & 0 deletions
24
src/components/Device/components/Terminal/components/TerminalDialog/composables/adb.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createStderr, createStdout } from 'vue-command' | ||
|
||
const $adb = window.adbkit | ||
|
||
export function useAdb({ loading }) { | ||
const adb = async (args) => { | ||
loading.value = true | ||
const command = args.slice(1).join(' ') | ||
|
||
const { stderr, stdout } = await $adb.shell(command || 'help') | ||
|
||
if (stderr) { | ||
return createStderr(stderr) | ||
} | ||
|
||
loading.value = false | ||
|
||
return createStdout(stdout) | ||
} | ||
|
||
return { | ||
adb, | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/components/Device/components/Terminal/components/TerminalDialog/composables/gnirehtet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { debounce } from 'lodash-es' | ||
import { createStderr, createStdout, textFormatter } from 'vue-command' | ||
|
||
const $gnirehtet = window.gnirehtet | ||
|
||
const fixCursor = (history) => { | ||
const length = history.value.length | ||
if (history.value[length - 1]?.__name === 'VueCommandQuery') { | ||
history.value.splice(length - 1, 1, textFormatter('Waiting...')) | ||
} | ||
} | ||
|
||
export function useGnirehtet({ vShell, history, loading } = {}) { | ||
const gnirehtet = async (args) => { | ||
loading.value = true | ||
|
||
const command = args.slice(1).join(' ') | ||
|
||
const appendToHistory = debounce(vShell.value.appendToHistory, 500) | ||
|
||
let stdoutText = '' | ||
let stderrText = '' | ||
$gnirehtet.shell(command, { | ||
stdout(text) { | ||
loading.value = false | ||
|
||
stdoutText += text | ||
|
||
fixCursor(history) | ||
|
||
appendToHistory(createStdout(stdoutText)) | ||
}, | ||
stderr(text) { | ||
loading.value = false | ||
|
||
stderrText += text | ||
|
||
fixCursor(history) | ||
|
||
appendToHistory(createStderr(stderrText)) | ||
}, | ||
}) | ||
|
||
return textFormatter('Loading...') | ||
} | ||
|
||
return { | ||
gnirehtet, | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/components/Device/components/Terminal/components/TerminalDialog/composables/scrcpy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { debounce } from 'lodash-es' | ||
import { createStderr, createStdout, textFormatter } from 'vue-command' | ||
|
||
const $scrcpy = window.scrcpy | ||
|
||
const fixCursor = (history) => { | ||
const length = history.value.length | ||
if (history.value[length - 1]?.__name === 'VueCommandQuery') { | ||
history.value.splice(length - 1, 1, textFormatter('Waiting...')) | ||
} | ||
} | ||
|
||
export function useScrcpy({ vShell, history, loading } = {}) { | ||
const scrcpy = async (args) => { | ||
loading.value = true | ||
|
||
const command = args.slice(1).join(' ') | ||
|
||
const appendToHistory = debounce(vShell.value.appendToHistory, 500) | ||
|
||
let stdoutText = '' | ||
let stderrText = '' | ||
$scrcpy.shell(command, { | ||
stdout(text) { | ||
loading.value = false | ||
|
||
stdoutText += text | ||
|
||
fixCursor(history) | ||
|
||
appendToHistory(createStdout(stdoutText)) | ||
}, | ||
stderr(text) { | ||
loading.value = false | ||
|
||
stderrText += text | ||
|
||
fixCursor(history) | ||
|
||
appendToHistory(createStderr(stderrText)) | ||
}, | ||
}) | ||
|
||
return textFormatter('Loading...') | ||
} | ||
|
||
return { | ||
scrcpy, | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
src/components/Device/components/Terminal/components/TerminalDialog/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<template> | ||
<el-dialog | ||
v-model="visible" | ||
width="80%" | ||
:close-on-click-modal="false" | ||
:close-on-press-escape="false" | ||
class="overflow-hidden rounded-xl el-dialog-headless" | ||
@open="onOpen" | ||
> | ||
<el-icon | ||
class="cursor-pointer absolute top-2 right-2 w-8 h-8 flex items-center justify-center text-gray-200 hover:bg-gray-700 !active:bg-red-600 rounded" | ||
@click="hide" | ||
> | ||
<CloseBold /> | ||
</el-icon> | ||
|
||
<VueCommand | ||
v-if="visible" | ||
:ref="(value) => (vShell = value)" | ||
v-model:history="history" | ||
:commands="commands" | ||
hide-bar | ||
show-help | ||
help-text="Type in help" | ||
:help-timeout="3500" | ||
class="" | ||
:dispatched-queries="dispatchedQueries" | ||
> | ||
<template #prompt> | ||
<div class="flex items-center pr-2"> | ||
<span class="">escrcpy~$</span> | ||
</div> | ||
</template> | ||
</VueCommand> | ||
</el-dialog> | ||
</template> | ||
|
||
<script> | ||
import { ref } from 'vue' | ||
import VueCommand, { | ||
createQuery, | ||
createStdout, | ||
listFormatter, | ||
} from 'vue-command' | ||
import 'vue-command/dist/vue-command.css' | ||
import { useAdb } from './composables/adb.js' | ||
import { useScrcpy } from './composables/scrcpy.js' | ||
import { useGnirehtet } from './composables/gnirehtet.js' | ||
export default { | ||
components: { | ||
VueCommand, | ||
}, | ||
setup() { | ||
const vShell = ref(null) | ||
const history = ref([createQuery()]) | ||
const loading = ref(false) | ||
const dispatchedQueries = ref(new Set([])) | ||
const { adb } = useAdb({ vShell, history, loading }) | ||
const { scrcpy } = useScrcpy({ vShell, history, loading }) | ||
const { gnirehtet } = useGnirehtet({ vShell, history, loading }) | ||
const commands = ref({ | ||
adb, | ||
scrcpy, | ||
gnirehtet, | ||
clear() { | ||
history.value = [] | ||
return createQuery() | ||
}, | ||
}) | ||
commands.value.help = () => { | ||
const commandList = Object.keys(commands.value) | ||
return createStdout(listFormatter('Supported Commands:', ...commandList)) | ||
} | ||
dispatchedQueries.value = new Set(Object.keys(commands.value)) | ||
return { | ||
vShell, | ||
loading, | ||
history, | ||
commands, | ||
dispatchedQueries, | ||
} | ||
}, | ||
data() { | ||
return { | ||
visible: false, | ||
} | ||
}, | ||
methods: { | ||
show() { | ||
this.visible = true | ||
}, | ||
hide() { | ||
this.visible = false | ||
}, | ||
async onOpen() { | ||
console.log('vShell', this.vShell) | ||
this.vShell.signals.off('SIGINT') | ||
this.vShell.signals.on('SIGINT', () => { | ||
console.log('vShell.signals.on.SIGINT') | ||
this.$gnirehtet.shell('stop') | ||
}) | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<template> | ||
<div class=""> | ||
<slot :show="show" /> | ||
<TerminalDialog ref="terminalDialog" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import TerminalDialog from './components/TerminalDialog/index.vue' | ||
export default { | ||
components: { | ||
TerminalDialog, | ||
}, | ||
methods: { | ||
show() { | ||
this.$refs.terminalDialog.show() | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters