Skip to main content

logicaffeine_web/ui/components/
repl_output.rs

1//! REPL output for Math mode.
2//!
3//! Displays command history and execution results in a terminal-like interface.
4//! Shows success output in green and errors in red. The panel around it carries the
5//! title and the Clear control.
6//!
7//! # Props
8//!
9//! - `lines` - List of executed commands and their results
10
11use crate::ui::state::ReplLine;
12use dioxus::prelude::*;
13
14const REPL_OUTPUT_STYLE: &str = r#"
15.repl-output {
16    display: flex;
17    flex-direction: column;
18    height: 100%;
19    min-height: 0;
20    background: var(--studio-surface, #0f1419);
21    font-family: 'SF Mono', 'Fira Code', monospace;
22}
23
24
25.repl-history {
26    flex: 1;
27    min-height: 0;
28    overflow: auto;
29    padding: var(--studio-inset, 12px);
30}
31
32.repl-line {
33    margin-bottom: 16px;
34}
35
36/* The history ends at its last line; the panel's own inset is the only space after it. */
37.repl-line:last-child {
38    margin-bottom: 0;
39}
40
41.repl-input-line {
42    display: flex;
43    gap: 8px;
44    color: rgba(255, 255, 255, 0.6);
45    font-size: 13px;
46    line-height: 1.5;
47}
48
49.repl-prompt {
50    color: #667eea;
51    user-select: none;
52    flex-shrink: 0;
53}
54
55.repl-input-text {
56    color: rgba(255, 255, 255, 0.9);
57    white-space: pre-wrap;
58    word-break: break-word;
59}
60
61.repl-output-line {
62    padding-left: 24px;
63    margin-top: 4px;
64    font-size: 13px;
65    line-height: 1.5;
66    white-space: pre-wrap;
67    word-break: break-word;
68}
69
70.repl-output-line.success {
71    color: #4ade80;
72}
73
74.repl-output-line.error {
75    color: #e06c75;
76}
77
78.repl-empty {
79    display: flex;
80    flex-direction: column;
81    align-items: center;
82    justify-content: center;
83    height: 100%;
84    color: rgba(255, 255, 255, 0.4);
85    text-align: center;
86    padding: 20px;
87}
88
89.repl-empty .hint {
90    font-size: 13px;
91    margin-top: 8px;
92}
93
94.repl-empty .commands {
95    margin-top: 16px;
96    font-size: 12px;
97    color: rgba(255, 255, 255, 0.3);
98}
99
100.repl-empty .commands code {
101    background: rgba(255, 255, 255, 0.05);
102    padding: 2px 6px;
103    border-radius: 4px;
104    margin: 0 2px;
105}
106"#;
107
108#[component]
109pub fn ReplOutput(lines: Vec<ReplLine>) -> Element {
110    rsx! {
111        style { "{REPL_OUTPUT_STYLE}" }
112
113        div { class: "repl-output",
114            // History
115            div { class: "repl-history",
116                if lines.is_empty() {
117                    div { class: "repl-empty",
118                        div { "No output yet" }
119                        div { class: "hint", "Execute code to see results here" }
120                        div { class: "commands",
121                            "Commands: "
122                            code { "Definition" }
123                            code { "Check" }
124                            code { "Eval" }
125                            code { "Inductive" }
126                        }
127                    }
128                } else {
129                    for (i, line) in lines.iter().enumerate() {
130                        div { key: "{i}", class: "repl-line",
131                            // Input line
132                            div { class: "repl-input-line",
133                                span { class: "repl-prompt", ">" }
134                                span { class: "repl-input-text", "{line.input}" }
135                            }
136
137                            // Output line
138                            match &line.output {
139                                Ok(output) if !output.is_empty() => rsx! {
140                                    div { class: "repl-output-line success", "{output}" }
141                                },
142                                Err(error) => rsx! {
143                                    div { class: "repl-output-line error", "{error}" }
144                                },
145                                _ => rsx! {}
146                            }
147                        }
148                    }
149                }
150            }
151        }
152    }
153}