Skip to content

Commit 7e154c5

Browse files
committed
Print tx index in gastronomy-cli
1 parent 4a03a50 commit 7e154c5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

gastronomy-cli/src/app.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl Default for Focus {
3131
#[derive(Default)]
3232
pub struct App<'a> {
3333
pub file_name: PathBuf,
34+
pub index: Option<usize>,
3435
pub cursor: usize,
3536
pub frames: Vec<RawFrame<'a>>,
3637
pub source_files: BTreeMap<String, String>,
@@ -164,7 +165,7 @@ impl<'a> Widget for &mut App<'a> {
164165
let location = curr_frame.location;
165166
let ret_value = curr_frame.ret_value;
166167

167-
let layout = render_block_region(self.file_name.clone(), location, area, buf);
168+
let layout = render_block_region(self.file_name.clone(), self.index, location, area, buf);
168169

169170
let gauge_region = layout[0];
170171
let command_region = layout[1];
@@ -209,13 +210,15 @@ impl<'a> Widget for &mut App<'a> {
209210

210211
fn render_block_region(
211212
file_name: PathBuf,
213+
index: Option<usize>,
212214
location: Option<&String>,
213215
area: Rect,
214216
buf: &mut Buffer,
215217
) -> Rc<[Rect]> {
216218
let title = Line::from(vec![
217219
" Gastronomy Debugger (".bold(),
218220
file_name.to_str().unwrap().bold(),
221+
index.map(|i| format!(" #{i}")).unwrap_or_default().bold(),
219222
")".bold(),
220223
]);
221224
let mut instructions = if location.is_some() {

gastronomy-cli/src/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{collections::BTreeMap, path::PathBuf};
22

3-
use anyhow::Result;
3+
use anyhow::{bail, Result};
44
use app::App;
55
use clap::{command, Parser, Subcommand};
66
use figment::providers::Env;
@@ -58,6 +58,18 @@ async fn run() -> Result<(), anyhow::Error> {
5858
source_root,
5959
}) => {
6060
let mut raw_programs = gastronomy::uplc::load_programs_from_file(&file, query).await?;
61+
let index = index.or(if raw_programs.len() == 1 {
62+
None
63+
} else {
64+
Some(0)
65+
});
66+
if index.unwrap_or_default() >= raw_programs.len() {
67+
bail!(
68+
"Invalid index #{}, tx only has {} redeemer(s)",
69+
index.unwrap_or_default(),
70+
raw_programs.len()
71+
);
72+
}
6173
let raw_program = raw_programs.remove(index.unwrap_or_default());
6274
let arguments = parameters
6375
.iter()
@@ -80,6 +92,7 @@ async fn run() -> Result<(), anyhow::Error> {
8092
let mut terminal = utils::init()?;
8193
let mut app = App {
8294
file_name: file,
95+
index,
8396
cursor: 0,
8497
frames,
8598
source_files,

0 commit comments

Comments
 (0)