Skip to content

Commit

Permalink
show exit code
Browse files Browse the repository at this point in the history
Signed-off-by: Cocoa <[email protected]>
  • Loading branch information
cocoa-xu committed Sep 30, 2024
1 parent 5bc0cf7 commit b119146
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
35 changes: 1 addition & 34 deletions lib/assets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
13 changes: 10 additions & 3 deletions lib/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion lib/assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ export async function init(ctx, info) {
placeholder="/bin/bash"
v-model="fields.executable"
inputClass="input input--xs"
:grow
:inline
:required
/>
<div class="inline-field grow">
<label class="inline-input-label inline-status-label" data-el-status-label></label>
</div>
<button id="start-stop-button" @click="start_stop_executable" class="icon-button">
<i class="ri ri-play-line" data-start-stop-button></i>
</button>
Expand All @@ -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");
Expand All @@ -109,6 +113,8 @@ export async function init(ctx, info) {
term.clear()
}

statusEl.innerText = ``;

fit_addon.fit()
resizeObserver = new ResizeObserver((entries) => {
try {
Expand Down Expand Up @@ -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 &&
Expand Down
12 changes: 12 additions & 0 deletions lib/expty_smartcell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ else
assign(ctx,
executable: executable,
pty: nil,
pty_ref: nil,
started?: false
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b119146

Please sign in to comment.