Skip to content

Commit

Permalink
fix: replace tui dependency with ratatui
Browse files Browse the repository at this point in the history
  • Loading branch information
therustmonk committed Aug 29, 2023
1 parent 61b436c commit b90bfe9
Show file tree
Hide file tree
Showing 24 changed files with 218 additions and 246 deletions.
220 changes: 96 additions & 124 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions applications/minotari_console_wallet/Cargo.toml
Expand Up @@ -32,7 +32,7 @@ bitflags = "1.2.1"
chrono = { version = "0.4.19", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
config = "0.13.0"
crossterm = { version = "0.25.0" }
crossterm = { version = "0.27.0" }
digest = "0.10"
futures = { version = "^0.3.16", default-features = false, features = ["alloc"] }
log4rs = { git = "https://github.com/tari-project/log4rs.git", default_features = false, features = ["config_parsing", "threshold_filter", "yaml_format", "console_appender", "rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller", "delete_roller"] }
Expand Down Expand Up @@ -62,8 +62,8 @@ path = "../../base_layer/core"
default-features = false
features = ["transactions", "mempool_proto", "base_node_proto"]

[dependencies.tui]
version = "^0.16"
[dependencies.ratatui]
version = "^0.23"
default-features = false
features = ["crossterm"]

Expand Down
6 changes: 3 additions & 3 deletions applications/minotari_console_wallet/src/ui/app.rs
Expand Up @@ -21,13 +21,13 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use minotari_wallet::{util::wallet_identity::WalletIdentity, WalletConfig, WalletSqlite};
use tari_comms::peer_manager::Peer;
use tokio::runtime::Handle;
use tui::{
use ratatui::{
backend::Backend,
layout::{Constraint, Direction, Layout},
Frame,
};
use tari_comms::peer_manager::Peer;
use tokio::runtime::Handle;

use crate::{
notifier::Notifier,
Expand Down
@@ -1,15 +1,15 @@
// Copyright 2022 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tari_core::transactions::tari_amount::MicroMinotari;
use tui::{
use ratatui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Span, Spans},
text::{Line, Span},
widgets::{Block, Borders, Paragraph},
Frame,
};
use tari_core::transactions::tari_amount::MicroMinotari;

use crate::ui::{components::Component, state::AppState};

Expand Down Expand Up @@ -50,18 +50,18 @@ impl<B: Backend> Component<B> for Balance {

let balance = app_state.get_balance();
let time_locked = balance.time_locked_balance.unwrap_or_else(|| MicroMinotari::from(0u64));
let available_balance = Spans::from(vec![
let available_balance = Line::from(vec![
Span::styled("Available:", Style::default().fg(Color::Magenta)),
Span::raw(" "),
Span::raw(format!("{}", balance.available_balance.saturating_sub(time_locked))),
Span::raw(format!(" (Time Locked: {})", time_locked)),
]);
let incoming_balance = Spans::from(vec![
let incoming_balance = Line::from(vec![
Span::styled("Pending Incoming:", Style::default().fg(Color::Magenta)),
Span::raw(" "),
Span::raw(format!("{}", balance.pending_incoming_balance)),
]);
let outgoing_balance = Spans::from(vec![
let outgoing_balance = Line::from(vec![
Span::styled("Pending Outgoing:", Style::default().fg(Color::Magenta)),
Span::raw(" "),
Span::raw(format!("{}", balance.pending_outgoing_balance)),
Expand Down
Expand Up @@ -21,11 +21,11 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use minotari_wallet::connectivity_service::{OnlineStatus, WalletConnectivityInterface};
use tui::{
use ratatui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Style},
text::{Span, Spans},
text::{Line, Span},
widgets::{Block, Borders, Paragraph},
Frame,
};
Expand All @@ -46,20 +46,20 @@ impl<B: Backend> Component<B> for BaseNode {
#[allow(clippy::too_many_lines)]
fn draw(&mut self, f: &mut Frame<B>, area: Rect, app_state: &AppState)
where B: Backend {
let title = Spans::from(vec![Span::styled(
let title = Line::from(vec![Span::styled(
" Base Node Status - ",
Style::default().fg(Color::White),
)]);

let current_online_status = app_state.get_wallet_connectivity().get_connectivity_status();
let mut base_node_id_color = Color::White;
let chain_info = match current_online_status {
OnlineStatus::Connecting => Spans::from(vec![
OnlineStatus::Connecting => Line::from(vec![
Span::styled("Chain Tip:", Style::default().fg(Color::Magenta)),
Span::raw(" "),
Span::styled("Connecting...", Style::default().fg(Color::Reset)),
]),
OnlineStatus::Offline => Spans::from(vec![
OnlineStatus::Offline => Line::from(vec![
Span::styled("Chain Tip:", Style::default().fg(Color::Magenta)),
Span::raw(" "),
Span::styled("Offline", Style::default().fg(Color::Red)),
Expand Down Expand Up @@ -109,9 +109,9 @@ impl<B: Backend> Component<B> for BaseNode {
Span::styled(" ms", Style::default().fg(Color::DarkGray)),
];

Spans::from(tip_info)
Line::from(tip_info)
} else {
Spans::from(vec![
Line::from(vec![
Span::styled("Chain Tip:", Style::default().fg(Color::Magenta)),
Span::raw(" "),
Span::styled("Waiting for data...", Style::default().fg(Color::DarkGray)),
Expand All @@ -120,7 +120,7 @@ impl<B: Backend> Component<B> for BaseNode {
},
};

let base_node_id = Spans::from(vec![
let base_node_id = Line::from(vec![
Span::styled(" Connected Base Node ID: ", Style::default().fg(Color::Magenta)),
Span::styled(
format!("{}", app_state.get_selected_base_node().node_id.clone()),
Expand Down
22 changes: 11 additions & 11 deletions applications/minotari_console_wallet/src/ui/components/burn_tab.rs
Expand Up @@ -5,16 +5,16 @@ use std::fs;

use log::*;
use minotari_wallet::output_manager_service::UtxoSelectionCriteria;
use tari_core::transactions::tari_amount::MicroMinotari;
use tokio::{runtime::Handle, sync::watch};
use tui::{
use ratatui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Span, Spans},
text::{Line, Span},
widgets::{Block, Borders, ListItem, Paragraph, Wrap},
Frame,
};
use tari_core::transactions::tari_amount::MicroMinotari;
use tokio::{runtime::Handle, sync::watch};
use unicode_width::UnicodeWidthStr;

use crate::ui::{
Expand Down Expand Up @@ -90,7 +90,7 @@ impl BurnTab {
.split(area);

let instructions = Paragraph::new(vec![
Spans::from(vec![
Line::from(vec![
Span::raw("Press "),
Span::styled("P", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Expand All @@ -111,7 +111,7 @@ impl BurnTab {
Span::styled("B", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to view burnt proofs."),
]),
Spans::from(vec![
Line::from(vec![
Span::raw("Press "),
Span::styled("S", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to send a burn transaction."),
Expand All @@ -121,7 +121,7 @@ impl BurnTab {
.block(Block::default());
f.render_widget(instructions, vert_chunks[0]);

let burnt_proof_filepath_input = Paragraph::new(self.burnt_proof_filepath_field.as_ref())
let burnt_proof_filepath_input = Paragraph::new(&*self.burnt_proof_filepath_field)
.style(match self.burn_input_mode {
BurnInputMode::BurntProofPath => Style::default().fg(Color::Magenta),
_ => Style::default(),
Expand All @@ -133,7 +133,7 @@ impl BurnTab {
);
f.render_widget(burnt_proof_filepath_input, vert_chunks[1]);

let claim_public_key_input = Paragraph::new(self.claim_public_key_field.as_ref())
let claim_public_key_input = Paragraph::new(&*self.claim_public_key_field)
.style(match self.burn_input_mode {
BurnInputMode::ClaimPublicKey => Style::default().fg(Color::Magenta),
_ => Style::default(),
Expand All @@ -154,15 +154,15 @@ impl BurnTab {
.block(Block::default().borders(Borders::ALL).title("(A)mount:"));
f.render_widget(amount_input, amount_fee_layout[0]);

let fee_input = Paragraph::new(self.fee_field.as_ref())
let fee_input = Paragraph::new(&*self.fee_field)
.style(match self.burn_input_mode {
BurnInputMode::Fee => Style::default().fg(Color::Magenta),
_ => Style::default(),
})
.block(Block::default().borders(Borders::ALL).title("(F)ee-per-gram (uT):"));
f.render_widget(fee_input, amount_fee_layout[1]);

let message_input = Paragraph::new(self.message_field.as_ref())
let message_input = Paragraph::new(&*self.message_field)
.style(match self.burn_input_mode {
BurnInputMode::Message => Style::default().fg(Color::Magenta),
_ => Style::default(),
Expand Down Expand Up @@ -220,7 +220,7 @@ impl BurnTab {
.margin(1)
.split(area);

let instructions = Paragraph::new(Spans::from(vec![
let instructions = Paragraph::new(Line::from(vec![
Span::raw(" Use "),
Span::styled("Up↑/Down↓ Keys", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to choose a proof, "),
Expand Down
@@ -1,11 +1,11 @@
// Copyright 2022 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tui::{
use ratatui::{
backend::Backend,
layout::Rect,
style::{Color, Style},
text::{Span, Spans},
text::{Line, Span},
Frame,
};

Expand All @@ -25,7 +25,7 @@ pub trait Component<B: Backend> {
fn on_tick(&mut self, _app_state: &mut AppState) {}

// Create custom title based on data in AppState.
fn format_title(&self, title: &str, _app_state: &AppState) -> Spans {
Spans::from(Span::styled(title.to_owned(), Style::default().fg(Color::White)))
fn format_title(&self, title: &str, _app_state: &AppState) -> Line {
Line::from(Span::styled(title.to_owned(), Style::default().fg(Color::White)))
}
}
@@ -1,15 +1,15 @@
// Copyright 2022 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tokio::runtime::Handle;
use tui::{
use ratatui::{
backend::Backend,
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
text::{Span, Spans},
text::{Line, Span},
widgets::{Block, Borders, Clear, ListItem, Paragraph, Wrap},
Frame,
};
use tokio::runtime::Handle;
use unicode_width::UnicodeWidthStr;

use crate::{
Expand Down Expand Up @@ -58,7 +58,7 @@ impl ContactsTab {
.margin(1)
.split(area);

let instructions = Paragraph::new(Spans::from(vec![
let instructions = Paragraph::new(Line::from(vec![
Span::raw("Use "),
Span::styled("Up↑/Down↓ Keys", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to select a contact, "),
Expand Down Expand Up @@ -137,7 +137,7 @@ impl ContactsTab {
.margin(1)
.split(popup_area);

let instructions = Paragraph::new(Spans::from(vec![
let instructions = Paragraph::new(Line::from(vec![
Span::raw("Press "),
Span::styled("L", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Expand All @@ -153,15 +153,15 @@ impl ContactsTab {
.block(Block::default());
f.render_widget(instructions, vert_chunks[0]);

let alias_input = Paragraph::new(self.alias_field.as_ref())
let alias_input = Paragraph::new(&*self.alias_field)
.style(match self.edit_contact_mode {
ContactInputMode::Alias => Style::default().fg(Color::Magenta),
_ => Style::default(),
})
.block(Block::default().borders(Borders::ALL).title("A(l)ias:"));
f.render_widget(alias_input, vert_chunks[1]);

let tari_address_input = Paragraph::new(self.address_field.as_ref())
let tari_address_input = Paragraph::new(&*self.address_field)
.style(match self.edit_contact_mode {
ContactInputMode::PubkeyEmojiId => Style::default().fg(Color::Magenta),
_ => Style::default(),
Expand Down
@@ -1,7 +1,7 @@
// Copyright 2022 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tui::{
use ratatui::{
backend::Backend,
layout::{Constraint, Rect},
widgets::{Block, Borders, Row, Table, TableState},
Expand Down
Expand Up @@ -3,15 +3,15 @@

use std::fs;

use regex::Regex;
use tui::{
use ratatui::{
backend::Backend,
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
text::{Span, Spans},
text::{Line, Span},
widgets::{Block, Borders, Paragraph, Wrap},
Frame,
};
use regex::Regex;

use crate::ui::{components::Component, state::AppState};

Expand All @@ -31,9 +31,9 @@ impl LogTab {
}

// Format the log line nicely. If it cannot be parsed then return raw line
fn format_line(&self, line: String) -> Spans {
fn format_line(&self, line: String) -> Line {
match self.re.captures(line.as_str()) {
Some(caps) => Spans::from(vec![
Some(caps) => Line::from(vec![
Span::styled(caps["timestamp"].to_string(), Style::default().fg(Color::LightGreen)),
Span::raw(" ["),
Span::styled(caps["target"].to_string(), Style::default().fg(Color::LightMagenta)),
Expand All @@ -49,7 +49,7 @@ impl LogTab {
Span::raw(caps["message"].to_string()),
]),
// In case the line is not well formatted, just print as it is
None => Spans::from(vec![Span::raw(line)]),
None => Line::from(vec![Span::raw(line)]),
}
}

Expand All @@ -70,8 +70,8 @@ impl LogTab {
Ok(content) => content,
Err(err) => format!("Error reading log: {}", err),
};
// Convert the content into Spans
let mut text: Vec<Spans> = content.lines().map(|line| self.format_line(line.to_string())).collect();
// Convert the content into Line
let mut text: Vec<Line> = content.lines().map(|line| self.format_line(line.to_string())).collect();
// We want newest at the top
text.reverse();
// Render the Paragraph
Expand Down

0 comments on commit b90bfe9

Please sign in to comment.