foundry_debugger/tui/mod.rs
1//! The debugger TUI.
2
3use eyre::Result;
4use foundry_tui::run_app;
5
6mod context;
7use crate::debugger::DebuggerContext;
8use context::TUIContext;
9
10mod draw;
11
12/// Debugger exit reason.
13#[derive(Debug)]
14pub enum ExitReason {
15 /// Exit using 'q'.
16 CharExit,
17}
18
19/// The debugger TUI.
20pub struct TUI<'a> {
21 debugger_context: &'a mut DebuggerContext,
22}
23
24impl<'a> TUI<'a> {
25 /// Creates a new debugger.
26 pub const fn new(debugger_context: &'a mut DebuggerContext) -> Self {
27 Self { debugger_context }
28 }
29
30 /// Starts the debugger TUI.
31 pub fn try_run(&mut self) -> Result<ExitReason> {
32 self.run_inner()
33 }
34
35 #[instrument(target = "debugger", name = "run", skip_all, ret)]
36 fn run_inner(&mut self) -> Result<ExitReason> {
37 let mut cx = TUIContext::new(self.debugger_context);
38 cx.init();
39 Ok(run_app(&mut cx)?)
40 }
41}