forked from ratatui/ansi-to-tui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete rewrite of the whole parser logic
now using nom instead of manually iterating over bytes however the parsing may now fail in case of malformed text
- Loading branch information
1 parent
92736b3
commit 0e28929
Showing
9 changed files
with
384 additions
and
619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
[package] | ||
name = "ansi-to-tui" | ||
version = "0.5.0" | ||
authors = ["Uttarayan Mondal <uttarayan21@gmail.com>"] | ||
version = "1.0.1" | ||
authors = ["Uttarayan Mondal <email@uttarayan.me>"] | ||
edition = "2018" | ||
description = "A library to convert ansi color coded text into tui::text::Text type from tui-rs library" | ||
keywords = ["ansi", "ascii", "tui", "parser"] | ||
license = "MIT" | ||
readme = "README.md" | ||
repository = "https://github.com/uttarayan21/ansi-to-tui" | ||
exclude = [ | ||
".github/*", | ||
"ascii", | ||
"tests", | ||
] | ||
|
||
[dependencies] | ||
simdutf8 = { version = "0.1.1", optional = true } | ||
tui = { version = "0.17.0", default-features = false } | ||
nom = "7.1.1" | ||
simdutf8 = { version = "0.1.4", optional = true } | ||
tui = { version = "0.18.0", default-features = false } | ||
thiserror = "1.0.31" | ||
|
||
[dev-dependencies] | ||
anyhow = "1.0.40" | ||
anyhow = "1.0.58" | ||
|
||
[features] | ||
simd = ["simdutf8"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[31;42mAAAA[32;41mBBBB | ||
[0;38;2;123;223;23mTRUECOLOR[0m | ||
[0;38;2;123;223;23mTRUECOLOR[0m |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,24 @@ | ||
#[cfg(feature = "simd")] | ||
use simdutf8::basic::Utf8Error; | ||
#[cfg(not(feature = "simd"))] | ||
use std::string::FromUtf8Error; | ||
|
||
use std::error::Error as StdErr; | ||
|
||
/// This enum stores the error types | ||
#[derive(Debug)] | ||
#[derive(Debug, thiserror::Error, PartialEq)] | ||
pub enum Error { | ||
/// Stack is empty (should never happen) | ||
StackEmpty, | ||
#[error("Nom Error")] | ||
NomError(String), | ||
|
||
/// Error parsing the input as utf-8 | ||
Utf8Error, | ||
#[cfg(feature = "simdutf8")] | ||
/// Cannot determine the foreground or background | ||
UnknownLayer, | ||
/// Error while parsing the color | ||
ColorParsingError, | ||
/// Error while paring the ansi sequnce as a usize ( should really be u8 max ) | ||
UsizeParsingError, | ||
} | ||
#[error("{0:?}")] | ||
Utf8Error(#[from] simdutf8::basic::Utf8Error), | ||
|
||
#[cfg(not(feature = "simd"))] | ||
impl From<FromUtf8Error> for Error { | ||
fn from(_: FromUtf8Error) -> Self { | ||
Error::Utf8Error | ||
} | ||
} | ||
#[cfg(feature = "simd")] | ||
impl From<Utf8Error> for Error { | ||
fn from(_: Utf8Error) -> Self { | ||
Error::Utf8Error | ||
} | ||
#[cfg(not(feature = "simdutf8"))] | ||
/// Cannot determine the foreground or background | ||
#[error("{0:?}")] | ||
Utf8Error(#[from] std::string::FromUtf8Error), | ||
} | ||
|
||
impl std::fmt::Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
write!(f, "{:?}", self) | ||
impl From<nom::Err<nom::error::Error<&[u8]>>> for Error { | ||
fn from(e: nom::Err<nom::error::Error<&[u8]>>) -> Self { | ||
Self::NomError(format!("{:?}", e)) | ||
} | ||
} | ||
|
||
impl StdErr for Error {} |
Oops, something went wrong.