[Electron] xterm startup logs (#1620)

* Add live terminal output

* Fix scrolling

* Refactor loading

* Fallback to polling if endpoint fails

* Comment

* Move clientId to executionStore
Refactor types

* Remove polling

* wip terminal command input

* Refactor to use node-pty

* Hide tabs if not electron

* Lint fix

* ts fix

* Refactor tab components

* Use xterm for startup logs

* Nicer logs display

* Fix not setting xterm + mark terminal as raw
This commit is contained in:
pythongosssss
2024-11-20 21:09:54 +00:00
committed by GitHub
parent f34d50da3d
commit d5b8a555d9
2 changed files with 33 additions and 17 deletions

View File

@@ -1,14 +1,16 @@
import { FitAddon } from '@xterm/addon-fit' import { FitAddon } from '@xterm/addon-fit'
import { Terminal } from '@xterm/xterm' import { Terminal } from '@xterm/xterm'
import { debounce } from 'lodash' import { debounce } from 'lodash'
import { onMounted, onUnmounted, Ref } from 'vue' import { markRaw, onMounted, onUnmounted, Ref } from 'vue'
import '@xterm/xterm/css/xterm.css' import '@xterm/xterm/css/xterm.css'
export function useTerminal(element: Ref<HTMLElement>) { export function useTerminal(element: Ref<HTMLElement>) {
const fitAddon = new FitAddon() const fitAddon = new FitAddon()
const terminal = new Terminal({ const terminal = markRaw(
convertEol: true new Terminal({
}) convertEol: true
})
)
terminal.loadAddon(fitAddon) terminal.loadAddon(fitAddon)
onMounted(async () => { onMounted(async () => {

View File

@@ -3,42 +3,56 @@
class="font-sans flex flex-col justify-center items-center h-screen m-0 text-neutral-300 bg-neutral-900 dark-theme pointer-events-auto" class="font-sans flex flex-col justify-center items-center h-screen m-0 text-neutral-300 bg-neutral-900 dark-theme pointer-events-auto"
> >
<h2 class="text-2xl font-bold">{{ ProgressMessages[status] }}</h2> <h2 class="text-2xl font-bold">{{ ProgressMessages[status] }}</h2>
<LogTerminal :fetch-logs="fetchLogs" :fetch-interval="500" /> <BaseTerminal @created="terminalCreated" />
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue' import { ref, onMounted, Ref } from 'vue'
import LogTerminal from '@/components/common/LogTerminal.vue' import BaseTerminal from '@/components/bottomPanel/tabs/terminal/BaseTerminal.vue'
import { import {
ProgressStatus, ProgressStatus,
ProgressMessages ProgressMessages
} from '@comfyorg/comfyui-electron-types' } from '@comfyorg/comfyui-electron-types'
import { electronAPI } from '@/utils/envUtil' import { electronAPI } from '@/utils/envUtil'
import type { useTerminal } from '@/hooks/bottomPanelTabs/useTerminal'
import { Terminal } from '@xterm/xterm'
const electron = electronAPI() const electron = electronAPI()
const status = ref<ProgressStatus>(ProgressStatus.INITIAL_STATE) const status = ref<ProgressStatus>(ProgressStatus.INITIAL_STATE)
const logs = ref<string[]>([]) let xterm: Terminal | undefined
const updateProgress = ({ status: newStatus }: { status: ProgressStatus }) => { const updateProgress = ({ status: newStatus }: { status: ProgressStatus }) => {
status.value = newStatus status.value = newStatus
logs.value = [] // Clear logs when status changes xterm?.clear()
} }
const addLogMessage = (message: string) => { const terminalCreated = (
logs.value = [...logs.value, message] { terminal, useAutoSize }: ReturnType<typeof useTerminal>,
} root: Ref<HTMLElement>
) => {
xterm = terminal
const fetchLogs = async () => { useAutoSize(root, true, true)
return logs.value.join('\n') electron.onLogMessage((message: string) => {
terminal.write(message)
})
terminal.options.cursorBlink = false
terminal.options.disableStdin = true
terminal.options.cursorInactiveStyle = 'block'
} }
onMounted(() => { onMounted(() => {
electron.sendReady() electron.sendReady()
electron.onProgressUpdate(updateProgress) electron.onProgressUpdate(updateProgress)
electron.onLogMessage((message: string) => {
addLogMessage(message)
})
}) })
</script> </script>
<style scoped>
:deep(.xterm-helper-textarea) {
/* Hide this as it moves all over when uv is running */
display: none;
}
</style>