-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial implementation of rich output with emojis. (#1509)
Co-authored-by: Willem Wyndham <[email protected]> Co-authored-by: Leigh McCulloch <[email protected]>
- Loading branch information
1 parent
2c936d5
commit 70d56ca
Showing
7 changed files
with
155 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::fmt::Display; | ||
|
||
use soroban_env_host::xdr::{Error as XdrError, Transaction}; | ||
|
||
use crate::{ | ||
config::network::Network, | ||
utils::{explorer_url_for_transaction, transaction_hash}, | ||
}; | ||
|
||
pub struct Output { | ||
pub quiet: bool, | ||
} | ||
|
||
impl Output { | ||
pub fn new(quiet: bool) -> Output { | ||
Output { quiet } | ||
} | ||
|
||
fn print<T: Display>(&self, icon: &str, message: T) { | ||
if !self.quiet { | ||
eprintln!("{icon} {message}"); | ||
} | ||
} | ||
|
||
pub fn check<T: Display>(&self, message: T) { | ||
self.print("✅", message); | ||
} | ||
|
||
pub fn info<T: Display>(&self, message: T) { | ||
self.print("ℹ️", message); | ||
} | ||
|
||
pub fn globe<T: Display>(&self, message: T) { | ||
self.print("🌎", message); | ||
} | ||
|
||
pub fn link<T: Display>(&self, message: T) { | ||
self.print("🔗", message); | ||
} | ||
|
||
/// # Errors | ||
/// | ||
/// Might return an error | ||
pub fn log_transaction( | ||
&self, | ||
tx: &Transaction, | ||
network: &Network, | ||
show_link: bool, | ||
) -> Result<(), XdrError> { | ||
let tx_hash = transaction_hash(tx, &network.network_passphrase)?; | ||
let hash = hex::encode(tx_hash); | ||
|
||
self.info(format!("Transaction hash is {hash}").as_str()); | ||
|
||
if show_link { | ||
if let Some(url) = explorer_url_for_transaction(network, &hash) { | ||
self.link(url); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters