app
Resend Studio
Public Made by Adomby adom
A local editor for Resend email templates: paste your API key, then edit, preview, lint, test-send, and publish templates without Resend's dashboard. Also imports SendGrid dynamic templates and converts their Handlebars to Resend's variable syntax.
main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
use std::io::IsTerminal;
use std::sync::OnceLock;
const GREEN: &str = "\x1b[32m";
const RED: &str = "\x1b[31m";
const DIM: &str = "\x1b[2m";
const BOLD: &str = "\x1b[1m";
const RESET: &str = "\x1b[0m";
static STDOUT_IS_TTY: OnceLock<bool> = OnceLock::new();
static STDERR_IS_TTY: OnceLock<bool> = OnceLock::new();
fn stdout_is_tty() -> bool {
*STDOUT_IS_TTY.get_or_init(|| std::io::stdout().is_terminal())
}
fn stderr_is_tty() -> bool {
*STDERR_IS_TTY.get_or_init(|| std::io::stderr().is_terminal())
}
fn strip_ansi(s: &str) -> String {
let mut out = String::with_capacity(s.len());
let mut chars = s.chars().peekable();
while let Some(c) = chars.next() {
if c == '\x1b' && chars.peek() == Some(&'[') {
chars.next();
for c2 in chars.by_ref() {
if c2.is_ascii_alphabetic() {
break;
}
}
continue;
}
out.push(c);
}
out
}
pub fn ok(msg: impl std::fmt::Display) {
if stdout_is_tty() {
println!("{GREEN}{BOLD}OK:{RESET} {msg}");
} else {
println!("OK: {}", strip_ansi(&msg.to_string()));
}
}
pub fn err(msg: impl std::fmt::Display) {
if stderr_is_tty() {
eprintln!("{RED}{BOLD}ERROR:{RESET} {msg}");
} else {
eprintln!("ERROR: {}", strip_ansi(&msg.to_string()));
}
}
pub fn hint(msg: impl std::fmt::Display) {
if stderr_is_tty() {
eprintln!("{DIM}Hint:{RESET} {msg}");
} else {
eprintln!("Hint: {}", strip_ansi(&msg.to_string()));
}
}