From f645937a2b9ff8af1a2d64327b85293e4136b57d Mon Sep 17 00:00:00 2001 From: Gary Yu Date: Sat, 3 Nov 2018 16:42:41 +0800 Subject: [PATCH] replace cyan and yellow which not easy to read on white background (#1903) * replace cyan and yellow which not easy to read on white background * wallet output color scheme configuration for terminal dark/white background * use true for dark_background_color_scheme to make the default behavior same as before --- config/src/comments.rs | 6 ++ src/bin/cmd/wallet.rs | 32 ++++++++-- wallet/src/display.rs | 136 ++++++++++++++++++++++++++++++----------- wallet/src/types.rs | 4 ++ 4 files changed, 140 insertions(+), 38 deletions(-) diff --git a/config/src/comments.rs b/config/src/comments.rs index e2aa80c30..3a2dda559 100644 --- a/config/src/comments.rs +++ b/config/src/comments.rs @@ -344,6 +344,12 @@ fn comments() -> HashMap { "data_file_dir".to_string(), " #where to find wallet files (seed, data, etc) +".to_string(), + ); + retval.insert( + "dark_background_color_scheme".to_string(), + " +#Whether to use the black background color scheme for command line ".to_string(), ); diff --git a/src/bin/cmd/wallet.rs b/src/bin/cmd/wallet.rs index 565bcde12..03376dfa0 100644 --- a/src/bin/cmd/wallet.rs +++ b/src/bin/cmd/wallet.rs @@ -434,13 +434,24 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) { e, wallet_config )) })?; - display::info(account, &wallet_info, validated); + display::info( + account, + &wallet_info, + validated, + wallet_config.dark_background_color_scheme.unwrap(), + ); Ok(()) } ("outputs", Some(_)) => { let (height, _) = api.node_height()?; let (validated, outputs) = api.retrieve_outputs(show_spent, true, None)?; - display::outputs(account, height, validated, outputs).map_err(|e| { + display::outputs( + account, + height, + validated, + outputs, + wallet_config.dark_background_color_scheme.unwrap(), + ).map_err(|e| { ErrorKind::GenericError(format!( "Error getting wallet outputs: {:?} Config: {:?}", e, wallet_config @@ -462,7 +473,14 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) { let (height, _) = api.node_height()?; let (validated, txs) = api.retrieve_txs(true, tx_id)?; let include_status = !tx_id.is_some(); - display::txs(account, height, validated, txs, include_status).map_err(|e| { + display::txs( + account, + height, + validated, + txs, + include_status, + wallet_config.dark_background_color_scheme.unwrap(), + ).map_err(|e| { ErrorKind::GenericError(format!( "Error getting wallet outputs: {} Config: {:?}", e, wallet_config @@ -472,7 +490,13 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) { // inputs/outputs if tx_id.is_some() { let (_, outputs) = api.retrieve_outputs(true, false, tx_id)?; - display::outputs(account, height, validated, outputs).map_err(|e| { + display::outputs( + account, + height, + validated, + outputs, + wallet_config.dark_background_color_scheme.unwrap(), + ).map_err(|e| { ErrorKind::GenericError(format!( "Error getting wallet outputs: {} Config: {:?}", e, wallet_config diff --git a/wallet/src/display.rs b/wallet/src/display.rs index 93fbd6e93..1f7c52dfc 100644 --- a/wallet/src/display.rs +++ b/wallet/src/display.rs @@ -27,6 +27,7 @@ pub fn outputs( cur_height: u64, validated: bool, outputs: Vec<(OutputData, pedersen::Commitment)>, + dark_background_color_scheme: bool, ) -> Result<(), Error> { let title = format!( "Wallet Outputs - Account '{}' - Block Height: {}", @@ -69,16 +70,30 @@ pub fn outputs( None => "".to_owned(), Some(t) => t.to_string(), }; - table.add_row(row![ - bFC->commit, - bFB->height, - bFB->lock_height, - bFR->status, - bFY->is_coinbase, - bFB->num_confirmations, - bFG->value, - bFC->tx, - ]); + + if dark_background_color_scheme { + table.add_row(row![ + bFC->commit, + bFB->height, + bFB->lock_height, + bFR->status, + bFY->is_coinbase, + bFB->num_confirmations, + bFG->value, + bFC->tx, + ]); + } else { + table.add_row(row![ + bFD->commit, + bFB->height, + bFB->lock_height, + bFR->status, + bFD->is_coinbase, + bFB->num_confirmations, + bFG->value, + bFD->tx, + ]); + } } table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP); @@ -102,6 +117,7 @@ pub fn txs( validated: bool, txs: Vec, include_status: bool, + dark_background_color_scheme: bool, ) -> Result<(), Error> { let title = format!( "Transaction Log - Account '{}' - Block Height: {}", @@ -164,21 +180,57 @@ pub fn txs( Some(_) => format!("Exists"), None => "None".to_owned(), }; - table.add_row(row![ - bFC->id, - bFC->entry_type, - bFC->slate_id, - bFB->creation_ts, - bFC->confirmed, - bFB->confirmation_ts, - bFC->num_inputs, - bFC->num_outputs, - bFG->amount_credited_str, - bFR->amount_debited_str, - bFR->fee, - bFY->net_diff, - bFb->tx_data, - ]); + if dark_background_color_scheme { + table.add_row(row![ + bFC->id, + bFC->entry_type, + bFC->slate_id, + bFB->creation_ts, + bFC->confirmed, + bFB->confirmation_ts, + bFC->num_inputs, + bFC->num_outputs, + bFG->amount_credited_str, + bFR->amount_debited_str, + bFR->fee, + bFY->net_diff, + bFb->tx_data, + ]); + } else { + if t.confirmed { + table.add_row(row![ + bFD->id, + bFb->entry_type, + bFD->slate_id, + bFB->creation_ts, + bFg->confirmed, + bFB->confirmation_ts, + bFD->num_inputs, + bFD->num_outputs, + bFG->amount_credited_str, + bFD->amount_debited_str, + bFD->fee, + bFG->net_diff, + bFB->tx_data, + ]); + } else { + table.add_row(row![ + bFD->id, + bFb->entry_type, + bFD->slate_id, + bFB->creation_ts, + bFR->confirmed, + bFB->confirmation_ts, + bFD->num_inputs, + bFD->num_outputs, + bFG->amount_credited_str, + bFD->amount_debited_str, + bFD->fee, + bFG->net_diff, + bFB->tx_data, + ]); + } + } } table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP); @@ -195,19 +247,35 @@ pub fn txs( Ok(()) } /// Display summary info in a pretty way -pub fn info(account: &str, wallet_info: &WalletInfo, validated: bool) { +pub fn info( + account: &str, + wallet_info: &WalletInfo, + validated: bool, + dark_background_color_scheme: bool, +) { println!( "\n____ Wallet Summary Info - Account '{}' as of height {} ____\n", account, wallet_info.last_confirmed_height ); - let mut table = table!( - [bFG->"Total", FG->amount_to_hr_string(wallet_info.total, false)], - [bFY->"Awaiting Confirmation", FY->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)], - [bFY->"Immature Coinbase", FY->amount_to_hr_string(wallet_info.amount_immature, false)], - [bFG->"Currently Spendable", FG->amount_to_hr_string(wallet_info.amount_currently_spendable, false)], - [Fw->"---------", Fw->"---------"], - [Fr->"(Locked by previous transaction)", Fr->amount_to_hr_string(wallet_info.amount_locked, false)] - ); + let mut table = if dark_background_color_scheme { + table!( + [bFG->"Total", FG->amount_to_hr_string(wallet_info.total, false)], + [bFY->"Awaiting Confirmation", FY->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)], + [bFY->"Immature Coinbase", FY->amount_to_hr_string(wallet_info.amount_immature, false)], + [bFG->"Currently Spendable", FG->amount_to_hr_string(wallet_info.amount_currently_spendable, false)], + [Fw->"--------------------------------", Fw->"-------------"], + [Fr->"(Locked by previous transaction)", Fr->amount_to_hr_string(wallet_info.amount_locked, false)] + ) + } else { + table!( + [bFG->"Total", FG->amount_to_hr_string(wallet_info.total, false)], + [bFB->"Awaiting Confirmation", FB->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)], + [bFB->"Immature Coinbase", FB->amount_to_hr_string(wallet_info.amount_immature, false)], + [bFG->"Currently Spendable", FG->amount_to_hr_string(wallet_info.amount_currently_spendable, false)], + [Fw->"--------------------------------", Fw->"-------------"], + [Fr->"(Locked by previous transaction)", Fr->amount_to_hr_string(wallet_info.amount_locked, false)] + ) + }; table.set_format(*prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR); table.printstd(); println!(); diff --git a/wallet/src/types.rs b/wallet/src/types.rs index 8df0028b1..70de81ff1 100644 --- a/wallet/src/types.rs +++ b/wallet/src/types.rs @@ -51,6 +51,9 @@ pub struct WalletConfig { pub tls_certificate_file: Option, /// TLS ceritificate private key file pub tls_certificate_key: Option, + /// Whether to use the black background color scheme for command line + /// if enabled, wallet command output color will be suitable for black background terminal + pub dark_background_color_scheme: Option, } impl Default for WalletConfig { @@ -65,6 +68,7 @@ impl Default for WalletConfig { data_file_dir: ".".to_string(), tls_certificate_file: None, tls_certificate_key: None, + dark_background_color_scheme: Some(true), } } }