diff --git a/Cargo.lock b/Cargo.lock index c40e8931cea98..3a5f3ab783b89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1147,7 +1147,7 @@ version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e959d788268e3bf9d35ace83e81b124190378e4c91c9067524675e33394b8ba" dependencies = [ - "crossterm 0.26.1", + "crossterm", "strum 0.24.1", "strum_macros 0.24.3", "unicode-width", @@ -1347,22 +1347,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossterm" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" -dependencies = [ - "bitflags 1.3.2", - "crossterm_winapi", - "libc", - "mio", - "parking_lot", - "signal-hook", - "signal-hook-mio", - "winapi", -] - [[package]] name = "crossterm" version = "0.26.1" @@ -3553,6 +3537,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "indoc" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c785eefb63ebd0e33416dfcb8d6da0bf27ce752843a45632a67bf10d4d4b5c4" + [[package]] name = "inlinable_string" version = "0.1.15" @@ -5131,6 +5121,21 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "ratatui" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8285baa38bdc9f879d92c0e37cb562ef38aa3aeefca22b3200186bc39242d3d5" +dependencies = [ + "bitflags 2.4.0", + "cassowary", + "crossterm", + "indoc", + "paste", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "rayon" version = "1.7.0" @@ -6943,19 +6948,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" -[[package]] -name = "tui" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" -dependencies = [ - "bitflags 1.3.2", - "cassowary", - "crossterm 0.25.0", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "tungstenite" version = "0.17.3" @@ -7032,13 +7024,13 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" name = "ui" version = "0.2.0" dependencies = [ - "crossterm 0.26.1", + "crossterm", "ethers", "eyre", "foundry-common", "foundry-evm", + "ratatui", "revm", - "tui", ] [[package]] diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml index 4a7f767d45e4f..7efe80c1aa530 100644 --- a/crates/ui/Cargo.toml +++ b/crates/ui/Cargo.toml @@ -18,4 +18,4 @@ ethers.workspace = true crossterm = "0.26" eyre = "0.6" revm = { version = "3", features = ["std", "serde"] } -tui = { version = "0.19", default-features = false, features = ["crossterm"] } +ratatui = { version = "0.22.0", default-features = false, features = ["crossterm"]} \ No newline at end of file diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index 0588fc2bd4086..53ce831eb85b8 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -16,6 +16,15 @@ use foundry_evm::{ utils::{build_pc_ic_map, PCICMap}, CallKind, }; +use ratatui::{ + backend::{Backend, CrosstermBackend}, + layout::{Alignment, Constraint, Direction, Layout, Rect}, + style::{Color, Modifier, Style}, + terminal::Frame, + text::{Line, Span, Text}, + widgets::{Block, Borders, Paragraph, Wrap}, + Terminal, +}; use revm::{interpreter::opcode, primitives::SpecId}; use std::{ cmp::{max, min}, @@ -25,15 +34,6 @@ use std::{ thread, time::{Duration, Instant}, }; -use tui::{ - backend::{Backend, CrosstermBackend}, - layout::{Alignment, Constraint, Direction, Layout, Rect}, - style::{Color, Modifier, Style}, - terminal::Frame, - text::{Span, Spans, Text}, - widgets::{Block, Borders, Paragraph, Wrap}, - Terminal, -}; /// Trait for starting the UI pub trait Ui { @@ -367,9 +367,9 @@ impl Tui { fn draw_footer(f: &mut Frame, area: Rect) { let block_controls = Block::default(); - let text_output = vec![Spans::from(Span::styled( + let text_output = vec![Line::from(Span::styled( "[q]: quit | [k/j]: prev/next op | [a/s]: prev/next jump | [c/C]: prev/next call | [g/G]: start/end", Style::default().add_modifier(Modifier::DIM))), -Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/k]: scroll stack | [ctrl + j/k]: scroll memory | [']: goto breakpoint | [h] toggle help", Style::default().add_modifier(Modifier::DIM)))]; +Line::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/k]: scroll stack | [ctrl + j/k]: scroll memory | [']: goto breakpoint | [h] toggle help", Style::default().add_modifier(Modifier::DIM)))]; let paragraph = Paragraph::new(text_output) .block(block_controls) @@ -486,7 +486,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ if let Some(last) = before.pop() { if !last.ends_with('\n') { before.iter().skip(start_line).for_each(|line| { - text_output.lines.push(Spans::from(vec![ + text_output.lines.push(Line::from(vec![ Span::styled( format!( "{: >max_line_num$}", @@ -506,7 +506,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ line_number += 1; }); - text_output.lines.push(Spans::from(vec![ + text_output.lines.push(Line::from(vec![ Span::styled( format!( "{: >max_line_num$}", @@ -530,7 +530,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ line_number += 1; actual.iter().skip(1).for_each(|s| { - text_output.lines.push(Spans::from(vec![ + text_output.lines.push(Line::from(vec![ Span::styled( format!( "{: >max_line_num$}", @@ -561,7 +561,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ } else { before.push(last); before.iter().skip(start_line).for_each(|line| { - text_output.lines.push(Spans::from(vec![ + text_output.lines.push(Line::from(vec![ Span::styled( format!( "{: >max_line_num$}", @@ -582,7 +582,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ line_number += 1; }); actual.iter().for_each(|s| { - text_output.lines.push(Spans::from(vec![ + text_output.lines.push(Line::from(vec![ Span::styled( format!( "{: >max_line_num$}", @@ -611,7 +611,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ } } else { actual.iter().for_each(|s| { - text_output.lines.push(Spans::from(vec![ + text_output.lines.push(Line::from(vec![ Span::styled( format!( "{: >max_line_num$}", @@ -644,7 +644,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ if !last.ends_with('\n') { if let Some(post) = after.pop_front() { if let Some(last) = text_output.lines.last_mut() { - last.0.push(Span::raw(post)); + last.spans.push(Span::raw(post)); } } } @@ -655,7 +655,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ after.pop_back(); } after.iter().for_each(|line| { - text_output.lines.push(Spans::from(vec![ + text_output.lines.push(Line::from(vec![ Span::styled( format!( "{: >max_line_num$}", @@ -721,7 +721,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ debug_steps[current_step].total_gas_used, )) .borders(Borders::ALL); - let mut text_output: Vec = Vec::new(); + let mut text_output: Vec = Vec::new(); // Scroll: // Focused line is line that should always be at the center of the screen. @@ -776,12 +776,12 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ }; if let Some(op) = opcode_list.get(line_number) { - text_output.push(Spans::from(Span::styled( + text_output.push(Line::from(Span::styled( format!("{line_number_format}{op}"), Style::default().fg(Color::White).bg(bg_color), ))); } else { - text_output.push(Spans::from(Span::styled( + text_output.push(Line::from(Span::styled( line_number_format, Style::default().fg(Color::White).bg(bg_color), ))); @@ -818,7 +818,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ vec![] }; - let text: Vec = stack + let text: Vec = stack .iter() .rev() .enumerate() @@ -861,7 +861,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ spans.extend(words); spans.push(Span::raw("\n")); - Spans::from(spans) + Line::from(spans) }) .collect(); @@ -923,7 +923,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ let height = area.height as usize; let end_line = draw_mem.current_mem_startline + height; - let text: Vec = memory + let text: Vec = memory .chunks(32) .enumerate() .skip(draw_mem.current_mem_startline) @@ -975,7 +975,7 @@ Spans::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/ spans.push(Span::raw("\n")); - Spans::from(spans) + Line::from(spans) }) .collect(); let paragraph = Paragraph::new(text).block(stack_space).wrap(Wrap { trim: true });