2023-10-08 16:34:55 +11:00
|
|
|
use ansi_markup::parse_ansi_markup;
|
2023-06-03 23:47:29 +10:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use quote::ToTokens;
|
|
|
|
use syn::{parse_macro_input, Lit};
|
2022-12-24 01:34:01 +11:00
|
|
|
|
|
|
|
#[proc_macro]
|
|
|
|
pub fn ansi(input: TokenStream) -> TokenStream {
|
|
|
|
let raw = match parse_macro_input!(input as Lit) {
|
|
|
|
Lit::Str(lit_str) => lit_str.value(),
|
2023-06-03 23:47:29 +10:00
|
|
|
_ => panic!("Expected a string literal"),
|
2022-12-24 01:34:01 +11:00
|
|
|
};
|
2023-06-03 23:47:29 +10:00
|
|
|
TokenStream::from(
|
2023-10-08 16:34:55 +11:00
|
|
|
parse_ansi_markup(&raw)
|
2023-06-03 23:47:29 +10:00
|
|
|
.unwrap_or_else(|e| panic!("Bad ansi literal: {}", e))
|
|
|
|
.into_token_stream(),
|
|
|
|
)
|
2022-12-24 01:34:01 +11:00
|
|
|
}
|