forge
Explore
Log in

Don't you dare go Hollow

wifi_lab

Clone
★ 0

0 watching0 forksRust2.1 MiBb265998Tahinli1 month ago27 commits

log.rs66 lines, 2.3 KiBHistoryRawDownload
1//! Log page: read-only multiline text area over the backend event log
2//! (plain text widgets are NOT selectable; the input gives mouse-
3//! selection + Ctrl-C for free). A "Copy log" button puts the whole
4//! buffer, oldest first, straight on the clipboard.
5
6use gpui::{ClipboardItem, Context, Entity, ParentElement, Styled, Window};
7use gpuikit::elements::button::button;
8use gpuikit::elements::input::text_area;
9use gpuikit::elements::typography::{h3, small};
10use gpuikit::layout::{h_stack, v_stack};
11
12use crate::ui::app::AppRoot;
13
14pub fn render(
15 app: &mut AppRoot,
16 view: &Entity<AppRoot>,
17 _window: &mut Window,
18 cx: &mut Context<AppRoot>,
19) -> gpui::Div {
20 // Sync the read-only view with the log buffer, oldest first.
21 let joined = app.state.log.iter().cloned().collect::<Vec<_>>().join("\n");
22 if app.log_input.read(cx).content() != joined {
23 app.log_input
24 .update(cx, |input, cx| input.set_content_silent(joined, cx));
25 }
26
27 v_stack()
28 .size_full()
29 .gap_2()
30 .p_4()
31 .child(
32 h_stack()
33 .items_center()
34 .gap_3()
35 .child(h3("Log"))
36 .child(small(format!(
37 "{} lines — click, drag, Ctrl-A/Ctrl-C to copy",
38 app.state.log.len()
39 )))
40 .child(gpui::div().flex_1())
41 .child(button("btn-copy-log", "Copy log").on_click({
42 let view = view.clone();
43 move |_, _window, cx| {
44 let joined = view
45 .read(cx)
46 .state
47 .log
48 .iter()
49 .cloned()
50 .collect::<Vec<_>>()
51 .join("\n");
52 cx.write_to_clipboard(ClipboardItem::new_string(joined));
53 view.update(cx, |app, cx| {
54 app.state.push_log("log copied to clipboard");
55 cx.notify();
56 });
57 }
58 })),
59 )
60 .child(
61 gpui::div()
62 .flex_1()
63 .min_h_0()
64 .child(text_area(&app.log_input, cx)),
65 )
66}