├── .gitignore ├── Cargo.toml ├── output_tests ├── Cargo.toml └── src │ └── main.rs ├── ansic-macros ├── README.md ├── Cargo.toml ├── src │ ├── detect.rs │ ├── error.rs │ ├── styles.rs │ └── lib.rs └── LICENSE ├── ansic ├── src │ ├── utils.rs │ └── lib.rs ├── Cargo.toml ├── README.md └── LICENSE ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | **/target 2 | **/Cargo.lock 3 | **/.DS_Store 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "3" 3 | members = ["ansic", "ansic-macros", "output_tests"] 4 | -------------------------------------------------------------------------------- /output_tests/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "output_tests" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | ansic-macros = {path="../ansic-macros"} 8 | -------------------------------------------------------------------------------- /ansic-macros/README.md: -------------------------------------------------------------------------------- 1 | ### Ansic-Macros 2 | Proc macros for ansic including the ansi! macro. refer to the main README.md at https://github.com/zeonzip/ansic for more information. 3 | -------------------------------------------------------------------------------- /output_tests/src/main.rs: -------------------------------------------------------------------------------- 1 | use ansic_macros::ansi; 2 | 3 | const ERROR: &str = ansi!(br.red bold underline italic); 4 | const RESET: &str = ansi!(reset); 5 | 6 | fn main() { 7 | println!("{:?}", ERROR); 8 | println!("{ERROR}[ERROR]:{RESET} Hello, world!"); 9 | } 10 | -------------------------------------------------------------------------------- /ansic/src/utils.rs: -------------------------------------------------------------------------------- 1 | /// Ideal when you want to easily style a dynamic string and terminate it and allocate a String for it at runtime. 2 | /// This is not a fully compiletime or no_std option as it allows for dynamic strings as text. If you want fully compile time, refer to the ansi! macro. 3 | /// ## Usage: 4 | /// ```rust 5 | /// styled!("myString", br.red bold underline) 6 | /// ``` 7 | /// 8 | /// In place of the "myString" literal can be anything that implemements Display. 9 | #[macro_export] 10 | macro_rules! styled { 11 | ($text:expr, $($style:tt)+) => {{ 12 | format!("{}{}{}", ansi!($($style)+), $text, ansi!(reset)) 13 | }} 14 | } 15 | -------------------------------------------------------------------------------- /ansic-macros/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ansic-macros" 3 | version = "0.1.0" 4 | authors = ["zeondev"] 5 | license = "Apache-2.0" 6 | description = "ansic's macros package containing the ansi! macro." 7 | repository = "https://github.com/zeonzip/ansic" 8 | homepage = "https://github.com/zeonzip/ansic" 9 | documentation = "https://docs.rs/ansic" 10 | keywords = ["macro", "ansi", "zerocost", "proc-macro", "compile-time"] 11 | categories = ["development-tools", "text-processing", "command-line-interface"] 12 | readme = "README.md" 13 | edition = "2024" 14 | 15 | [dependencies] 16 | proc-macro2 = "1.0.95" 17 | syn = "2.0.101" 18 | 19 | [lib] 20 | proc-macro = true 21 | -------------------------------------------------------------------------------- /ansic-macros/src/detect.rs: -------------------------------------------------------------------------------- 1 | // Argument parsing 2 | 3 | use crate::styles::AnsiStyle::{self, *}; 4 | use crate::styles::BasicAnsiStyle::*; 5 | use proc_macro2::Span; 6 | 7 | pub fn error(error: &str) -> syn::Error { 8 | syn::Error::new(Span::call_site(), error) 9 | } 10 | 11 | // Different arguments for colours 12 | pub enum ArgumentType { 13 | Bright, 14 | Background, 15 | } 16 | 17 | // parses arguments to their respective enum 18 | pub fn parse_arg(target: &str) -> Option { 19 | Some(match target { 20 | "bg" => ArgumentType::Background, 21 | "br" => ArgumentType::Bright, 22 | _ => return None, 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /ansic/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ansic" 3 | version = "0.1.7" 4 | edition = "2024" 5 | authors = ["zeondev"] 6 | license = "Apache-2.0" 7 | description = "Ansic is a crate which does ansi parsing in a dynamic DSL and at compile time for efficient and zero cost ansi styling." 8 | repository = "https://github.com/zeonzip/ansic" 9 | homepage = "https://github.com/zeonzip/ansic" 10 | documentation = "https://docs.rs/ansic" 11 | keywords = ["macro", "ansi", "zerocost", "proc-macro", "compile-time"] 12 | categories = ["development-tools", "text-processing", "command-line-interface"] 13 | readme = "README.md" 14 | 15 | [dependencies] 16 | ansic-macros = "0.1.0" 17 | 18 | [features] 19 | utils = [] 20 | 21 | [package.metadata.docs.rs] 22 | all-features = true 23 | rustdoc-args = ["--cfg", "docsrs"] 24 | -------------------------------------------------------------------------------- /ansic-macros/src/error.rs: -------------------------------------------------------------------------------- 1 | use crate::detect::error; 2 | 3 | pub enum AnsicMacroError<'a> { 4 | Unreachable, 5 | MultipleColorStyleArgs, 6 | InvalidRgbArg(i32, &'a str), 7 | MissingRgbArg(i32), 8 | InvalidStyleAndColor(&'a str), 9 | NoStyleOrColorTarget, 10 | RgbArgNotU8(&'a str), 11 | ExpectedRgbSyntax, 12 | } 13 | 14 | use AnsicMacroError::*; 15 | 16 | impl<'a> Into for AnsicMacroError<'a> { 17 | fn into(self) -> syn::Error { 18 | match self { 19 | Unreachable => error("Unreachable Error!"), 20 | MultipleColorStyleArgs => error("Gave multiple color/style arguments!"), 21 | InvalidRgbArg(index, content) => error( 22 | format!( 23 | "Argument {} isn't a valid RGB argument! (content: {})", 24 | index + 1, 25 | content, 26 | ) 27 | .as_str(), 28 | ), 29 | MissingRgbArg(index) => { 30 | error(format!("Missing the index {} argument for RGB colour.", index + 1).as_str()) 31 | } 32 | InvalidStyleAndColor(name) => { 33 | error(format!("{name} isn't a valid style/colour.").as_str()) 34 | } 35 | NoStyleOrColorTarget => error("No valid style or color target!"), 36 | RgbArgNotU8(arg) => { 37 | error(format!("RGB argument wasn't of u8. Found: {}", arg).as_str()) 38 | } 39 | ExpectedRgbSyntax => error("Expected RGB syntax: rgb(r, g, b)."), 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ansic/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] 3 | 4 | /// Contains optional utilities like vt_mode!() and styled!() 5 | #[cfg(feature = "utils")] 6 | pub mod utils; 7 | 8 | /// # The ansi! macro 9 | /// 10 | /// The proc macro directly returns the harcoded string result of the DSL syntax and styling you provided fully at compile time. 11 | /// 12 | /// Syntax: 13 | /// 14 | /// Each styling argument is passed to the ansi macro separated by a space as such: 15 | /// ```rust 16 | /// ansi!(red bold); 17 | /// ``` 18 | /// 19 | /// Each styling argument (which has a color target) may also have any combination of these arguments: 20 | /// - "br" - sets the target as a bright color 21 | /// - "bg" - sets the color as the background color 22 | /// 23 | /// Example with a red bright background and a bold style: 24 | /// ```rust 25 | /// ansi!(bg.br.red bold); 26 | /// ``` 27 | /// 28 | /// (foreground is the default of written colors so to specify a red foreground you can just write "red") 29 | /// 30 | /// We also Support rgb with the rgb(r, g, b) syntax like this: 31 | /// ```rust 32 | /// ansi!(rgb(255, 34, 55)); 33 | /// ``` 34 | /// 35 | /// Idiomatic ansic syntax is also storing styles in constants and using them to style in a much less verbose way: 36 | /// ```rust 37 | /// const ERROR: &str = ansi!(br.red bold underline italic); 38 | /// const RESET: &str = ansi!(reset); 39 | /// 40 | /// fn main() { 41 | /// println!("{ERROR}[ERROR]: Hello, world!{RESET}"); 42 | /// } 43 | /// ``` 44 | /// 45 | /// Rgb colors may also take bg as an argument but br won't have an effect 46 | /// ```rust 47 | /// ansi!(bg.rgb(255, 34, 55)) 48 | /// ``` 49 | /// 50 | /// ## All styles (doesnt support any arguments): 51 | /// - reset 52 | /// - bold 53 | /// - dim 54 | /// - italic 55 | /// - underline 56 | /// - blink 57 | /// - rapidblink (mostly deprecated) 58 | /// - invert 59 | /// - hidden 60 | /// - strikethrough (has alias: st) 61 | /// 62 | /// ## All colors (supports br and bg arguments): 63 | /// - black 64 | /// - red 65 | /// - green 66 | /// - yellow 67 | /// - blue 68 | /// - magenta 69 | /// - cyan 70 | /// - white 71 | /// 72 | /// Rgb color 24 bits (supports bg argument): 73 | /// - rgb(r, g, b) 74 | pub use ansic_macros::ansi; 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansic 2 | *The most efficient and easy ansi styling crate ever!* 3 | 4 | ![crates.io](https://img.shields.io/crates/v/ansic) ![docs.rs](https://img.shields.io/docsrs/ansic) 5 | 6 | Ansic is a crate which adds the ansi! proc macro, which allows for easy, simple and zero cost styling which happens at compiletime, in addition to other ansi utilities. (with default and 100% support for `#[no_std]`) 7 | 8 | ## Features: 9 | - Convenient and easy DSL syntax 10 | - Compiletime styling with proc macro 11 | - Zero cost at runtime 12 | - Encoded in static str's 13 | - #[no_std] 14 | 15 | Ansic directly outputs a &str literal with zero runtime implications. 16 | 17 | ## Usage: 18 | To make a red foreground, bold and underline ansi 19 | ```rust 20 | ansi!(red bold underline) 21 | ``` 22 | 23 | All color arguments can take these arguments: 24 | - "br" - bright 25 | - "bg" - background 26 | (rgb can only take bg) 27 | 28 | You can chain them like this if we want a red background: 29 | 30 | ```rust 31 | ansi!(bg.red bold underline) 32 | ``` 33 | 34 | Or if you want a red bright background you can do this: 35 | ```rust 36 | ansi!(bg.br.red bold underline) 37 | ``` 38 | 39 | In addition we can add a foreground color now that we have a background one. Let's add green! 40 | ```rust 41 | ansi!(bg.br.red green bold underline) 42 | ``` 43 | 44 | Idiomatic ansic syntax is also storing styles in constants and using them to style in a much less verbose way: 45 | 46 | ```rust 47 | const ERROR: &str = ansi!(br.red bold underline italic); 48 | const R: &str = ansi!(reset); 49 | 50 | fn main() { 51 | println!("{ERROR}[ERROR]: Hello, world!{R}"); 52 | } 53 | ``` 54 | 55 | Ansic also supports full RGB styles with the color syntax "rgb(r, g, b)". 56 | 57 | Ansic has alot more styles which you can find on our docs.rs page: [Ansic on Docs.rs](https://docs.rs/ansic); 58 | Ansic also has util macros and functions for more convenient use (listed under Comparisons) 59 | 60 | ## Comparisons 61 | 62 | | Feature | Ansic ✅ | owo-colors ⚠️/✅ | ansi_term ❌/⚠️ | 63 | |-----------------------------|--------------------|------------------------|------------------------| 64 | | FULLY Compile Time Generation | Yes ✅ | No ❌ | No ❌ | 65 | | Zero Runtime Cost | Yes ✅ | No ❌ | No ❌ | 66 | | Minimal Binary Size | Zero extra ✅ | Very Low ⚠️ | Medium ⚠️ | 67 | | Supports RGB Styles | Yes ✅ | Yes ✅ | No ❌ | 68 | | No-Std support | Yes ✅ | Yes ✅ | Yes ✅ | 69 | | Reusable Style Constants | Yes ✅ | Awkward ⚠️ | Partial ⚠️ | 70 | | Simple Macro DSL | Yes ✅ | No ❌ | No ❌ | 71 | | ANSI Reset Handling | Via `styled!` from `utils` ⚠️ | Automatic ✅ | Manual ⚠️ | 72 | | Text Injection | Yes ✅ | Yes ✅ | Yes ✅ | 73 | | Extensibility / Custom DSL | Yes ✅ | No ❌ | No ❌ | 74 | | Windows Compatibility | Can be enabled ✅ (via vt_mode!()) | Yes ✅ | Yes ✅ | 75 | | Well-maintained | New, active 🚧 | Yes ✅ | Mostly deprecated ⚠️ | 76 | 77 | 78 | ## Why ansic? 79 | There are tons of other ansi styling crates out there, so why `ansic`? 80 | Ansic is for people who need a ANSI styling crate, which more efficient, easier for maintainability or `#[no_std]`. 81 | Ansic solves this with a simple and very readable reuseability pattern, proc macro DSL, and being fully compile time letting you live without the stress of bigger binary sizes. 82 | -------------------------------------------------------------------------------- /ansic/README.md: -------------------------------------------------------------------------------- 1 | # Ansic 2 | *The most efficient and easy ansi styling crate ever!* 3 | 4 | ![crates.io](https://img.shields.io/crates/v/ansic) ![docs.rs](https://img.shields.io/docsrs/ansic) 5 | 6 | Ansic is a crate which adds the ansi! proc macro, which allows for easy, simple and zero cost styling which happens at compiletime, in addition to other ansi utilities. (with default and 100% support for `#[no_std]`) 7 | 8 | ## Features: 9 | - Convenient and easy DSL syntax 10 | - Compiletime styling with proc macro 11 | - Zero cost at runtime 12 | - Encoded in static str's 13 | - #[no_std] 14 | 15 | Ansic directly outputs a &str literal with zero runtime implications. 16 | 17 | ## Usage: 18 | To make a red foreground, bold and underline ansi 19 | ```rust 20 | ansi!(red bold underline) 21 | ``` 22 | 23 | All color arguments can take these arguments: 24 | - "br" - bright 25 | - "bg" - background 26 | (rgb can only take bg) 27 | 28 | You can chain them like this if we want a red background: 29 | 30 | ```rust 31 | ansi!(bg.red bold underline) 32 | ``` 33 | 34 | Or if you want a red bright background you can do this: 35 | ```rust 36 | ansi!(bg.br.red bold underline) 37 | ``` 38 | 39 | In addition we can add a foreground color now that we have a background one. Let's add green! 40 | ```rust 41 | ansi!(bg.br.red green bold underline) 42 | ``` 43 | 44 | Idiomatic ansic syntax is also storing styles in constants and using them to style in a much less verbose way: 45 | 46 | ```rust 47 | const ERROR: &str = ansi!(br.red bold underline italic); 48 | const R: &str = ansi!(reset); 49 | 50 | fn main() { 51 | println!("{ERROR}[ERROR]: Hello, world!{R}"); 52 | } 53 | ``` 54 | 55 | Ansic also supports full RGB styles with the color syntax "rgb(r, g, b)". 56 | 57 | Ansic has alot more styles which you can find on our docs.rs page: [Ansic on Docs.rs](https://docs.rs/ansic); 58 | Ansic also has util macros and functions for more convenient use (listed under Comparisons) 59 | 60 | ## Comparisons 61 | 62 | | Feature | Ansic ✅ | owo-colors ⚠️/✅ | ansi_term ❌/⚠️ | 63 | |-----------------------------|--------------------|------------------------|------------------------| 64 | | FULLY Compile Time Generation | Yes ✅ | No ❌ | No ❌ | 65 | | Zero Runtime Cost | Yes ✅ | No ❌ | No ❌ | 66 | | Minimal Binary Size | Zero extra ✅ | Very Low ⚠️ | Medium ⚠️ | 67 | | Supports RGB Styles | Yes ✅ | Yes ✅ | No ❌ | 68 | | No-Std support | Yes ✅ | Yes ✅ | Yes ✅ | 69 | | Reusable Style Constants | Yes ✅ | Awkward ⚠️ | Partial ⚠️ | 70 | | Simple Macro DSL | Yes ✅ | No ❌ | No ❌ | 71 | | ANSI Reset Handling | Via `styled!` from `utils` ⚠️ | Automatic ✅ | Manual ⚠️ | 72 | | Text Injection | Yes ✅ | Yes ✅ | Yes ✅ | 73 | | Extensibility / Custom DSL | Yes ✅ | No ❌ | No ❌ | 74 | | Windows Compatibility | Can be enabled ✅ (via vt_mode!()) | Yes ✅ | Yes ✅ | 75 | | Well-maintained | New, active 🚧 | Yes ✅ | Mostly deprecated ⚠️ | 76 | 77 | 78 | ## Why ansic? 79 | There are tons of other ansi styling crates out there, so why `ansic`? 80 | Ansic is for people who need a ANSI styling crate, which more efficient, easier for maintainability or `#[no_std]`. 81 | Ansic solves this with a simple and very readable reuseability pattern, proc macro DSL, and being fully compile time letting you live without the stress of bigger binary sizes. 82 | -------------------------------------------------------------------------------- /ansic-macros/src/styles.rs: -------------------------------------------------------------------------------- 1 | // Parsing of styles and colours 2 | 3 | use crate::{AnsiArg, detect::error}; 4 | 5 | #[repr(u8)] 6 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] 7 | pub enum BasicAnsiStyle { 8 | // Styles 9 | Reset = 0, 10 | Bold = 1, 11 | Dim = 2, 12 | Italic = 3, 13 | Underline = 4, 14 | Blink = 5, 15 | RapidBlink = 6, 16 | Invert = 7, 17 | Hidden = 8, 18 | Strikethrough = 9, 19 | 20 | // Foreground Colors 21 | FgBlack = 30, 22 | FgRed = 31, 23 | FgGreen = 32, 24 | FgYellow = 33, 25 | FgBlue = 34, 26 | FgMagenta = 35, 27 | FgCyan = 36, 28 | FgWhite = 37, 29 | 30 | // Bright Foreground 31 | FgBrightBlack = 90, 32 | FgBrightRed = 91, 33 | FgBrightGreen = 92, 34 | FgBrightYellow = 93, 35 | FgBrightBlue = 94, 36 | FgBrightMagenta = 95, 37 | FgBrightCyan = 96, 38 | FgBrightWhite = 97, 39 | 40 | // Background Colors 41 | BgBlack = 40, 42 | BgRed = 41, 43 | BgGreen = 42, 44 | BgYellow = 43, 45 | BgBlue = 44, 46 | BgMagenta = 45, 47 | BgCyan = 46, 48 | BgWhite = 47, 49 | 50 | // Bright Background 51 | BgBrightBlack = 100, 52 | BgBrightRed = 101, 53 | BgBrightGreen = 102, 54 | BgBrightYellow = 103, 55 | BgBrightBlue = 104, 56 | BgBrightMagenta = 105, 57 | BgBrightCyan = 106, 58 | BgBrightWhite = 107, 59 | } 60 | 61 | pub enum AnsiStyle { 62 | Basic(BasicAnsiStyle), 63 | FgRgb(u8, u8, u8), 64 | BgRgb(u8, u8, u8), 65 | } 66 | 67 | use AnsiStyle::*; 68 | use BasicAnsiStyle::*; 69 | 70 | impl AnsiStyle { 71 | pub fn to_color(bg: bool, bright: bool, name: &str, rgb: Option<(u8, u8, u8)>) -> Option { 72 | Some(Basic(match name.to_ascii_lowercase().as_str() { 73 | "black" => match (bg, bright) { 74 | (false, false) => FgBlack, 75 | (false, true) => FgBrightBlack, 76 | (true, false) => BgBlack, 77 | (true, true) => BgBrightBlack, 78 | }, 79 | "red" => match (bg, bright) { 80 | (false, false) => FgRed, 81 | (false, true) => FgBrightRed, 82 | (true, false) => BgRed, 83 | (true, true) => BgBrightRed, 84 | }, 85 | "green" => match (bg, bright) { 86 | (false, false) => FgGreen, 87 | (false, true) => FgBrightGreen, 88 | (true, false) => BgGreen, 89 | (true, true) => BgBrightGreen, 90 | }, 91 | "yellow" => match (bg, bright) { 92 | (false, false) => FgYellow, 93 | (false, true) => FgBrightYellow, 94 | (true, false) => BgYellow, 95 | (true, true) => BgBrightYellow, 96 | }, 97 | "blue" => match (bg, bright) { 98 | (false, false) => FgBlue, 99 | (false, true) => FgBrightBlue, 100 | (true, false) => BgBlue, 101 | (true, true) => BgBrightBlue, 102 | }, 103 | "magenta" => match (bg, bright) { 104 | (false, false) => FgMagenta, 105 | (false, true) => FgBrightMagenta, 106 | (true, false) => BgMagenta, 107 | (true, true) => BgBrightMagenta, 108 | }, 109 | "cyan" => match (bg, bright) { 110 | (false, false) => FgCyan, 111 | (false, true) => FgBrightCyan, 112 | (true, false) => BgCyan, 113 | (true, true) => BgBrightCyan, 114 | }, 115 | "white" => match (bg, bright) { 116 | (false, false) => FgWhite, 117 | (false, true) => FgBrightWhite, 118 | (true, false) => BgWhite, 119 | (true, true) => BgBrightWhite, 120 | }, 121 | "rgb" => { 122 | let (r, g, b) = rgb?; 123 | match bg { 124 | true => return Some(BgRgb(r, g, b)), 125 | false => return Some(FgRgb(r, g, b)), 126 | } 127 | } 128 | _ => return None, 129 | })) 130 | } 131 | 132 | pub fn to_style(name: &str) -> Option { 133 | Some(Basic(match name.to_ascii_lowercase().as_str() { 134 | "reset" => Reset, 135 | "bold" => Bold, 136 | "dim" => Dim, 137 | "italic" => Italic, 138 | "underline" => Underline, 139 | "blink" => Blink, 140 | "rapidblink" => RapidBlink, 141 | "invert" => Invert, 142 | "hidden" => Hidden, 143 | "strikethrough" => Strikethrough, 144 | "st" => Strikethrough, 145 | _ => return None, 146 | })) 147 | } 148 | 149 | pub fn code(self) -> String { 150 | match self { 151 | Basic(code) => (code as u8).to_string(), 152 | FgRgb(r, g, b) => format!("38;2;{r};{g};{b}"), 153 | BgRgb(r, g, b) => format!("48;2;{r};{g};{b}"), 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /ansic-macros/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Hey! This code does need a cleanup and some comments, so if you come over this 3 | * and is looking to contribute, this is a good place to start! 4 | */ 5 | 6 | use detect::{ArgumentType, error, parse_arg}; 7 | use error::AnsicMacroError; 8 | use proc_macro::{Delimiter, Literal, TokenStream, TokenTree}; 9 | use styles::AnsiStyle; 10 | 11 | mod detect; 12 | mod error; 13 | mod styles; 14 | 15 | const ANSI_PREFIX: &'static str = "\x1b["; 16 | 17 | struct AnsiArg<'a> { 18 | pub name: &'a str, 19 | pub rgb: Option<(u8, u8, u8)>, 20 | pub bright: bool, 21 | pub bg: bool, 22 | } 23 | 24 | impl<'a> AnsiArg<'a> { 25 | fn generate_ansi(self) -> Option { 26 | if let Some(style) = AnsiStyle::to_style(self.name) { 27 | return Some(style.code()); 28 | } else if let Some(color) = AnsiStyle::to_color(self.bg, self.bright, self.name, self.rgb) { 29 | return Some(color.code()); 30 | } 31 | 32 | None 33 | } 34 | } 35 | 36 | fn generate_ansiarg(args: Vec, name: &str, rgb: Option<(u8, u8, u8)>) -> AnsiArg { 37 | let mut profile = AnsiArg { 38 | name, 39 | bright: false, 40 | bg: false, 41 | rgb, 42 | }; 43 | 44 | for arg in args { 45 | match arg { 46 | ArgumentType::Background => profile.bg = true, 47 | ArgumentType::Bright => profile.bright = true, 48 | } 49 | } 50 | 51 | profile 52 | } 53 | 54 | fn generate(args: Vec) -> Result { 55 | let mut args_iter = args.iter().peekable(); 56 | 57 | let mut name: Option<&str> = None; 58 | let mut rgb: Option<(u8, u8, u8)> = None; 59 | let mut args: Vec = Vec::new(); 60 | 61 | while let Some(arg) = args_iter.next() { 62 | if arg == "rgb" { 63 | if let Some(_) = name { 64 | return Err(AnsicMacroError::MultipleColorStyleArgs.into()); 65 | } 66 | 67 | name = Some(arg); 68 | let (mut r, mut g, mut b): (u8, u8, u8) = (0, 0, 0); 69 | 70 | for i in 0..3 { 71 | if let Some(res) = args_iter.next() { 72 | if let Ok(num) = res.parse::() { 73 | match i { 74 | 0 => r = num, 75 | 1 => g = num, 76 | 2 => b = num, 77 | _ => return Err(AnsicMacroError::Unreachable.into()), 78 | } 79 | } else { 80 | return Err(AnsicMacroError::InvalidRgbArg(i, res).into()); 81 | } 82 | } else { 83 | return Err(AnsicMacroError::MissingRgbArg(i).into()); 84 | } 85 | } 86 | 87 | rgb = Some((r, g, b)); 88 | } else if let Some(color) = AnsiStyle::to_color(false, false, arg, None) { 89 | if let Some(_) = name { 90 | return Err(AnsicMacroError::MultipleColorStyleArgs.into()); 91 | } 92 | 93 | name = Some(arg) 94 | } else if let Some(style) = AnsiStyle::to_style(arg) { 95 | if let Some(_) = name { 96 | return Err(AnsicMacroError::MultipleColorStyleArgs.into()); 97 | } 98 | 99 | name = Some(arg) 100 | } else if let Some(targ) = parse_arg(arg) { 101 | args.push(targ); 102 | } else { 103 | return Err(AnsicMacroError::InvalidStyleAndColor(arg).into()); 104 | } 105 | } 106 | 107 | if let Some(fname) = name { 108 | let arg = generate_ansiarg(args, fname, rgb); 109 | 110 | if let Some(data) = arg.generate_ansi() { 111 | return Ok(data); 112 | } 113 | 114 | return Err(AnsicMacroError::Unreachable.into()); 115 | } 116 | 117 | Err(AnsicMacroError::NoStyleOrColorTarget.into()) 118 | } 119 | 120 | fn generate_ansi(args: Vec>) -> Result { 121 | let mut ansi_code = ANSI_PREFIX.to_string(); 122 | 123 | let argslen = args.len(); 124 | 125 | for (i, arg) in args.into_iter().enumerate() { 126 | let parsed = generate(arg)?; 127 | 128 | if argslen - 1 == i { 129 | ansi_code.push_str(&format!("{}m", parsed)); 130 | } else { 131 | ansi_code.push_str(&format!("{};", parsed)); 132 | } 133 | } 134 | 135 | Ok(ansi_code) 136 | } 137 | 138 | fn generate_tokens(tokens: TokenStream) -> Result>, syn::Error> { 139 | let mut result = Vec::new(); 140 | let mut current = Vec::new(); 141 | 142 | let mut token_iter = tokens.into_iter().peekable(); 143 | 144 | while let Some(token) = token_iter.next() { 145 | match &token { 146 | TokenTree::Ident(ident) => { 147 | current.push(ident.to_string()); 148 | 149 | if ident.to_string() == "rgb" { 150 | match token_iter.peek() { 151 | Some(TokenTree::Group(parens)) => { 152 | if parens.delimiter() == Delimiter::Parenthesis { 153 | // pstream is the tokenstream inside theparenthesis 154 | let pstream = parens.stream(); 155 | let mut stream_iter = pstream.into_iter().peekable(); 156 | 157 | while let Some(token) = stream_iter.next() { 158 | match token { 159 | TokenTree::Literal(lit) => { 160 | let s = lit.to_string(); 161 | 162 | if let Ok(num) = s.parse::() { 163 | current.push(s); 164 | 165 | match stream_iter.peek() { 166 | Some(TokenTree::Punct(p)) 167 | if p.as_char() == ',' => 168 | { 169 | stream_iter.next(); 170 | } 171 | _ => { 172 | result.push(current); 173 | current = Vec::new(); 174 | } 175 | } 176 | } else { 177 | return Err(AnsicMacroError::RgbArgNotU8(&s).into()); 178 | } 179 | } 180 | _ => {} 181 | } 182 | } 183 | } 184 | } 185 | _ => { 186 | return Err(AnsicMacroError::ExpectedRgbSyntax.into()); 187 | } 188 | } 189 | 190 | continue; 191 | } 192 | 193 | match token_iter.peek() { 194 | Some(TokenTree::Punct(p)) if p.as_char() == '.' => { 195 | token_iter.next(); 196 | } 197 | _ => { 198 | result.push(current); 199 | current = Vec::new(); 200 | } 201 | } 202 | } 203 | _ => {} 204 | } 205 | } 206 | 207 | Ok(result) 208 | } 209 | 210 | #[proc_macro] 211 | pub fn ansi(input: TokenStream) -> TokenStream { 212 | let tokens = generate_tokens(input); 213 | 214 | if let Ok(args) = tokens { 215 | let result = generate_ansi(args); 216 | 217 | if let Ok(ansi_code) = result { 218 | let lit = TokenTree::Literal(Literal::string(&ansi_code)); 219 | return TokenStream::from(lit); 220 | } else if let Err(err) = result { 221 | return err.to_compile_error().into(); 222 | } else { 223 | let err: syn::Error = AnsicMacroError::Unreachable.into(); 224 | 225 | return err.to_compile_error().into(); 226 | } 227 | } else if let Err(err) = tokens { 228 | return err.to_compile_error().into(); 229 | } else { 230 | let err: syn::Error = AnsicMacroError::Unreachable.into(); 231 | 232 | return err.to_compile_error().into(); 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /ansic/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /ansic-macros/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------