team-ljyzipelo

공개
198줄8.4 KB
1use eframe::egui::{self, Color32, FontData, FontDefinitions, FontFamily, FontId, TextStyle};
2use zipelo_ui_memory_app::{
3 controller::{CloseState, Controller},
4 runtime::Action,
5};
6
7#[derive(Default)]
8struct App {
9 controller: Controller,
10}
11
12impl eframe::App for App {
13 fn ui(&mut self, root: &mut egui::Ui, _frame: &mut eframe::Frame) {
14 self.controller.poll();
15 let ctx = root.ctx().clone();
16 if ctx.input(|i| i.viewport().close_requested()) {
17 self.controller.request_close();
18 if self.controller.close != CloseState::Allowed {
19 ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
20 }
21 }
22 if self.controller.close == CloseState::Allowed {
23 ctx.send_viewport_cmd(egui::ViewportCommand::Close);
24 }
25 egui::Panel::top("actions").show(root, |ui| {
26 ui.heading("Zipelo 메모리 작업실");
27 ui.label("합성 입력 전용 / 파일 저장 미지원");
28 ui.horizontal_wrapped(|ui| {
29 for (label, action) in [
30 ("ZIP 생성", Action::Zip),
31 ("USTAR 목록과 내용", Action::Ustar),
32 ("GZip 검증과 내용", Action::Gzip),
33 ("합성 오류 확인", Action::InvalidGzip),
34 ] {
35 if ui
36 .add_enabled(
37 !self.controller.busy() && self.controller.close == CloseState::Open,
38 egui::Button::new(label),
39 )
40 .clicked()
41 {
42 self.controller.start(action);
43 }
44 }
45 if ui
46 .add_enabled(self.controller.busy(), egui::Button::new("취소 요청"))
47 .clicked()
48 {
49 self.controller.cancel();
50 }
51 if ui.button("닫기").clicked() {
52 self.controller.request_close();
53 }
54 });
55 });
56 egui::Panel::bottom("status").show(root, |ui| {
57 ui.label(self.controller.status_text());
58 if let Some(progress) = self.controller.progress {
59 ui.label(format!("{:?}: {}", progress.metric, progress.value));
60 }
61 ui.label("USTAR 내용 무결성 검증 정보는 제공되지 않음");
62 if self.controller.busy() {
63 ui.label("작업 스레드 종료 확인 전에는 다시 시작하거나 닫지 않습니다");
64 }
65 if let Some(error) = &self.controller.spawn_error {
66 ui.label(format!(
67 "작업 시작 실패: {}",
68 format!("{error:?}").chars().take(256).collect::<String>()
69 ));
70 }
71 if let Some(completion) = &self.controller.terminal {
72 if !completion.outcome.is_ok() || completion.delivery.is_some() {
73 let detail = match &completion.outcome {
74 zipelo_ui_memory_app::runtime::Outcome::Zip(t) => {
75 format!("{:?}", t.result().err())
76 }
77 zipelo_ui_memory_app::runtime::Outcome::Ustar(t) => {
78 format!("{:?}", t.result().err())
79 }
80 zipelo_ui_memory_app::runtime::Outcome::Gzip(t) => {
81 format!("{:?}", t.result().err())
82 }
83 };
84 ui.label(format!(
85 "반환 원인: {}",
86 detail.chars().take(512).collect::<String>()
87 ));
88 if let Some(fault) = completion.delivery {
89 ui.label(format!(
90 "UI 전달 원인: {:?}, 최초 누락 {}",
91 fault.kind, fault.first_missing_sequence
92 ));
93 }
94 }
95 }
96 });
97 egui::CentralPanel::default_margins().show(root, |ui| {
98 ui.columns(2, |columns| {
99 columns[0].heading("메모리 결과 목록");
100 let rows: Vec<String> = self
101 .controller
102 .rows()
103 .into_iter()
104 .map(str::to_owned)
105 .collect();
106 for (index, name) in rows.iter().enumerate() {
107 if columns[0]
108 .selectable_label(
109 self.controller.selected.is_some_and(|(_, _, i)| i == index),
110 name,
111 )
112 .clicked()
113 {
114 if let Some(task) = &self.controller.task {
115 self.controller
116 .select(task.id, self.controller.generation, index);
117 }
118 }
119 }
120 columns[1].heading("선택한 내용");
121 if let Some(bytes) = self.controller.selected_bytes() {
122 columns[1].label(format!("원본 {} bytes / 텍스트 최대 2048자", bytes.len()));
123 }
124 columns[1].label(self.controller.preview());
125 });
126 });
127 if self.controller.close == CloseState::Confirming {
128 egui::Window::new("작업 중 닫기")
129 .collapsible(false)
130 .resizable(false)
131 .show(&ctx, |ui| {
132 ui.label("취소를 요청하고 작업 스레드 종료를 기다릴까요?");
133 if ui.button("계속 열기").clicked() {
134 self.controller.keep_open();
135 }
136 if ui.button("취소 후 닫기").clicked() {
137 self.controller.confirm_close();
138 }
139 });
140 }
141 if self.controller.close == CloseState::Waiting {
142 egui::Window::new("종료 대기")
143 .collapsible(false)
144 .show(&ctx, |ui| {
145 ui.label("취소 요청은 전송됐습니다. 작업 종료를 기다립니다.");
146 if ui.button("닫기 철회").clicked() {
147 self.controller.keep_open();
148 }
149 });
150 }
151 if self.controller.busy() {
152 ctx.request_repaint_after(std::time::Duration::from_millis(30));
153 }
154 }
155}
156
157fn main() -> eframe::Result {
158 let font = std::fs::read("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc")
159 .map_err(|e| eframe::Error::AppCreation(Box::new(e)))?;
160 eframe::run_native(
161 "Zipelo 합성 메모리 작업",
162 eframe::NativeOptions {
163 renderer: eframe::Renderer::Glow,
164 viewport: egui::ViewportBuilder::default()
165 .with_inner_size([1060.0, 720.0])
166 .with_min_inner_size([760.0, 540.0]),
167 ..Default::default()
168 },
169 Box::new(move |cc| {
170 let mut fonts = FontDefinitions::empty();
171 let mut data = FontData::from_owned(font);
172 data.index = 1;
173 fonts.font_data.insert("noto-kr".into(), data.into());
174 fonts
175 .families
176 .insert(FontFamily::Proportional, vec!["noto-kr".into()]);
177 cc.egui_ctx.set_fonts(fonts);
178 cc.egui_ctx.set_visuals(egui::Visuals::light());
179 cc.egui_ctx.style_mut_of(egui::Theme::Light, |style| {
180 style
181 .text_styles
182 .insert(TextStyle::Body, FontId::proportional(18.0));
183 style
184 .text_styles
185 .insert(TextStyle::Button, FontId::proportional(18.0));
186 style
187 .text_styles
188 .insert(TextStyle::Heading, FontId::proportional(26.0));
189 style.visuals.panel_fill = Color32::WHITE;
190 style.visuals.override_text_color = Some(Color32::from_rgb(24, 39, 57));
191 style.visuals.selection.bg_fill = Color32::from_rgb(211, 230, 246);
192 style.spacing.item_spacing = egui::vec2(12.0, 10.0);
193 style.spacing.button_padding = egui::vec2(14.0, 10.0);
194 });
195 Ok(Box::<App>::default())
196 }),
197 )
198}