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

@@ -5,7 +5,11 @@ use std::{
io::{self, IsTerminal},
path::PathBuf,
};
use tb_ide::{app::App, options, terminal::TerminalGuard};
use tb_ide::{
app::{App, Execution},
options,
terminal::TerminalGuard,
};
fn main() -> Result<()> {
let args: Vec<_> = std::env::args().skip(1).collect();
@@ -23,11 +27,58 @@ fn main() -> Result<()> {
if let Some(path) = args.first() {
app.load_initial_project(PathBuf::from(path))?;
}
let _guard = TerminalGuard::enter(io::stdout())?;
let mut guard = TerminalGuard::enter(io::stdout())?;
let mut terminal = Terminal::new(CrosstermBackend::new(io::stdout()))?;
let start = std::time::Instant::now();
let mut last_draw = start - std::time::Duration::from_millis(16);
let signals = tb_ui::signale::Signalquelle::neu();
while !app.quit {
terminal.draw(|f| app.render(f))?;
app.handle(event::read()?);
if signals.abholen().is_some() {
app.pause_execution();
}
let shell = if app.session.file_shell
|| matches!(app.execution, Execution::Running | Execution::Waiting)
{
app.session.host.shell_request.take()
} else {
None
};
if let Some(command) = shell {
let result = guard.shell(&command, &signals);
terminal.clear()?;
let (cols, rows) = crossterm::terminal::size()?;
app.handle(event::Event::Resize(cols, rows));
if app.session.file_shell {
app.session.file_shell = false;
app.message = match result {
Ok(code) => format!("Shell beendet: {code}"),
Err(e) => format!("Shell: {e}"),
};
} else {
app.session.host.shell_result =
Some(result.map_err(|_| tb_runtime::errors::RuntimeError(53)));
}
}
if last_draw.elapsed() >= std::time::Duration::from_millis(16) {
terminal.draw(|f| app.render(f))?;
last_draw = std::time::Instant::now();
}
// Bounded input batch: both keyboard and VM make progress under load.
for _ in 0..64 {
if !event::poll(std::time::Duration::ZERO)? {
break;
}
app.handle(event::read()?);
}
app.tick_execution(start.elapsed().as_millis() as u64);
let timeout = if app.execution == Execution::Running {
std::time::Duration::ZERO
} else {
std::time::Duration::from_millis(10)
};
if event::poll(timeout)? {
app.handle(event::read()?);
}
}
Ok(())
}