#![deny(missing_docs)]
#![deny(clippy::all)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
mod color;
mod escape;
mod modifier;
mod parser;
mod sequence;
mod style;
pub use color::Color;
#[cfg(feature = "brand")]
pub use color::brand;
pub use escape::{Escape, EscapeKind};
pub use modifier::Modifier;
pub use parser::{parse, strip_ansi, visible_len, ParsedSequence};
pub use sequence::{Sequence, SequenceBuilder};
pub use style::{style, Style, Styled};
pub const CSI: &str = "\x1b[";
pub const OSC: &str = "\x1b]";
pub const SGR_SUFFIX: &str = "m";
pub const RESET: &str = "\x1b[0m";
pub mod sequences {
pub const CLEAR_SCREEN: &str = "\x1b[2J";
pub const CLEAR_TO_END: &str = "\x1b[0J";
pub const CLEAR_TO_START: &str = "\x1b[1J";
pub const CLEAR_LINE: &str = "\x1b[2K";
pub const CLEAR_LINE_TO_END: &str = "\x1b[0K";
pub const CLEAR_LINE_TO_START: &str = "\x1b[1K";
pub const CURSOR_HOME: &str = "\x1b[H";
pub const CURSOR_HIDE: &str = "\x1b[?25l";
pub const CURSOR_SHOW: &str = "\x1b[?25h";
pub const CURSOR_SAVE: &str = "\x1b[s";
pub const CURSOR_RESTORE: &str = "\x1b[u";
pub const ALT_SCREEN_ENTER: &str = "\x1b[?1049h";
pub const ALT_SCREEN_EXIT: &str = "\x1b[?1049l";
pub const MOUSE_ENABLE: &str = "\x1b[?1000h";
pub const MOUSE_DISABLE: &str = "\x1b[?1000l";
pub const BRACKETED_PASTE_ENABLE: &str = "\x1b[?2004h";
pub const BRACKETED_PASTE_DISABLE: &str = "\x1b[?2004l";
}
pub mod cursor {
#[must_use]
pub fn up(n: u16) -> String {
format!("\x1b[{n}A")
}
#[must_use]
pub fn down(n: u16) -> String {
format!("\x1b[{n}B")
}
#[must_use]
pub fn right(n: u16) -> String {
format!("\x1b[{n}C")
}
#[must_use]
pub fn left(n: u16) -> String {
format!("\x1b[{n}D")
}
#[must_use]
pub fn goto(row: u16, col: u16) -> String {
format!("\x1b[{row};{col}H")
}
#[must_use]
pub fn column(col: u16) -> String {
format!("\x1b[{col}G")
}
}
pub mod prelude {
pub use crate::color::Color;
pub use crate::modifier::Modifier;
pub use crate::style::{style, Style, Styled};
pub use crate::{cursor, sequences, RESET};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_style_basic() {
let s = style("test").fg(Color::Red).to_string();
assert!(s.contains("\x1b["));
assert!(s.contains("test"));
assert!(s.ends_with(RESET));
}
#[test]
fn test_cursor_movement() {
assert_eq!(cursor::up(5), "\x1b[5A");
assert_eq!(cursor::goto(10, 20), "\x1b[10;20H");
}
}