Skip to content

Commit

Permalink
feat: add interactivity shell
Browse files Browse the repository at this point in the history
  • Loading branch information
whoamizzz committed Dec 1, 2023
1 parent b2f2662 commit c217511
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/PanelTerminalClient.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const terminal = new Terminal({
theme: theme.value,
fontFamily: 'DM Mono, monospace',
})
play.terminal = terminal
watch(
() => theme.value,
Expand Down
14 changes: 14 additions & 0 deletions composables/web-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,22 @@ export async function mountPlayground(
play.status = 'start'
processDev = await wc.spawn('pnpm', ['run', 'dev', '--no-qr'])
play.stream = processDev.output
addInteractivity()
}

async function addInteractivity() {
const shellProcess = await wc.spawn('jsh')
play.stream = shellProcess.output
const input = shellProcess.input.getWriter()
play.terminal?.onData((data) => {
// Ctrl+C to kill the process
if (data.charCodeAt(0) === 3)
processDev?.kill()

input.write(data)
})
};

async function downloadZip() {
const { default: JSZip } = await import('jszip')
const zip = new JSZip()
Expand Down
3 changes: 3 additions & 0 deletions stores/playground.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Raw } from 'vue'
import type { WebContainer } from '@webcontainer/api'
import type { Terminal } from 'xterm'
import type { VirtualFile } from '../structures/VirtualFile'

export const PlaygroundStatusOrder = [
Expand All @@ -23,6 +24,7 @@ export const usePlaygroundStore = defineStore('playground', () => {
const stream = shallowRef<ReadableStream>()
const files = shallowRef<Raw<VirtualFile>[]>([])
const webcontainer = shallowRef<Raw<WebContainer>>()
const terminal = shallowRef<Raw<Terminal>>()

const previewLocation = ref({
origin: '',
Expand All @@ -45,6 +47,7 @@ export const usePlaygroundStore = defineStore('playground', () => {
previewUrl,
previewLocation,
actions,
terminal,
}
})

Expand Down

0 comments on commit c217511

Please sign in to comment.