beyonder_gpu/block_renderers/
shell_block.rs1use beyonder_core::{Block, BlockContent, BlockKind, BlockStatus};
7
8use crate::pipeline::RectInstance;
9
10#[allow(clippy::too_many_arguments)]
11pub fn render_shell_block(
12 block: &Block,
13 x: f32,
14 y: f32,
15 width: f32,
16 height: f32,
17 font_size: f32,
18 scale: f32,
19 rects: &mut Vec<RectInstance>,
20) {
21 let BlockContent::ShellCommand {
22 output, exit_code, ..
23 } = &block.content
24 else {
25 return;
26 };
27
28 let cmd_bar_h = font_size * 2.8;
29 let inner_gap = font_size * 0.4;
30
31 let last_content = output
32 .rows
33 .iter()
34 .rposition(|row| {
35 row.cells.iter().any(|c| {
36 let fc = c.grapheme.chars().next().unwrap_or('\0');
37 fc != ' ' && fc != '\0'
38 })
39 })
40 .map(|i| i + 1)
41 .unwrap_or(0);
42 let has_output = last_content > 0;
43
44 rects.push(
47 RectInstance::filled(x, y, width, cmd_bar_h, [0.118, 0.118, 0.180, 1.0])
48 .with_radius(3.0 * scale),
49 );
50
51 let accent = match block.kind {
53 BlockKind::Human => [0.271, 0.278, 0.353, 0.7],
54 BlockKind::Agent => [0.537, 0.706, 0.980, 0.85],
55 BlockKind::Approval => [0.976, 0.886, 0.686, 0.90],
56 BlockKind::System => [0.271, 0.278, 0.353, 0.4],
57 BlockKind::Tool => [0.580, 0.886, 0.835, 0.75],
58 };
59 let stripe_w = 3.0 * scale;
60 rects.push(RectInstance::filled(x, y, stripe_w, cmd_bar_h, accent).with_radius(scale));
61
62 if block.status == BlockStatus::Running {
64 rects.push(
65 RectInstance::filled(x, y, stripe_w, cmd_bar_h, [0.796, 0.651, 0.969, 0.95]) .with_radius(scale),
67 );
68 }
69
70 if let Some(code) = exit_code {
72 let indicator = if *code == 0 {
73 [0.651, 0.890, 0.631, 0.80] } else {
75 [0.953, 0.545, 0.659, 0.85] };
77 rects.push(
78 RectInstance::filled(x + width - stripe_w, y, stripe_w, cmd_bar_h, indicator)
79 .with_radius(scale),
80 );
81 }
82
83 if has_output || block.status == BlockStatus::Running {
85 let out_y = y + cmd_bar_h + inner_gap;
86 let out_h = height - cmd_bar_h - inner_gap;
87 if out_h > 1.0 {
88 rects.push(
90 RectInstance::filled(x, out_y, width, out_h, [0.118, 0.118, 0.180, 1.0])
91 .with_radius(3.0 * scale),
92 );
93 }
94 }
95}