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
This commit is contained in:
Gary Yu 2018-11-03 16:42:41 +08:00 committed by hashmap
parent cc63fe4d32
commit f645937a2b
4 changed files with 140 additions and 38 deletions

View file

@ -344,6 +344,12 @@ fn comments() -> HashMap<String, String> {
"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(),
);

View file

@ -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

View file

@ -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<TxLogEntry>,
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!();

View file

@ -51,6 +51,9 @@ pub struct WalletConfig {
pub tls_certificate_file: Option<String>,
/// TLS ceritificate private key file
pub tls_certificate_key: Option<String>,
/// 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<bool>,
}
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),
}
}
}