Skip to content

Commit 6f9bdd5

Browse files
authored
Add better emoji support for unknown terminals. (#2279)
1 parent b05bc12 commit 6f9bdd5

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

cmd/soroban-cli/src/print.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use crate::{
77
config::network::Network, utils::explorer_url_for_transaction, utils::transaction_hash,
88
};
99

10-
const TERMS: &[&str] = &["Apple_Terminal", "vscode"];
11-
1210
#[derive(Clone)]
1311
pub struct Print {
1412
pub quiet: bool,
@@ -45,14 +43,13 @@ impl Print {
4543

4644
// Some terminals like vscode's and macOS' default terminal will not render
4745
// the subsequent space if the emoji codepoints size is 2; in this case,
48-
// we need an additional space.
46+
// we need an additional space. We also need an additional space if `TERM_PROGRAM` is not
47+
// defined (e.g. vhs running in a docker container).
4948
pub fn compute_emoji<T: Display + Sized>(&self, emoji: T) -> String {
50-
if let Ok(term_program) = env::var("TERM_PROGRAM") {
51-
if TERMS.contains(&term_program.as_str())
52-
&& (emoji.to_string().chars().count() == 2 || format!("{emoji}") == " ")
53-
{
54-
return format!("{emoji} ");
55-
}
49+
if should_add_additional_space()
50+
&& (emoji.to_string().chars().count() == 2 || format!("{emoji}") == " ")
51+
{
52+
return format!("{emoji} ");
5653
}
5754

5855
emoji.to_string()
@@ -102,6 +99,17 @@ macro_rules! create_print_functions {
10299
};
103100
}
104101

102+
fn should_add_additional_space() -> bool {
103+
const TERMS: &[&str] = &["Apple_Terminal", "vscode", "unknown"];
104+
let term_program = env::var("TERM_PROGRAM").unwrap_or("unknown".to_string());
105+
106+
if TERMS.contains(&term_program.as_str()) {
107+
return true;
108+
}
109+
110+
false
111+
}
112+
105113
create_print_functions!(bucket, bucketln, "🪣");
106114
create_print_functions!(check, checkln, "✅");
107115
create_print_functions!(error, errorln, "❌");

0 commit comments

Comments
 (0)