1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
mod path_formatting;
mod state;
mod ui;
use crate::state::CommandStatus;
use crate::ui::components;
use crate::ui::layout_calculations::calculate_viewport;
use state::{parse_commands, ChainType, CommandEntry, SequenceMode, State};
use zellij_tile::prelude::*;
use std::collections::BTreeMap;
use std::path::PathBuf;
register_plugin!(State);
impl ZellijPlugin for State {
fn load(&mut self, _configuration: BTreeMap<String, String>) {
subscribe(&[
EventType::ModeUpdate,
EventType::Key,
EventType::PermissionRequestResult,
EventType::HostFolderChanged,
EventType::CommandPaneExited,
EventType::CommandPaneOpened,
EventType::EditPaneExited,
EventType::Timer,
EventType::PastedText,
EventType::TabUpdate,
EventType::BeforeClose,
]);
// Store our own plugin ID and client ID
let plugin_ids = get_plugin_ids();
self.plugin_id = Some(plugin_ids.plugin_id);
self.client_id = Some(plugin_ids.client_id);
self.cwd = Some(plugin_ids.initial_cwd);
rename_plugin_pane(plugin_ids.plugin_id, "Sequence");
update_title(self);
}
fn update(&mut self, event: Event) -> bool {
handle_event(self, event)
}
#[cfg(target_family = "wasm")]
fn pipe(&mut self, pipe_message: PipeMessage) -> bool {
if !pipe_message.is_private {
return false;
}
let Some(payload) = pipe_message.payload else {
return false;
};
let payload = payload.trim().to_string();
if payload.is_empty() {
return false;
}
// If already running, emit error
if self.execution.is_running {
if let PipeSource::Cli(pipe_id) = &pipe_message.source {
#[cfg(target_family = "wasm")]
cli_pipe_output(pipe_id, "error: sequence already running\n");
}
return false;
}
self.load_commands(&payload, None);
// Handle blocking: keep CLI alive until sequence finishes
if pipe_message
.args
.get("blocking")
.map(|v| v == "true")
.unwrap_or(false)
{
if let PipeSource::Cli(pipe_id) = &pipe_message.source {
block_cli_pipe_input(pipe_id);
self.blocking_pipe_id = Some(pipe_id.clone());
}
}
show_self(true);
true
}
fn render(&mut self, rows: usize, cols: usize) {
// Store dimensions for use in calculations
self.own_rows = Some(rows);
self.own_columns = Some(cols);
// Main screen: plugin just opened, no commands entered yet
if self.all_commands_are_pending() && !self.execution.can_run_sequence() {
for (text, x, y) in components::render_intro_hint(rows, cols) {
print_text_with_coordinates(text, x, y, None, None);
}
return;
}
let is_staging = self.all_commands_are_pending() && self.execution.can_run_sequence();
// Reserve: 1 header above + 1 padding-to-controls + 1 controls + 1 below/ribbon
let max_visible_rows = rows.saturating_sub(4);
let (offset, visible_count, hidden_above, hidden_below) = calculate_viewport(
self.execution.all_commands.len(),
max_visible_rows,
self.selection.current_selected_command_index,
self.execution.current_running_command_index,
);
// For the staging screen, center the content both horizontally and vertically.
// Content height: 1 header row + visible_count command rows + 1 gap + 1 help row = visible_count + 3
let (base_x, base_y, table_max_width) = if is_staging {
let longest_cwd = self.execution.longest_cwd_display(&self.cwd);
let longest_cmd = self
.execution
.all_commands
.iter()
.map(|c| c.get_text().chars().count())
.max()
.unwrap_or(1);
let (max_chain_w, max_status_w) = components::calculate_max_widths(
&self.execution.all_commands,
self.layout.spinner_frame,
);
let content_width = components::calculate_longest_line(
&longest_cwd,
longest_cmd,
max_chain_w,
max_status_w,
)
.min(cols);
// header + commands + gap + help + ribbon/below = visible_count + 4
let content_height = visible_count + 4;
let bx = cols.saturating_sub(content_width) / 2;
let by = rows.saturating_sub(content_height) / 2;
(bx, by, Some(content_width))
} else {
(1, 0, self.own_columns.map(|o| o.saturating_sub(1)))
};
let mut table = components::build_table_header(hidden_above > 0 || hidden_below > 0);
for index in offset..offset + visible_count {
table = components::add_command_row(
table,
self,
index,
offset,
visible_count,
hidden_above,
hidden_below,
);
}
print_table_with_coordinates(table, base_x, base_y, table_max_width, None);
let help_y = base_y + visible_count + 2;
let (first_help, first_help_len, second_help) =
components::render_help_lines(self, Some(cols));
let help_x = if is_staging {
cols.saturating_sub(first_help_len) / 2
} else {
base_x
};
print_text_with_coordinates(first_help, help_x, help_y, None, None);
if let Some((second_help_text, second_help_len)) = second_help {
let second_help_x = if is_staging {
cols.saturating_sub(second_help_len) / 2
} else {
base_x
};
print_text_with_coordinates(second_help_text, second_help_x, help_y + 1, None, None);
}
// Mode ribbon: "<Tab> [Single Pane] [Spread]" — only while running
if self.execution.is_running {
let ribbon_y = help_y + 1;
print_text_with_coordinates(
Text::new("<Tab>").color_all(3),
base_x,
ribbon_y,
None,
None,
);
let ribbon_x = base_x + 6; // "<Tab>" (5) + space (1)
let (single_ribbon, spread_ribbon) = if self.mode == SequenceMode::SinglePane {
(Text::new("Single Pane").selected(), Text::new("Spread"))
} else {
(Text::new("Single Pane"), Text::new("Spread").selected())
};
print_ribbon_with_coordinates(single_ribbon, ribbon_x, ribbon_y, Some(15), None);
print_ribbon_with_coordinates(spread_ribbon, ribbon_x + 15, ribbon_y, Some(10), None);
}
}
}
pub fn handle_event(state: &mut State, event: Event) -> bool {
use std::path::PathBuf;
match event {
Event::PermissionRequestResult(_) => {
change_host_folder(PathBuf::from("/"));
update_title(state);
true
},
Event::ModeUpdate(mode_info) => {
state.shell = mode_info.shell.clone();
false
},
Event::Key(key) => {
let should_render = handle_key_event(state, key);
let repositioned = state.reposition_plugin();
if repositioned {
// we only want to render once we have repositioned, we will do this in TabUpdate
return false;
}
show_cursor(None);
should_render
},
Event::Timer(_elapsed) => {
let should_render = update_spinner(state);
update_title(state);
should_render
},
Event::PastedText(pasted_text) => {
if state.execution.is_running {
return false;
}
let payload = pasted_text.trim().to_string();
if payload.is_empty() {
return false;
}
state.load_commands(&payload, None);
let repositioned = state.reposition_plugin();
!repositioned
},
Event::TabUpdate(tab_infos) => {
if let Some(tab_info) = tab_infos.iter().find(|t| t.active) {
state.total_viewport_columns = Some(tab_info.viewport_columns);
state.total_viewport_rows = Some(tab_info.viewport_rows);
}
state.reposition_plugin()
},
Event::CommandPaneExited(terminal_pane_id, exit_code, _context) => {
let should_render = handle_command_pane_exited(state, terminal_pane_id, exit_code);
let repositioned = state.reposition_plugin();
update_title(state);
should_render || repositioned
},
Event::CommandPaneOpened(_terminal_pane_id, _context) => {
// Schedule spinner on first pane open
if !state.layout.spinner_timer_scheduled {
set_timeout(0.1);
state.layout.spinner_timer_scheduled = true;
}
update_title(state);
true
},
Event::EditPaneExited(terminal_pane_id, _exit_code, _context) => {
let should_render = handle_editor_pane_exited(state, terminal_pane_id);
let repositioned = state.reposition_plugin();
should_render || repositioned
},
Event::BeforeClose => {
if let Some(pipe_id) = state.blocking_pipe_id.take() {
unblock_cli_pipe_input(&pipe_id);
}
false
},
_ => false,
}
}
fn handle_command_pane_exited(
state: &mut State,
terminal_pane_id: u32,
exit_code: Option<i32>,
) -> bool {
let pane_id = PaneId::Terminal(terminal_pane_id);
// Find which command this pane belongs to — stale events produce no match
let Some(cmd_index) =
state.execution.all_commands.iter().position(
|c| matches!(c.get_status(), CommandStatus::Running(Some(id)) if id == pane_id),
)
else {
return false;
};
state.execution.all_commands[cmd_index]
.set_status(CommandStatus::Exited(exit_code, Some(pane_id)));
if !state.execution.is_running {
return true;
}
let chain_type = state.execution.all_commands[cmd_index].get_chain_type();
let should_continue = match chain_type {
ChainType::And => exit_code.unwrap_or(0) == 0,
ChainType::Or => exit_code.unwrap_or(0) != 0,
ChainType::Then => true,
ChainType::None => false,
};
let next_index = cmd_index + 1;
if should_continue && next_index < state.execution.all_commands.len() {
launch_command_at_index(state, next_index, Some(pane_id), false);
} else {
state.execution.is_running = false;
state.selection.current_selected_command_index = None;
// Unblock blocking CLI pipe if one is waiting
if let Some(pipe_id) = state.blocking_pipe_id.take() {
unblock_cli_pipe_input(&pipe_id);
}
}
true
}
fn handle_editor_pane_exited(state: &mut State, terminal_pane_id: u32) -> bool {
let pane_id = PaneId::Terminal(terminal_pane_id);
// Ignore events from unrelated panes
if state.editor_pane_id != Some(pane_id) {
return false;
}
// Read the temp file contents
let contents = if let Some(ref path) = state.editor_temp_file {
std::fs::read_to_string(path).unwrap_or_default()
} else {
String::new()
};
// Delete the temp file
if let Some(ref path) = state.editor_temp_file {
let _ = std::fs::remove_file(path);
}
// Clear editor state
state.editor_pane_id = None;
state.editor_temp_file = None;
// Parse file into commands
let commands = parse_commands(&contents, state.cwd.clone());
if !commands.is_empty() {
state.execution.all_commands = commands;
state.execution.current_running_command_index = 0;
state.selection.current_selected_command_index = None;
state.execution.is_running = false;
} else {
// Reset to empty pending state
state.execution.all_commands = vec![CommandEntry::new("", state.cwd.clone())];
state.execution.current_running_command_index = 0;
state.selection.current_selected_command_index = None;
state.execution.is_running = false;
}
show_self(true);
true
}
fn launch_command_at_index(
state: &mut State,
index: usize,
replace_pane_id: Option<PaneId>,
force_visible: bool,
) {
let cmd = &state.execution.all_commands[index];
let cmd_text = cmd.get_text().trim().to_string();
let command = CommandToRun {
path: state
.shell
.clone()
.unwrap_or_else(|| PathBuf::from("/bin/bash")),
args: vec!["-ic".to_string(), cmd_text.clone()],
cwd: cmd.get_cwd(),
};
let user_is_watching =
replace_pane_id.is_some() && replace_pane_id == state.execution.displayed_pane_id;
let new_pane_id = if state.mode == SequenceMode::Spread {
open_command_pane_near_plugin(command, BTreeMap::new())
} else if user_is_watching {
let prev_pane_id = replace_pane_id.unwrap();
let pane_id =
open_command_pane_in_place_of_pane_id(prev_pane_id, command, false, BTreeMap::new());
if let Some(pane_id) = pane_id {
state.execution.displayed_pane_id = Some(pane_id);
}
pane_id
} else if force_visible {
let (tab_id, pane_id) = open_command_pane_in_new_tab(command, BTreeMap::new());
if let Some(pane_id) = pane_id {
state.execution.displayed_pane_id = Some(pane_id);
}
if let (Some(tab_id), Some(plugin_id)) = (tab_id, state.plugin_id) {
state.sequence_tab_id = Some(tab_id);
break_panes_to_tab_with_id(&[PaneId::Plugin(plugin_id)], tab_id, true);
focus_pane_with_id(PaneId::Plugin(plugin_id), false, false);
}
pane_id
} else {
// User navigated away — open in background, invisible until they navigate to it
open_command_pane_background(command, BTreeMap::new())
};
if let Some(pane_id) = new_pane_id {
rename_pane_with_id(pane_id, &cmd_text);
state.execution.all_commands[index].set_status(CommandStatus::Running(Some(pane_id)));
state.execution.current_running_command_index = index;
state.selection.current_selected_command_index = Some(index);
state.show_selected_pane();
}
}
fn handle_key_event(state: &mut State, key: KeyWithModifier) -> bool {
// Ctrl+Space — copy to clipboard
if key.has_modifiers(&[KeyModifier::Ctrl]) && matches!(key.bare_key, BareKey::Char(' ')) {
state.copy_to_clipboard();
return false;
}
// Ctrl+W — close tab if sequence has run; close plugin if staging; no-op if running
if key.has_modifiers(&[KeyModifier::Ctrl]) && matches!(key.bare_key, BareKey::Char('w')) {
if state.all_commands_are_pending() {
if let Some(plugin_id) = state.plugin_id {
close_pane_with_id(PaneId::Plugin(plugin_id));
}
} else if !state.execution.is_running {
close_panes_and_return_to_shell(state);
}
return true;
}
// Ctrl+C — interrupt if running; clear commands if staging; close plugin if empty
if key.has_modifiers(&[KeyModifier::Ctrl]) && matches!(key.bare_key, BareKey::Char('c')) {
if state.execution.is_running {
interrupt_sequence(state);
return true;
} else if state.all_commands_are_pending() {
if state.execution.all_commands.iter().any(|c| !c.is_empty()) {
state.clear_all_commands();
} else if let Some(plugin_id) = state.plugin_id {
close_pane_with_id(PaneId::Plugin(plugin_id));
}
return true;
}
}
let is_staging = state.all_commands_are_pending() && state.execution.can_run_sequence();
if matches!(key.bare_key, BareKey::Up)
&& !key.has_modifiers(&[KeyModifier::Ctrl])
&& !key.has_modifiers(&[KeyModifier::Alt])
{
if !is_staging {
state.move_selection_up();
return true;
}
return false;
}
if matches!(key.bare_key, BareKey::Down)
&& !key.has_modifiers(&[KeyModifier::Ctrl])
&& !key.has_modifiers(&[KeyModifier::Alt])
{
if !is_staging {
state.move_selection_down();
return true;
}
return false;
}
// e — open external editor (when not running)
if !state.execution.is_running
&& key.has_no_modifiers()
&& matches!(key.bare_key, BareKey::Char('e'))
{
state.open_editor();
return true;
}
// Enter — rerun sequence
if key.has_no_modifiers() && matches!(key.bare_key, BareKey::Enter) {
rerun_sequence(state);
return true;
}
// Tab — toggle spread mode (when sequence has run)
if key.has_no_modifiers()
&& matches!(key.bare_key, BareKey::Tab)
&& !state.all_commands_are_pending()
{
toggle_spread_mode(state);
return true;
}
false
}
fn close_panes_and_return_to_shell(state: &mut State) -> bool {
if let Some(tab_id) = state.sequence_tab_id {
close_tab_with_id(tab_id as u64);
}
true
}
fn update_spinner(state: &mut State) -> bool {
// Advance spinner frame for RUNNING animation
state.layout.spinner_frame = (state.layout.spinner_frame + 1) % 8;
// Reset timer scheduled flag since this timer just fired
state.layout.spinner_timer_scheduled = false;
// If we have a running command, schedule next timer event
let has_running = state
.execution
.all_commands
.iter()
.any(|command| matches!(command.get_status(), CommandStatus::Running(_)));
if has_running {
set_timeout(0.1);
state.layout.spinner_timer_scheduled = true;
}
has_running
}
fn rerun_sequence(state: &mut State) {
if !state.can_run_sequence() {
return;
}
state.execution.all_commands.retain(|c| !c.is_empty());
if state.execution.all_commands.is_empty() {
return;
}
let selected_index = state
.selection
.current_selected_command_index
.unwrap_or(0)
.min(state.execution.all_commands.len().saturating_sub(1));
state.execution.is_running = true;
state.execution.current_running_command_index = selected_index;
ensure_spinner_running(state);
match state.execution.all_commands[selected_index].get_pane_id() {
Some(PaneId::Terminal(id)) => {
let pane_id = PaneId::Terminal(id);
// Replace the displayed pane with the starting pane first, while
// displayed_pane_id is still valid. The replaced pane is suppressed
// and can then be closed safely below.
if state.mode == SequenceMode::SinglePane {
if let Some(displayed) = state.execution.displayed_pane_id {
if displayed != pane_id {
replace_pane_with_existing_pane(displayed, pane_id, true);
}
}
state.execution.displayed_pane_id = Some(pane_id);
}
// Close and reset commands after selected (now suppressed).
for i in (selected_index + 1)..state.execution.all_commands.len() {
if let Some(p) = state.execution.all_commands[i].get_pane_id() {
close_pane_with_id(p);
}
state.execution.all_commands[i].set_status(CommandStatus::Pending);
}
state.execution.all_commands[selected_index]
.set_status(CommandStatus::Running(Some(pane_id)));
state.selection.current_selected_command_index = Some(selected_index);
rerun_command_pane(id);
},
_ => {
// Close and reset commands after selected.
for i in (selected_index + 1)..state.execution.all_commands.len() {
if let Some(p) = state.execution.all_commands[i].get_pane_id() {
close_pane_with_id(p);
}
state.execution.all_commands[i].set_status(CommandStatus::Pending);
}
let replace_pane_id = state.execution.displayed_pane_id;
launch_command_at_index(state, selected_index, replace_pane_id, true);
},
}
}
fn toggle_spread_mode(state: &mut State) {
match state.mode {
SequenceMode::SinglePane => enter_spread_mode(state),
SequenceMode::Spread => exit_spread_mode(state),
}
}
fn enter_spread_mode(state: &mut State) {
state.mode = SequenceMode::Spread;
let first_pane_id = state
.execution
.all_commands
.first()
.and_then(|c| c.get_pane_id());
let Some(first_pane_id) = first_pane_id else {
return;
};
if let Some(displayed) = state.execution.displayed_pane_id {
if displayed != first_pane_id {
replace_pane_with_existing_pane(displayed, first_pane_id, true);
}
}
state.execution.displayed_pane_id = Some(first_pane_id);
for cmd in state.execution.all_commands.iter().skip(1) {
if let Some(pane_id) = cmd.get_pane_id() {
show_pane_with_id(pane_id, false, false);
}
}
state.show_selected_pane();
}
fn exit_spread_mode(state: &mut State) {
// Remove all highlights before leaving spread mode
let all_pane_ids: Vec<PaneId> = state
.execution
.all_commands
.iter()
.filter_map(|c| c.get_pane_id())
.collect();
if !all_pane_ids.is_empty() {
highlight_and_unhighlight_panes(vec![], all_pane_ids);
}
state.mode = SequenceMode::SinglePane;
let first_pane_id = state
.execution
.all_commands
.first()
.and_then(|c| c.get_pane_id());
let selected_pane_id = state
.selection
.current_selected_command_index
.and_then(|i| state.execution.all_commands.get(i))
.and_then(|c| c.get_pane_id())
.or(first_pane_id);
let Some(selected_pane_id) = selected_pane_id else {
return;
};
if let Some(first_pane_id) = first_pane_id {
if first_pane_id != selected_pane_id {
replace_pane_with_existing_pane(first_pane_id, selected_pane_id, true);
}
}
for cmd in &state.execution.all_commands {
if let Some(pane_id) = cmd.get_pane_id() {
if pane_id != selected_pane_id {
hide_pane_with_id(pane_id);
}
}
}
state.execution.displayed_pane_id = Some(selected_pane_id);
}
fn interrupt_sequence(state: &mut State) {
if state.execution.is_running {
for command in state.execution.all_commands.iter_mut() {
if let CommandStatus::Running(pane_id) = command.get_status() {
if let Some(pane_id) = pane_id {
send_sigkill_to_pane_id(pane_id);
}
command.set_status(CommandStatus::Interrupted(pane_id));
}
}
state.execution.is_running = false;
state.selection.current_selected_command_index = None;
// Unblock blocking CLI pipe if interrupted
if let Some(pipe_id) = state.blocking_pipe_id.take() {
unblock_cli_pipe_input(&pipe_id);
}
} else {
eprintln!("Cannot interrupt a sequence that is not running.");
}
}
pub fn update_title(state: &mut State) {
let Some(tab_id) = state.sequence_tab_id else {
return;
};
let tab_id_u64 = tab_id as u64;
// All pending and not yet running
if state.all_commands_are_pending() && !state.execution.is_running {
rename_tab_with_id(tab_id_u64, "Run one or more commands in sequence");
return;
}
// Currently running: "<cmd> <n>/<total> <spinner>"
let has_running = state
.execution
.all_commands
.iter()
.any(|c| matches!(c.get_status(), CommandStatus::Running(..)));
if has_running {
let idx = state.execution.current_running_command_index;
let total = state.execution.all_commands.len();
let cmd_text = state
.execution
.all_commands
.get(idx)
.map(|c| c.get_text())
.unwrap_or_default();
let spinner = components::get_spinner_frame(state.layout.spinner_frame);
rename_tab_with_id(
tab_id_u64,
&format!("{} {}/{} {}", cmd_text, idx + 1, total, spinner),
);
return;
}
// Interrupted: "<cmd> [INTERRUPTED]"
if let Some(cmd) = state
.execution
.all_commands
.iter()
.find(|c| matches!(c.get_status(), CommandStatus::Interrupted(_)))
{
let status_str =
components::format_status_text(&cmd.get_status(), state.layout.spinner_frame);
rename_tab_with_id(tab_id_u64, &format!("{} {}", cmd.get_text(), status_str));
return;
}
// All exited
let all_exited = state
.execution
.all_commands
.iter()
.all(|c| matches!(c.get_status(), CommandStatus::Exited(..)));
if all_exited {
let all_success = state
.execution
.all_commands
.iter()
.all(|c| matches!(c.get_status(), CommandStatus::Exited(Some(0), _)));
if all_success {
rename_tab_with_id(tab_id_u64, "Sequence Complete");
} else {
// Show first command with non-zero or unknown exit
if let Some(cmd) = state
.execution
.all_commands
.iter()
.find(|c| !matches!(c.get_status(), CommandStatus::Exited(Some(0), _)))
{
let status_str =
components::format_status_text(&cmd.get_status(), state.layout.spinner_frame);
rename_tab_with_id(tab_id_u64, &format!("{} {}", cmd.get_text(), status_str));
} else {
rename_tab_with_id(tab_id_u64, "Sequence Complete");
}
}
return;
}
// Partial (chain condition failed): show last exited command with its status
if let Some(cmd) = state
.execution
.all_commands
.iter()
.rev()
.find(|c| matches!(c.get_status(), CommandStatus::Exited(..)))
{
let status_str =
components::format_status_text(&cmd.get_status(), state.layout.spinner_frame);
rename_tab_with_id(tab_id_u64, &format!("{} {}", cmd.get_text(), status_str));
} else {
rename_tab_with_id(tab_id_u64, "Stopped");
}
}
fn ensure_spinner_running(state: &mut State) {
if !state.layout.spinner_timer_scheduled {
set_timeout(0.1);
state.layout.spinner_timer_scheduled = true;
}
}
|