Skip to content

Commit b119146

Browse files
committed
show exit code
Signed-off-by: Cocoa <i@uwucocoa.moe>
1 parent 5bc0cf7 commit b119146

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

lib/assets/base.js

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -144,40 +144,7 @@ const BaseInput = {
144144
`,
145145
};
146146

147-
const SmartCellConfig = (ctx, info, extra_components, extra_data) => {
148-
return {
149-
components: {
150-
BaseInput: BaseInput,
151-
BaseSelect: BaseSelect,
152-
...extra_components
153-
},
154-
155-
data() {
156-
return {
157-
fields: info.fields,
158-
...extra_data
159-
};
160-
},
161-
162-
methods: {
163-
handleFieldChange(event) {
164-
const { name: field, value } = event.target;
165-
166-
if (field) {
167-
if (info.id == "evision.zoo") {
168-
ctx.pushEvent("update_field", { field, value });
169-
} else {
170-
const sub_value = field.split(".").reduce((data, key) => data[key], this.fields);
171-
ctx.pushEvent("update_field", { field, value: sub_value });
172-
}
173-
}
174-
},
175-
}
176-
}
177-
};
178-
179147
export const Base = {
180148
BaseInput: BaseInput,
181-
BaseSelect: BaseSelect,
182-
SmartCellConfig: SmartCellConfig
149+
BaseSelect: BaseSelect
183150
};

lib/assets/main.css

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ button {
6161

6262
.header {
6363
display: flex;
64+
flex-wrap: wrap;
65+
align-items: stretch;
6466
justify-content: flex-start;
6567
background-color: var(--blue-100);
6668
padding: 8px 16px;
67-
margin-bottom: 12px;
68-
border-radius: 0.5rem 0.5rem 0 0;
69+
border-left: solid 1px var(--gray-300);
70+
border-top: solid 1px var(--gray-300);
71+
border-right: solid 1px var(--gray-300);
6972
border-bottom: solid 1px var(--gray-200);
73+
border-radius: 0.5rem 0.5rem 0 0;
7074
gap: 16px;
7175
}
7276

@@ -129,7 +133,10 @@ input[required].empty {
129133
font-weight: 500;
130134
padding-right: 6px;
131135
font-size: 0.875rem;
132-
text-transform: uppercase;
136+
}
137+
138+
.inline-status-label {
139+
padding: 8px 0px;
133140
}
134141

135142
.input-label-tooltip {

lib/assets/main.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ export async function init(ctx, info) {
6464
placeholder="/bin/bash"
6565
v-model="fields.executable"
6666
inputClass="input input--xs"
67-
:grow
67+
:inline
6868
:required
6969
/>
70+
<div class="inline-field grow">
71+
<label class="inline-input-label inline-status-label" data-el-status-label></label>
72+
</div>
7073
<button id="start-stop-button" @click="start_stop_executable" class="icon-button">
7174
<i class="ri ri-play-line" data-start-stop-button></i>
7275
</button>
@@ -83,6 +86,7 @@ export async function init(ctx, info) {
8386
const button = ctx.root.querySelector("[data-start-stop-button]");
8487
const classList = button.classList;
8588
const terminalEl = ctx.root.querySelector('#terminal');
89+
const statusEl = ctx.root.querySelector("[data-el-status-label]");
8690
if (classList.contains("ri-stop-line")) {
8791
ctx.pushEvent("stop_executable");
8892
button.classList.remove("ri-stop-line");
@@ -109,6 +113,8 @@ export async function init(ctx, info) {
109113
term.clear()
110114
}
111115

116+
statusEl.innerText = ``;
117+
112118
fit_addon.fit()
113119
resizeObserver = new ResizeObserver((entries) => {
114120
try {
@@ -150,6 +156,14 @@ export async function init(ctx, info) {
150156
term.write(Uint8Array.from(atob(data), c => c.charCodeAt(0)))
151157
})
152158

159+
ctx.handleEvent("executable_exited", ({ code }) => {
160+
const status = ctx.root.querySelector("[data-el-status-label]");
161+
status.innerText = `Process exited with code ${code}`;
162+
const button = ctx.root.querySelector("[data-start-stop-button]");
163+
button.classList.remove("ri-stop-line");
164+
button.classList.add("ri-play-line");
165+
})
166+
153167
ctx.handleSync(() => {
154168
// Synchronously invokes change listeners
155169
document.activeElement &&

lib/expty_smartcell.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ else
1717
assign(ctx,
1818
executable: executable,
1919
pty: nil,
20+
pty_ref: nil,
2021
started?: false
2122
)
2223

@@ -55,6 +56,12 @@ else
5556
broadcast_event(ctx, "data", %{data: Base.encode64(data)})
5657
end)
5758

59+
self = self()
60+
61+
ExPTY.on_exit(pty, fn _, _, exit_code, _ ->
62+
Process.send_after(self, {:executable_exited, exit_code}, 0)
63+
end)
64+
5865
{:noreply,
5966
assign(ctx,
6067
pty: pty,
@@ -107,6 +114,11 @@ else
107114
{:noreply, ctx}
108115
end
109116

117+
def handle_info({:executable_exited, code}, ctx) do
118+
broadcast_event(ctx, "executable_exited", %{code: code})
119+
{:noreply, assign(ctx, pty: nil, pty_ref: nil, started?: false)}
120+
end
121+
110122
@impl true
111123
def terminate(_, ctx) do
112124
stop_executable(ctx)

0 commit comments

Comments
 (0)