Phase 5: Ausführung und Output implementieren und archivieren

This commit is contained in:
2026-09-06 18:56:47 +02:00
parent 9c85349a4d
commit e3dc9028bf
37 changed files with 2404 additions and 450 deletions

View File

@@ -21,8 +21,12 @@ pub enum Mode {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Execution {
Idle,
Compiling,
Paused,
Running,
Waiting,
Ended,
Error,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WindowKind {
@@ -213,6 +217,9 @@ pub enum DialogKind {
Dirty(AfterSave),
LoadText,
SaveText,
Print,
CommandLine,
ResumeRevision,
Display,
Paths,
RightMouse,
@@ -256,6 +263,7 @@ pub enum Hit {
}
pub struct App {
pub session: crate::execution::Session,
pub editor: crate::editor::Editor,
pub project: Project,
pub options: Options,
@@ -293,6 +301,7 @@ impl App {
let (options, errors, config_disk) = Options::load(&config_path);
project.include_paths = options.include_paths.clone();
let mut app = Self {
session: Default::default(),
editor: Default::default(),
project,
options: options.clone(),
@@ -423,6 +432,7 @@ impl App {
)
.trim_end()
.to_string(),
WindowKind::Output if self.session.old_revision => "Output · ALTES KOMPILAT".into(),
_ => format!("{:?}", w.kind),
}
}
@@ -452,6 +462,9 @@ impl App {
return Some(format!("Fachfunktion folgt in Phase-5-Change {phase:02}"));
}
use Command::*;
if command == Shell && self.session.host.shell_request.is_some() {
return Some("Shell-Übergabe bereits angefordert".into());
}
if matches!(
command,
Undo | Cut | Paste | Clear | LoadText | NewSub | NewFunction | Replace
@@ -467,6 +480,7 @@ impl App {
if matches!(
command,
LoadText
| Print
| SaveText
| Cut
| Copy
@@ -532,6 +546,40 @@ impl App {
use Command::*;
let id = self.active_document();
match command {
Start => self.start_execution()?,
Restart => self.restart_target()?,
Continue => self.continue_execution()?,
Pause => self.pause_execution(),
OutputScreen => {
self.session.fullscreen = !self.session.fullscreen;
}
CommandLine => self.open_dialog(
"COMMAND$",
DialogKind::CommandLine,
vec![Field::text(
"Argumente für den nächsten Start",
&self.session.command,
)],
),
Shell => {
self.session.file_shell = true;
self.session.host.shell_request = Some(String::new());
}
Print => self.open_dialog(
"Print",
DialogKind::Print,
vec![
Field::text("UTF-8-Ausgabedatei", self.output_default("LPT1.TXT")),
Field::toggle("Bestehendes Ziel überschreiben", false),
Field::toggle(
"Nur Auswahl",
self.project
.view(self.editor_view()?)?
.selection()
.is_some(),
),
],
),
Cut | Copy | Paste | Clear | NewSub | NewFunction | IncludedFile | IncludedLines
| Find | SelectedText | FindNext | Replace | Procedures | PreviousCode
| Diagnostics => self.editor_command(command)?,
@@ -706,6 +754,9 @@ impl App {
_ => WindowKind::Project,
};
self.show_tool(kind);
if command == Output {
self.session.fullscreen = false;
}
}
MenuBar => {
self.properties = !self.properties;
@@ -856,7 +907,7 @@ impl App {
let offset = (self.windows.len() % 5) as u16 * 2;
clamp(Rect::new(offset, 1 + offset, 60, 16), self.area())
}
fn show_tool(&mut self, kind: WindowKind) {
pub(crate) fn show_tool(&mut self, kind: WindowKind) {
if let Some(w) = self.windows.iter_mut().find(|w| w.kind == kind) {
self.active = w.id;
w.state = WindowState::Normal;
@@ -932,6 +983,8 @@ impl App {
match after {
AfterSave::Stay => return Ok(()),
AfterSave::Exit => {
self.session.finish();
self.basic_events.clear();
self.quit = true;
return Ok(());
}
@@ -943,6 +996,9 @@ impl App {
self.project.open_project(&path, Decision::Discard)?;
}
}
self.session = Default::default();
self.basic_events.clear();
self.execution = Execution::Idle;
self.base = self.project.directory().to_path_buf();
self.editor = Default::default();
self.windows.clear();
@@ -1141,11 +1197,25 @@ impl App {
let text = std::fs::read_to_string(self.base.join(d.fields[0].string()))?;
self.editor_insert(&text)?;
}
DialogKind::SaveText => {
DialogKind::CommandLine => {
self.session.command = d.fields[0].string();
}
DialogKind::ResumeRevision => {
if d.fields[0].index() == 0 {
self.restart_target()?;
} else {
self.resume_execution(true);
}
}
DialogKind::SaveText | DialogKind::Print => {
let (id, _) = self.code_cursor()?;
self.project.save_text(
id,
self.project.view(self.editor_view()?)?.selection(),
if matches!(d.kind, DialogKind::Print) && !d.fields[2].flag() {
None
} else {
self.project.view(self.editor_view()?)?.selection()
},
&Destination {
path: d.fields[0].string().into(),
overwrite: d.fields[1].flag(),
@@ -1255,8 +1325,20 @@ impl App {
self.line_leave(old);
}
fn handle_event(&mut self, event: Event) {
if matches!(event, Event::Key(k) if k.kind != KeyEventKind::Release && k.code == K::Pause && k.modifiers.contains(M::CONTROL))
{
self.pause_execution();
return;
}
if let Event::Resize(w, h) = event {
self.size = (w, h);
if let Some(vm) = self.session.vm.as_mut() {
vm.rt.ereignis(tb_runtime::host::Ereignis::Groesse {
cols: w as usize,
rows: h as usize,
});
vm.forms.resize(w as usize, h as usize);
}
return;
}
if self.size.0 < 80 || self.size.1 < 25 {
@@ -1269,6 +1351,10 @@ impl App {
self.key(key);
} else if let Event::Mouse(mouse) = event {
if self.dialog.is_none() && self.menu.is_none() && self.program_focus() {
if self.session.fullscreen {
self.basic_events.push(Event::Mouse(mouse));
return;
}
if let Some(w) = self.active_window() {
let r = self.rect(w);
let inner = Rect::new(
@@ -1278,6 +1364,9 @@ impl App {
r.height.saturating_sub(2),
);
if inner.contains((mouse.column, mouse.row).into()) {
let mut mouse = mouse;
mouse.column -= inner.x;
mouse.row -= inner.y;
self.basic_events.push(Event::Mouse(mouse));
return;
}
@@ -1399,13 +1488,18 @@ impl App {
}
}
fn program_focus(&self) -> bool {
self.execution == Execution::Running
&& matches!(
self.active_window().map(|w| w.kind),
Some(WindowKind::Output)
)
matches!(self.execution, Execution::Running | Execution::Waiting)
&& (self.session.fullscreen
|| matches!(
self.active_window().map(|w| w.kind),
Some(WindowKind::Output)
))
}
fn key(&mut self, key: KeyEvent) {
if self.session.fullscreen && self.dialog.is_none() && key.code == K::F(4) {
self.execute(Command::OutputScreen);
return;
}
if self.editor.chord.is_some()
&& self.dialog.is_none()
&& self.menu.is_none()
@@ -1586,7 +1680,7 @@ impl App {
return;
}
if self.program_focus() && key.modifiers.contains(M::CONTROL) && key.code == K::Char('c') {
self.basic_events.push(Event::Key(key));
self.pause_execution();
return;
}
if let Some(command) = shortcut(key) {
@@ -1634,7 +1728,8 @@ impl App {
DialogKind::OpenProject
| DialogKind::AddFile
| DialogKind::LoadText
| DialogKind::SaveText => index == 0,
| DialogKind::SaveText
| DialogKind::Print => index == 0,
DialogKind::Save { .. } => index % 2 == 0,
DialogKind::Export(_) => index == 3,
_ => false,