tirbofish/dropbear
main / crates / eucalyptus-editor / src / editor / docks / build_console.rs · 6628 bytes
crates/eucalyptus-editor/src/editor/docks/build_console.rs
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
use std::path::PathBuf;
use egui::{Margin, RichText};
use crate::editor::docks::console::{ConsoleItem, ErrorLevel};
use crate::editor::page::EditorTabVisibility;
use crate::editor::{EditorTabDock, EditorTabDockDescriptor, EditorTabViewer};
impl<'a> EditorTabViewer<'a> {
pub fn build_console(&mut self, ui: &mut egui::Ui) {
fn analyse_error(log: &Vec<String>) -> Vec<ConsoleItem> {
fn parse_compiler_location(line: &str) -> Option<(ErrorLevel, PathBuf, String)> {
let trimmed = line.trim_start();
let (error_level, rest) = if let Some(r) = trimmed.strip_prefix("e: file:///") {
(ErrorLevel::Error, r)
} else if let Some(r) = trimmed.strip_prefix("w: file:///") {
(ErrorLevel::Warn, r)
} else {
return None;
};
let location = rest.split_whitespace().next()?;
let mut segments = location.rsplitn(3, ':');
let column = segments.next()?;
let row = segments.next()?;
let path = segments.next()?;
Some((error_level, PathBuf::from(path), format!("{row}:{column}")))
}
let mut list: Vec<ConsoleItem> = Vec::new();
for (index, line) in log.iter().enumerate() {
if line.contains("The required library") {
list.push(ConsoleItem {
error_level: ErrorLevel::Error,
msg: line.clone(),
file_location: None,
line_ref: None,
id: index as u64,
});
} else if let Some((error_level, path, loc)) = parse_compiler_location(line) {
list.push(ConsoleItem {
error_level,
msg: line.clone(),
file_location: Some(path),
line_ref: Some(loc),
id: index as u64,
});
} else {
list.push(ConsoleItem {
error_level: ErrorLevel::Info,
msg: line.clone(),
file_location: None,
line_ref: None,
id: index as u64,
});
}
}
list
}
let logs = analyse_error(&self.build_logs);
egui::ScrollArea::vertical()
.auto_shrink([false, false])
.stick_to_bottom(true)
.show(ui, |ui| {
if logs.is_empty() {
ui.label("Build output will appear here once available.");
return;
}
for item in &logs {
let (bg_color, text_color, stroke_color) = match item.error_level {
ErrorLevel::Error => (
egui::Color32::from_rgb(60, 20, 20),
egui::Color32::from_rgb(255, 200, 200),
egui::Color32::from_rgb(255, 200, 200),
),
ErrorLevel::Warn => (
egui::Color32::from_rgb(40, 40, 10),
egui::Color32::from_rgb(255, 255, 200),
egui::Color32::from_rgb(255, 255, 200),
),
ErrorLevel::Info => (
egui::Color32::TRANSPARENT,
ui.style().visuals.text_color(),
egui::Color32::TRANSPARENT,
),
};
if matches!(item.error_level, ErrorLevel::Info) {
ui.label(RichText::new(&item.msg).monospace());
} else {
let available_width = ui.available_width();
let frame = egui::Frame::new()
.inner_margin(Margin::symmetric(8, 6))
.fill(bg_color)
.stroke(egui::Stroke::new(1.0, stroke_color));
let response = frame
.show(ui, |ui| {
ui.set_width(available_width - 10.0);
ui.horizontal(|ui| {
ui.label(
RichText::new(&item.msg).color(text_color).monospace(),
);
});
})
.response;
if response.clicked() {
log::debug!("Log item clicked: {}", &item.id);
if let (Some(path), Some(loc)) = (&item.file_location, &item.line_ref) {
let location_arg = format!("{}:{}", path.display(), loc);
match std::process::Command::new("code")
.args(["-g", &location_arg])
.spawn()
.map(|_| ())
{
Ok(()) => {
log::info!(
"Launched Visual Studio Code at the error: {}",
&location_arg
);
}
Err(e) => {
eucalyptus_core::warn!(
"Failed to open '{}' in VS Code: {}",
location_arg,
e
);
}
}
}
}
}
}
});
}
}
pub struct BuildConsoleDock;
impl EditorTabDock for BuildConsoleDock {
fn desc() -> EditorTabDockDescriptor {
EditorTabDockDescriptor {
id: "build_console",
title: "Build Output".to_string(),
visibility: EditorTabVisibility::all(), // idk about this one
}
}
fn display(viewer: &mut EditorTabViewer<'_>, ui: &mut egui::Ui) {
viewer.build_console(ui);
}
}