use owo_colors::OwoColorize;
use std::fmt::Display;
use crate::disasm::{AsmKind, AsmToken};
use crate::types::VirtAddr;
pub fn addr(value: u64) -> String {
format!("{value:016x}")
}
pub fn addr_opt(value: VirtAddr) -> String {
if value.is_zero() {
muted("unavailable")
} else {
addr(value.0)
}
}
pub fn symbol(sym: &str) -> String {
if sym.starts_with("0x") {
return muted(sym);
}
let (body, offset) = match sym.rfind("+0x") {
Some(idx) => (&sym[..idx], &sym[idx..]),
None => (sym, ""),
};
let body = body.bright_blue().to_string();
if offset.is_empty() {
body
} else {
format!("{}{}", body, muted(offset))
}
}
pub fn muted(text: &str) -> String {
text.bright_black().to_string()
}
pub fn label(text: &str) -> String {
text.bold().to_string()
}
pub fn disasm_asm(tokens: &[AsmToken]) -> String {
let mut out = String::new();
for token in tokens {
match token.kind {
AsmKind::Register => out.push_str(&token.text.cyan().to_string()),
AsmKind::Number => out.push_str(&token.text.green().to_string()),
AsmKind::Punctuation | AsmKind::Keyword => out.push_str(&muted(&token.text)),
AsmKind::Mnemonic => out.push_str(&token.text.bright_magenta().to_string()),
AsmKind::Text => out.push_str(&token.text),
}
}
out
}
pub fn bp_id(id: impl Display) -> String {
format!("#{id}").cyan().to_string()
}
pub fn thread_id(id: &str) -> String {
id.cyan().to_string()
}
pub fn badge(text: &str) -> String {
format!(" {text} ").white().on_red().to_string()
}
pub fn plate(text: &str) -> String {
text.on_black().to_string()
}