Skip to content

Commit

Permalink
Merge branch 'main' into feat/sign_with_lab
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman authored Sep 6, 2024
2 parents 800e802 + cd76196 commit abb0db6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/soroban-cli/src/print.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{env, fmt::Display};

use soroban_env_host::xdr::{Error as XdrError, Transaction};

Expand All @@ -7,6 +7,8 @@ use crate::{
utils::{explorer_url_for_transaction, transaction_hash},
};

const TERMS: &[&str] = &["Apple_Terminal", "vscode"];

pub struct Print {
pub quiet: bool,
}
Expand Down Expand Up @@ -36,6 +38,19 @@ impl Print {
}
}

// Some terminals like vscode's and macOS' default terminal will not render
// the subsequent space if the emoji codepoints size is 2; in this case,
// we need an additional space.
pub fn compute_emoji<T: Display + Sized>(&self, emoji: T) -> String {
if let Ok(term_program) = env::var("TERM_PROGRAM") {
if TERMS.contains(&term_program.as_str()) && emoji.to_string().chars().count() == 2 {
return format!("{emoji} ");
}
}

emoji.to_string()
}

/// # Errors
///
/// Might return an error
Expand Down Expand Up @@ -66,14 +81,14 @@ macro_rules! create_print_functions {
#[allow(dead_code)]
pub fn $name<T: Display + Sized>(&self, message: T) {
if !self.quiet {
eprint!("{} {}", $icon, message);
eprint!("{} {}", self.compute_emoji($icon), message);
}
}

#[allow(dead_code)]
pub fn $nameln<T: Display + Sized>(&self, message: T) {
if !self.quiet {
eprintln!("{} {}", $icon, message);
eprintln!("{} {}", self.compute_emoji($icon), message);
}
}
}
Expand Down

0 comments on commit abb0db6

Please sign in to comment.