Skip to content

Commit

Permalink
feat: add config setting to resize terminal (#3920)
Browse files Browse the repository at this point in the history
Description
---
- Added a config setting to resize the base node terminal
- Added terminal titles to base node, console wallet,  merge mining proxy and minining node.

Motivation and Context
---
See avbove

How Has This Been Tested?
---
System-level testing
  • Loading branch information
hansieodendaal committed Mar 31, 2022
1 parent be438ed commit ce697bd
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions applications/tari_base_node/src/commands/cli.rs
Expand Up @@ -23,7 +23,10 @@
use std::io::stdout;

use chrono::{Datelike, Utc};
use crossterm::{execute, terminal::SetSize};
use crossterm::{
execute,
terminal::{SetSize, SetTitle},
};
use tari_app_utilities::consts;

/// returns the top or bottom box line of the specified length
Expand Down Expand Up @@ -112,7 +115,12 @@ fn resize_terminal_to_fit_the_box(width: usize, height: usize) {
}

/// Prints a pretty banner on the console as well as the list of available commands
pub fn print_banner(commands: Vec<String>, chunk_size: i32) {
pub fn print_banner(commands: Vec<String>, chunk_size: i32, resize_terminal: bool) {
let terminal_title = format!("Tari Base Node - Version {}", consts::APP_VERSION);
if let Err(e) = execute!(stdout(), SetTitle(terminal_title.as_str())) {
println!("Error setting terminal title. {}", e)
}

let chunks: Vec<Vec<String>> = commands.chunks(chunk_size as usize).map(|x| x.to_vec()).collect();
let mut cell_sizes = Vec::new();

Expand Down Expand Up @@ -188,5 +196,7 @@ pub fn print_banner(commands: Vec<String>, chunk_size: i32) {
}
println!("{}", box_line(target_line_length, false));

resize_terminal_to_fit_the_box(target_line_length, height_to_resize);
if resize_terminal {
resize_terminal_to_fit_the_box(target_line_length, height_to_resize);
}
}
4 changes: 2 additions & 2 deletions applications/tari_base_node/src/commands/cli_loop.rs
Expand Up @@ -77,8 +77,8 @@ impl CliLoop {
///
/// ## Returns
/// Doesn't return anything
pub async fn cli_loop(mut self) {
cli::print_banner(self.commands.clone(), 3);
pub async fn cli_loop(mut self, resize_terminal_on_startup: bool) {
cli::print_banner(self.commands.clone(), 3, resize_terminal_on_startup);

if self.non_interactive {
self.watch_loop_non_interactive().await;
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_base_node/src/main.rs
Expand Up @@ -282,7 +282,7 @@ async fn run_node(
"Node has been successfully configured and initialized. Starting CLI loop."
);
}
task::spawn(main_loop.cli_loop());
task::spawn(main_loop.cli_loop(config.base_node_resize_terminal_on_startup));
if !config.force_sync_peers.is_empty() {
warn!(
target: LOG_TARGET,
Expand Down
12 changes: 7 additions & 5 deletions applications/tari_console_wallet/src/ui/mod.rs
Expand Up @@ -20,20 +20,18 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crossterm::terminal::SetTitle;
use log::error;
use tari_app_utilities::consts;
use tari_common::exit_codes::{ExitCode, ExitError};

use crate::utils::crossterm_events::CrosstermEvents;

mod app;
mod components;
mod widgets;

pub mod state;

mod ui_contact;
mod ui_error;

mod widgets;
use std::io::{stdout, Stdout, Write};

pub use app::*;
Expand Down Expand Up @@ -89,6 +87,10 @@ fn crossterm_loop(mut app: App<CrosstermBackend<Stdout>>) -> Result<(), ExitErro
error!(target: LOG_TARGET, "Error creating stdout context. {}", e);
ExitCode::InterfaceError
})?;
let terminal_title = format!("Tari Console Wallet - Version {}", consts::APP_VERSION);
if let Err(e) = execute!(stdout, SetTitle(terminal_title.as_str())) {
println!("Error setting terminal title. {}", e)
}

let backend = CrosstermBackend::new(stdout);

Expand Down
1 change: 1 addition & 0 deletions applications/tari_merge_mining_proxy/Cargo.toml
Expand Up @@ -21,6 +21,7 @@ tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.3.1" }

anyhow = "1.0.53"
crossterm = { version = "0.17" }
bincode = "1.3.1"
bytes = "1.1"
chrono = { version = "0.4.6", default-features = false }
Expand Down
13 changes: 11 additions & 2 deletions applications/tari_merge_mining_proxy/src/main.rs
Expand Up @@ -37,20 +37,29 @@ mod proxy;
#[cfg(test)]
mod test;

use std::convert::{Infallible, TryFrom};
use std::{
convert::{Infallible, TryFrom},
io::{stdout, Write},
};

use crossterm::{execute, terminal::SetTitle};
use futures::future;
use hyper::{service::make_service_fn, Server};
use proxy::{MergeMiningProxyConfig, MergeMiningProxyService};
use tari_app_grpc::tari_rpc as grpc;
use tari_app_utilities::initialization::init_configuration;
use tari_app_utilities::{consts, initialization::init_configuration};
use tari_common::configuration::bootstrap::ApplicationType;
use tokio::time::Duration;

use crate::{block_template_data::BlockTemplateRepository, error::MmProxyError};

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let terminal_title = format!("Tari Merge Mining Proxy - Version {}", consts::APP_VERSION);
if let Err(e) = execute!(stdout(), SetTitle(terminal_title.as_str())) {
println!("Error setting terminal title. {}", e)
}

let (_, config, _) = init_configuration(ApplicationType::MergeMiningProxy)?;

let config = match MergeMiningProxyConfig::try_from(config) {
Expand Down
1 change: 1 addition & 0 deletions applications/tari_mining_node/Cargo.toml
Expand Up @@ -16,6 +16,7 @@ tari_app_grpc = { path = "../tari_app_grpc" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.12.5" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.3.1" }

crossterm = { version = "0.17" }
crossbeam = "0.8"
futures = "0.3"
log = { version = "0.4", features = ["std"] }
Expand Down
14 changes: 12 additions & 2 deletions applications/tari_mining_node/src/main.rs
Expand Up @@ -20,15 +20,21 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{convert::TryFrom, thread, time::Instant};
use std::{
convert::TryFrom,
io::{stdout, Write},
thread,
time::Instant,
};

use config::MinerConfig;
use crossterm::{execute, terminal::SetTitle};
use errors::{err_empty, MinerError};
use futures::stream::StreamExt;
use log::*;
use miner::Miner;
use tari_app_grpc::tari_rpc::{base_node_client::BaseNodeClient, wallet_client::WalletClient};
use tari_app_utilities::initialization::init_configuration;
use tari_app_utilities::{consts, initialization::init_configuration};
use tari_common::{
configuration::bootstrap::ApplicationType,
exit_codes::{ExitCode, ExitError},
Expand Down Expand Up @@ -57,6 +63,10 @@ mod utils;
/// Application entry point
fn main() {
let rt = Runtime::new().expect("Failed to start tokio runtime");
let terminal_title = format!("Tari Mining Node - Version {}", consts::APP_VERSION);
if let Err(e) = execute!(stdout(), SetTitle(terminal_title.as_str())) {
println!("Error setting terminal title. {}", e)
}
match rt.block_on(main_inner()) {
Ok(_) => std::process::exit(0),
Err(err) => {
Expand Down
2 changes: 2 additions & 0 deletions common/config/presets/base_node.toml
Expand Up @@ -30,6 +30,8 @@ grpc_enabled = true
grpc_address = "/ip4/127.0.0.1/tcp/18142"
# Set to true to record all reorgs. Recorded reorgs can be viewed using the list-reorgs command.
track_reorgs = true
# Resize the base node terminal on startup equal to the banner size [default = true]
#resize_terminal_on_startup = true

# Configuration options for testnet dibbler
[base_node.dibbler]
Expand Down
5 changes: 5 additions & 0 deletions common/src/configuration/global.rs
Expand Up @@ -75,6 +75,7 @@ pub struct GlobalConfig {
pub base_node_event_channel_size: usize,
pub base_node_identity_file: PathBuf,
pub base_node_query_timeout: Duration,
pub base_node_resize_terminal_on_startup: bool,
pub base_node_status_line_interval: Duration,
pub base_node_tor_identity_file: PathBuf,
pub base_node_use_libtor: bool,
Expand Down Expand Up @@ -435,6 +436,9 @@ fn convert_node_config(
let key = config_string("base_node", net_str, "bypass_range_proof_verification");
let base_node_bypass_range_proof_verification = cfg.get_bool(&key).unwrap_or(false);

let key = "base_node.resize_terminal_on_startup".to_string();
let base_node_resize_terminal_on_startup = cfg.get_bool(&key).unwrap_or(true);

// Peer DB path
let comms_peer_db_path = data_dir.join("peer_db");
let wallet_peer_db_path = data_dir.join("wallet_peer_db");
Expand Down Expand Up @@ -835,6 +839,7 @@ fn convert_node_config(
base_node_event_channel_size,
base_node_identity_file,
base_node_query_timeout,
base_node_resize_terminal_on_startup,
base_node_status_line_interval,
base_node_tor_identity_file,
base_node_use_libtor,
Expand Down

0 comments on commit ce697bd

Please sign in to comment.