From b119146b93a2fc027f9d0783695dabc63df822bd Mon Sep 17 00:00:00 2001 From: Cocoa Date: Mon, 30 Sep 2024 02:27:18 +0100 Subject: [PATCH] show exit code Signed-off-by: Cocoa --- lib/assets/base.js | 35 +---------------------------------- lib/assets/main.css | 13 ++++++++++--- lib/assets/main.js | 16 +++++++++++++++- lib/expty_smartcell.ex | 12 ++++++++++++ 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/assets/base.js b/lib/assets/base.js index b668bdc..e05289a 100644 --- a/lib/assets/base.js +++ b/lib/assets/base.js @@ -144,40 +144,7 @@ const BaseInput = { `, }; -const SmartCellConfig = (ctx, info, extra_components, extra_data) => { - return { - components: { - BaseInput: BaseInput, - BaseSelect: BaseSelect, - ...extra_components - }, - - data() { - return { - fields: info.fields, - ...extra_data - }; - }, - - methods: { - handleFieldChange(event) { - const { name: field, value } = event.target; - - if (field) { - if (info.id == "evision.zoo") { - ctx.pushEvent("update_field", { field, value }); - } else { - const sub_value = field.split(".").reduce((data, key) => data[key], this.fields); - ctx.pushEvent("update_field", { field, value: sub_value }); - } - } - }, - } - } -}; - export const Base = { BaseInput: BaseInput, - BaseSelect: BaseSelect, - SmartCellConfig: SmartCellConfig + BaseSelect: BaseSelect }; diff --git a/lib/assets/main.css b/lib/assets/main.css index b3dbd54..f1e8306 100644 --- a/lib/assets/main.css +++ b/lib/assets/main.css @@ -61,12 +61,16 @@ button { .header { display: flex; + flex-wrap: wrap; + align-items: stretch; justify-content: flex-start; background-color: var(--blue-100); padding: 8px 16px; - margin-bottom: 12px; - border-radius: 0.5rem 0.5rem 0 0; + border-left: solid 1px var(--gray-300); + border-top: solid 1px var(--gray-300); + border-right: solid 1px var(--gray-300); border-bottom: solid 1px var(--gray-200); + border-radius: 0.5rem 0.5rem 0 0; gap: 16px; } @@ -129,7 +133,10 @@ input[required].empty { font-weight: 500; padding-right: 6px; font-size: 0.875rem; - text-transform: uppercase; +} + +.inline-status-label { + padding: 8px 0px; } .input-label-tooltip { diff --git a/lib/assets/main.js b/lib/assets/main.js index 7f75e06..05e19f7 100644 --- a/lib/assets/main.js +++ b/lib/assets/main.js @@ -64,9 +64,12 @@ export async function init(ctx, info) { placeholder="/bin/bash" v-model="fields.executable" inputClass="input input--xs" - :grow + :inline :required /> +
+ +
@@ -83,6 +86,7 @@ export async function init(ctx, info) { const button = ctx.root.querySelector("[data-start-stop-button]"); const classList = button.classList; const terminalEl = ctx.root.querySelector('#terminal'); + const statusEl = ctx.root.querySelector("[data-el-status-label]"); if (classList.contains("ri-stop-line")) { ctx.pushEvent("stop_executable"); button.classList.remove("ri-stop-line"); @@ -109,6 +113,8 @@ export async function init(ctx, info) { term.clear() } + statusEl.innerText = ``; + fit_addon.fit() resizeObserver = new ResizeObserver((entries) => { try { @@ -150,6 +156,14 @@ export async function init(ctx, info) { term.write(Uint8Array.from(atob(data), c => c.charCodeAt(0))) }) + ctx.handleEvent("executable_exited", ({ code }) => { + const status = ctx.root.querySelector("[data-el-status-label]"); + status.innerText = `Process exited with code ${code}`; + const button = ctx.root.querySelector("[data-start-stop-button]"); + button.classList.remove("ri-stop-line"); + button.classList.add("ri-play-line"); + }) + ctx.handleSync(() => { // Synchronously invokes change listeners document.activeElement && diff --git a/lib/expty_smartcell.ex b/lib/expty_smartcell.ex index 7735a58..fbb2801 100644 --- a/lib/expty_smartcell.ex +++ b/lib/expty_smartcell.ex @@ -17,6 +17,7 @@ else assign(ctx, executable: executable, pty: nil, + pty_ref: nil, started?: false ) @@ -55,6 +56,12 @@ else broadcast_event(ctx, "data", %{data: Base.encode64(data)}) end) + self = self() + + ExPTY.on_exit(pty, fn _, _, exit_code, _ -> + Process.send_after(self, {:executable_exited, exit_code}, 0) + end) + {:noreply, assign(ctx, pty: pty, @@ -107,6 +114,11 @@ else {:noreply, ctx} end + def handle_info({:executable_exited, code}, ctx) do + broadcast_event(ctx, "executable_exited", %{code: code}) + {:noreply, assign(ctx, pty: nil, pty_ref: nil, started?: false)} + end + @impl true def terminate(_, ctx) do stop_executable(ctx)