diff --git a/gastronomy-cli/src/app.rs b/gastronomy-cli/src/app.rs index 82aaa6b..bedc9eb 100644 --- a/gastronomy-cli/src/app.rs +++ b/gastronomy-cli/src/app.rs @@ -31,6 +31,7 @@ impl Default for Focus { #[derive(Default)] pub struct App<'a> { pub file_name: PathBuf, + pub index: Option, pub cursor: usize, pub frames: Vec>, pub source_files: BTreeMap, @@ -164,7 +165,7 @@ impl<'a> Widget for &mut App<'a> { let location = curr_frame.location; let ret_value = curr_frame.ret_value; - let layout = render_block_region(self.file_name.clone(), location, area, buf); + let layout = render_block_region(self.file_name.clone(), self.index, location, area, buf); let gauge_region = layout[0]; let command_region = layout[1]; @@ -209,6 +210,7 @@ impl<'a> Widget for &mut App<'a> { fn render_block_region( file_name: PathBuf, + index: Option, location: Option<&String>, area: Rect, buf: &mut Buffer, @@ -216,6 +218,7 @@ fn render_block_region( let title = Line::from(vec![ " Gastronomy Debugger (".bold(), file_name.to_str().unwrap().bold(), + index.map(|i| format!(" #{i}")).unwrap_or_default().bold(), ")".bold(), ]); let mut instructions = if location.is_some() { diff --git a/gastronomy-cli/src/main.rs b/gastronomy-cli/src/main.rs index 378ae4b..37e4d71 100644 --- a/gastronomy-cli/src/main.rs +++ b/gastronomy-cli/src/main.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeMap, path::PathBuf}; -use anyhow::Result; +use anyhow::{bail, Result}; use app::App; use clap::{command, Parser, Subcommand}; use figment::providers::Env; @@ -58,6 +58,18 @@ async fn run() -> Result<(), anyhow::Error> { source_root, }) => { let mut raw_programs = gastronomy::uplc::load_programs_from_file(&file, query).await?; + let index = index.or(if raw_programs.len() == 1 { + None + } else { + Some(0) + }); + if index.unwrap_or_default() >= raw_programs.len() { + bail!( + "Invalid index #{}, tx only has {} redeemer(s)", + index.unwrap_or_default(), + raw_programs.len() + ); + } let raw_program = raw_programs.remove(index.unwrap_or_default()); let arguments = parameters .iter() @@ -80,6 +92,7 @@ async fn run() -> Result<(), anyhow::Error> { let mut terminal = utils::init()?; let mut app = App { file_name: file, + index, cursor: 0, frames, source_files,