1use crate::app::App; 2use crate::app::tabs::Tab; 3use crate::ui::theme::{self, pal}; 4use crate::ui::widgets::{mono, tab}; 5use crate::vm::Vm; 6use crate::{editor, exec, paths, settings, workflow, workspace}; 7use rune::{Cx, El, col, row, text}; 8use rune_kit::Kit; 9 10pub const SIDE: f32 = 260.0; 11 12pub fn frame(s: &App, k: &Kit, _cx: &mut Cx<App>, layer: &mut Vec<El>) -> El { 13 let active = s.tab().clone(); 14 let side = match &active { 15 Tab::Welcome | Tab::Settings => None, 16 Tab::Prompt(stem) => Some(workspace::sidebar::view(s, Some(stem))), 17 Tab::Workflow(stem) | Tab::Task(stem) => Some(workflow::steps::view(s, stem, false)), 18 Tab::Run(stem) => Some(workflow::steps::view(s, stem, true)), 19 }; 20 let main = match &active { 21 Tab::Welcome => workspace::welcome::view(s), 22 Tab::Settings => settings::view::view(s, k), 23 Tab::Prompt(stem) => editor::view::view(s, stem, k, layer), 24 Tab::Workflow(stem) => workflow::review::view(s, stem, k), 25 Tab::Task(stem) => workflow::task_view::view(s, stem, k), 26 Tab::Run(stem) => exec::view::view(s, stem), 27 }; 28 let tabs = s.tabs.iter().enumerate().map(|(i, t)| { 29 let close = text("×") 30 .font(theme::SMALL) 31 .color(pal().faint) 32 .role("button") 33 .label("Close tab") 34 .focusable(true) 35 .cursor(rune::Cursor::Pointer) 36 .on_press(move |s: &mut App| s.close(i)); 37 tab(&t.label(s), i == s.active) 38 .key(format!("tab-{i}")) 39 .focusable(true) 40 .cursor(rune::Cursor::Pointer) 41 .on_press(move |s: &mut App| s.active = i) 42 .child(close) 43 }); 44 shell(tabs.collect(), side, main, status(s)) 45} 46 47pub fn shell(tabs: Vec<El>, side: Option<El>, main: El, status: El) -> El { 48 let p = pal(); 49 let brand = row() 50 .w(SIDE) 51 .h_full() 52 .px(12.0) 53 .center_y() 54 .child(text("▲ cast").font(theme::MONO).color(p.accent)); 55 let mut body = row().grow(1.0).min_h(0.0); 56 if let Some(side) = side { 57 body = body.child(side.w(SIDE).h_full().fill(p.surface).clip_rounded(0.0)); 58 } 59 col() 60 .w_full() 61 .h_full() 62 .child( 63 row() 64 .h(36.0) 65 .w_full() 66 .fill(p.surface) 67 .child(brand) 68 .children(tabs), 69 ) 70 .child( 71 body.child( 72 col() 73 .grow(1.0) 74 .min_w(0.0) 75 .h_full() 76 .child(main.grow(1.0).min_h(0.0)), 77 ), 78 ) 79 .child( 80 row() 81 .h(28.0) 82 .w_full() 83 .px(12.0) 84 .gap(16.0) 85 .fill(p.surface) 86 .center_y() 87 .child(status), 88 ) 89} 90 91fn status(s: &App) -> El { 92 let p = pal(); 93 let vm = match &s.vm { 94 Vm::Off => mono("○ VM off", p.muted), 95 Vm::Booting => mono("◐ VM booting", p.accent), 96 Vm::Ready(_) => mono("● VM running", p.ok), 97 Vm::Failed(e) => mono(format!("✕ VM {e}"), p.danger), 98 }; 99 let mut left = row().gap(16.0).center_y().child(match &s.ws { 100 Some(ws) => mono(paths::tilde(&ws.dir), p.fg), 101 None => mono("No directory open", p.muted), 102 }); 103 left = left.child(vm); 104 if let Some(n) = &s.notice { 105 left = left.child( 106 mono(format!("✕ {n}"), p.danger) 107 .role("button") 108 .label("Dismiss") 109 .focusable(true) 110 .cursor(rune::Cursor::Pointer) 111 .on_press(|s: &mut App| s.notice = None), 112 ); 113 } 114 left 115}