Change io crate & add a small shell

This commit is contained in:
2026-03-25 20:45:11 +01:00
parent f966a1239e
commit ae0593c972
98 changed files with 11102 additions and 810 deletions

7
crates/ansii/Cargo.toml Normal file
View File

@@ -0,0 +1,7 @@
[package]
name = "ansii"
version = "0.1.0"
edition = "2024"
[dependencies]
winnow = { version = "1", default-features = false, features = ["binary", "ascii"] }

66
crates/ansii/src/lib.rs Normal file
View File

@@ -0,0 +1,66 @@
#![no_std]
use winnow::Result;
use winnow::ascii::dec_uint;
use winnow::combinator::{alt, preceded, seq};
use winnow::error::ContextError;
use winnow::prelude::*;
pub enum AnsiiEscape {
Color16(ColorPlace, Color16Type, u8),
Color256(u8),
ColorRGB(ColorPlace, u8, u8, u8),
}
pub enum ColorPlace {
Foreground,
Background,
}
pub enum Color16Type {
Normal,
Bold,
Brigth,
}
fn parse_color16(input: &mut &str) -> Result<AnsiiEscape> {
let (c, _) = preceded("[", seq!(dec_uint, "m")).parse_next(input)?;
if c < 30 || c == 38 || c == 48 || c > 49 {
Err(ContextError::new())
} else {
Ok(AnsiiEscape::Color16(
ColorPlace::Foreground,
Color16Type::Normal,
c,
))
}
}
fn parse_color_rgb(input: &mut &str) -> Result<AnsiiEscape> {
let (t, _, r, _, g, _, b, _) = preceded(
"[",
seq!(
alt(("38", "48")),
";",
dec_uint,
";",
dec_uint,
";",
dec_uint,
"m"
),
)
.parse_next(input)?;
Ok(AnsiiEscape::ColorRGB(
if t == "38" {
ColorPlace::Foreground
} else {
ColorPlace::Background
},
r,
g,
b,
))
}
pub fn parse_ansii(input: &mut &str) -> Result<AnsiiEscape> {
alt((parse_color_rgb, parse_color16)).parse_next(input)
}