Merge branch 'imbris/update-conrod-copypasta' into 'master'

Update copypasta version used by conrod

See merge request veloren/veloren!3854
This commit is contained in:
Imbris 2023-04-05 07:19:16 +00:00
commit 76bfae38a0
3 changed files with 105 additions and 186 deletions

190
Cargo.lock generated
View File

@ -62,7 +62,7 @@ checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
"getrandom 0.2.7",
"once_cell",
"version_check 0.9.4",
"version_check",
]
[[package]]
@ -74,7 +74,7 @@ dependencies = [
"cfg-if 1.0.0",
"getrandom 0.2.7",
"once_cell",
"version_check 0.9.4",
"version_check",
]
[[package]]
@ -130,16 +130,6 @@ dependencies = [
"libc",
]
[[package]]
name = "ansi-parser"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcb2392079bf27198570d6af79ecbd9ec7d8f16d3ec6b60933922fdb66287127"
dependencies = [
"heapless 0.5.6",
"nom 4.2.3",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
@ -236,18 +226,6 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]]
name = "as-slice"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45403b49e3954a4b8428a0ac21a4b7afadccf92bfd96273f1a58cd4812496ae0"
dependencies = [
"generic-array 0.12.4",
"generic-array 0.13.3",
"generic-array 0.14.6",
"stable_deref_trait",
]
[[package]]
name = "ash"
version = "0.32.1"
@ -504,7 +482,7 @@ version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e"
dependencies = [
"generic-array 0.14.6",
"generic-array",
]
[[package]]
@ -594,6 +572,12 @@ dependencies = [
"nix 0.18.0",
]
[[package]]
name = "cansi"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bdcae87153686017415ce77e48c53e6818a0a058f0e21b56640d1e944967ef8"
[[package]]
name = "cassowary"
version = "0.3.0"
@ -645,7 +629,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom 7.1.1",
"nom",
]
[[package]]
@ -827,7 +811,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "983a7010836ecd04dde2c6d27a0cb56ec5d21572177e782bdcb24a600124e921"
dependencies = [
"thiserror",
"x11rb",
"x11rb 0.9.0",
]
[[package]]
@ -917,7 +901,7 @@ dependencies = [
[[package]]
name = "conrod_core"
version = "0.63.0"
source = "git+https://gitlab.com/veloren/conrod.git?branch=copypasta_0.7#ca9fd429ca7db854e018acc6dcb2cd8abd9e070d"
source = "git+https://gitlab.com/veloren/conrod.git?branch=copypasta_0.7#59fddc617696e68d28a75c2137a08c2572efb986"
dependencies = [
"conrod_derive",
"copypasta",
@ -932,7 +916,7 @@ dependencies = [
[[package]]
name = "conrod_derive"
version = "0.63.0"
source = "git+https://gitlab.com/veloren/conrod.git?branch=copypasta_0.7#ca9fd429ca7db854e018acc6dcb2cd8abd9e070d"
source = "git+https://gitlab.com/veloren/conrod.git?branch=copypasta_0.7#59fddc617696e68d28a75c2137a08c2572efb986"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
@ -942,7 +926,7 @@ dependencies = [
[[package]]
name = "conrod_winit"
version = "0.63.0"
source = "git+https://gitlab.com/veloren/conrod.git?branch=copypasta_0.7#ca9fd429ca7db854e018acc6dcb2cd8abd9e070d"
source = "git+https://gitlab.com/veloren/conrod.git?branch=copypasta_0.7#59fddc617696e68d28a75c2137a08c2572efb986"
[[package]]
name = "const-random"
@ -989,9 +973,9 @@ checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536"
[[package]]
name = "copypasta"
version = "0.7.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4423d79fed83ebd9ab81ec21fa97144300a961782158287dc9bf7eddac37ff0b"
checksum = "133fc8675ee3a4ec9aa513584deda9aa0faeda3586b87f7f0f2ba082c66fb172"
dependencies = [
"clipboard-win 3.1.1",
"objc",
@ -1460,7 +1444,7 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array 0.14.6",
"generic-array",
"typenum",
]
@ -1731,7 +1715,7 @@ dependencies = [
"ahash 0.8.0",
"lazy_static",
"log",
"nom 7.1.1",
"nom",
]
[[package]]
@ -2256,24 +2240,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "generic-array"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd"
dependencies = [
"typenum",
]
[[package]]
name = "generic-array"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f797e67af32588215eaaab8327027ee8e71b9dd0b2b26996aedf20c030fce309"
dependencies = [
"typenum",
]
[[package]]
name = "generic-array"
version = "0.14.6"
@ -2281,7 +2247,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
dependencies = [
"typenum",
"version_check 0.9.4",
"version_check",
]
[[package]]
@ -2518,7 +2484,7 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "579160312273c954cc51bd440f059dde741029ac8daf8c84fece76cb77f62c15"
dependencies = [
"version_check 0.9.4",
"version_check",
]
[[package]]
@ -2652,15 +2618,6 @@ version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
[[package]]
name = "hash32"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc"
dependencies = [
"byteorder",
]
[[package]]
name = "hash32"
version = "0.2.1"
@ -2708,18 +2665,6 @@ dependencies = [
"hashbrown 0.9.1",
]
[[package]]
name = "heapless"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74911a68a1658cfcfb61bc0ccfbd536e3b6e906f8c2f7883ee50157e3e2184f1"
dependencies = [
"as-slice",
"generic-array 0.13.3",
"hash32 0.1.1",
"stable_deref_trait",
]
[[package]]
name = "heapless"
version = "0.7.16"
@ -2727,7 +2672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743"
dependencies = [
"atomic-polyfill",
"hash32 0.2.1",
"hash32",
"rustc_version 0.4.0",
"spin 0.9.4",
"stable_deref_trait",
@ -3140,7 +3085,7 @@ dependencies = [
"wayland-client 0.29.5",
"winapi 0.3.9",
"winit",
"xcb 1.2.0",
"xcb",
"xkbcommon",
]
@ -3869,29 +3814,9 @@ dependencies = [
[[package]]
name = "nom"
version = "4.2.3"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
dependencies = [
"memchr",
"version_check 0.1.5",
]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"memchr",
"version_check 0.9.4",
]
[[package]]
name = "nom"
version = "7.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
@ -4584,7 +4509,7 @@ dependencies = [
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.100",
"version_check 0.9.4",
"version_check",
]
[[package]]
@ -4595,7 +4520,7 @@ checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2 1.0.43",
"quote 1.0.21",
"version_check 0.9.4",
"version_check",
]
[[package]]
@ -5217,7 +5142,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b40f1bfe5acdab44bc63e6699c28b74f75ec43afb59f3eda01e145aff86a25fa"
dependencies = [
"heapless 0.7.16",
"heapless",
"num-traits",
"smallvec",
]
@ -5784,7 +5709,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342"
dependencies = [
"serde",
"version_check 0.9.4",
"version_check",
]
[[package]]
@ -6479,11 +6404,11 @@ dependencies = [
[[package]]
name = "tynm"
version = "0.1.6"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4df2caa2dc9c3d1f7641ba981f4cd40ab229775aa7aeb834c9ab2850d50623d"
checksum = "cd59ecde1e694c0495c8b92bdd0f9a70e3b489cd8180fc6a18f6ea1c1026f3b2"
dependencies = [
"nom 5.1.2",
"nom",
]
[[package]]
@ -6507,7 +6432,7 @@ version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622"
dependencies = [
"version_check 0.9.4",
"version_check",
]
[[package]]
@ -7026,7 +6951,7 @@ dependencies = [
name = "veloren-server-cli"
version = "0.14.0"
dependencies = [
"ansi-parser",
"cansi",
"clap 3.2.22",
"crossterm 0.25.0",
"lazy_static",
@ -7219,12 +7144,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73"
[[package]]
name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
[[package]]
name = "version_check"
version = "0.9.4"
@ -8188,11 +8107,11 @@ dependencies = [
[[package]]
name = "x11-clipboard"
version = "0.5.3"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "473068b7b80ac86a18328824f1054e5e007898c47b5bbc281bd7abe32bc3653c"
checksum = "980b9aa9226c3b7de8e2adb11bf20124327c054e0e5812d2aac0b5b5a87e7464"
dependencies = [
"xcb 0.10.1",
"x11rb 0.10.1",
]
[[package]]
@ -8218,6 +8137,28 @@ dependencies = [
"winapi-wsapoll",
]
[[package]]
name = "x11rb"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507"
dependencies = [
"gethostname",
"nix 0.24.2",
"winapi 0.3.9",
"winapi-wsapoll",
"x11rb-protocol",
]
[[package]]
name = "x11rb-protocol"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67"
dependencies = [
"nix 0.24.2",
]
[[package]]
name = "xattr"
version = "0.2.3"
@ -8227,17 +8168,6 @@ dependencies = [
"libc",
]
[[package]]
name = "xcb"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c"
dependencies = [
"libc",
"log",
"quick-xml",
]
[[package]]
name = "xcb"
version = "1.2.0"
@ -8255,7 +8185,7 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7"
dependencies = [
"nom 7.1.1",
"nom",
]
[[package]]
@ -8281,7 +8211,7 @@ checksum = "acbee136714379ab22da0280207fdb7f47e0bb940adea97731b65598b8c7a92e"
dependencies = [
"libc",
"memmap2 0.5.7",
"xcb 1.2.0",
"xcb",
]
[[package]]

View File

@ -37,7 +37,7 @@ world = { package = "veloren-world", path = "../world", optional = true }
tokio = { version = "1.14", default-features = false, features = ["rt-multi-thread"] }
num_cpus = "1.0"
ansi-parser = "0.8"
cansi = "2.2.1"
clap = { version = "3.1.8", features = ["derive"] }
crossterm = "0.25"
lazy_static = "1"

View File

@ -21,81 +21,70 @@ impl<'a> TuiLog<'a> {
impl<'a> Write for TuiLog<'a> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
use ansi_parser::{AnsiParser, AnsiSequence, Output};
// TODO: this processing can probably occur in the consumer of the log lines
// (and instead of having a TuiLog::resize the consumer can take
// ownership of the lines and manage them itself).
// Not super confident this is the ideal parser but it works for now and doesn't
// depend on an old version of nom. Alternatives to consider may include
// `vte`, `anstyle-parse`, `vt100`, or others.
use cansi::v3::categorise_text;
use tui::{
style::{Color, Modifier},
text::{Span, Spans},
};
let line = String::from_utf8(buf.into())
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
let line =
core::str::from_utf8(buf).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
let mut spans = Vec::new();
let mut span = Span::raw("");
let mut lines = Vec::new();
for out in line.ansi_parse() {
match out {
Output::TextBlock(text) => {
// search for newlines
for t in text.split_inclusive('\n') {
span.content.to_mut().push_str(t);
if t.ends_with('\n') && span.content.len() != 0 {
spans.push(std::mem::replace(&mut span, Span::raw("")));
lines.push(std::mem::take(&mut spans));
}
}
for out in categorise_text(line) {
let mut style = tui::style::Style::default();
// NOTE: There are other values returned from cansi that we don't bother to use
// for now including background color, italics, blinking, etc.
style.fg = match out.fg {
Some(cansi::Color::Black) => Some(Color::Black),
Some(cansi::Color::Red) => Some(Color::Red),
Some(cansi::Color::Green) => Some(Color::Green),
Some(cansi::Color::Yellow) => Some(Color::Yellow),
Some(cansi::Color::Blue) => Some(Color::Blue),
Some(cansi::Color::Magenta) => Some(Color::Magenta),
Some(cansi::Color::Cyan) => Some(Color::Cyan),
Some(cansi::Color::White) => Some(Color::White),
// "Bright" versions currently not handled
Some(c) => {
warn!("Unknown color {:#?}", c);
style.fg
},
Output::Escape(seq) => {
if span.content.len() != 0 {
spans.push(span);
None => style.fg,
};
match out.intensity {
Some(cansi::Intensity::Normal) | None => {},
Some(cansi::Intensity::Bold) => style.add_modifier = Modifier::BOLD,
Some(cansi::Intensity::Faint) => style.add_modifier = Modifier::DIM,
}
span = Span::raw("");
}
match seq {
AnsiSequence::SetGraphicsMode(values) => {
const COLOR_TABLE: [Color; 8] = [
Color::Black,
Color::Red,
Color::Green,
Color::Yellow,
Color::Blue,
Color::Magenta,
Color::Cyan,
Color::White,
];
let mut iter = values.iter();
match iter.next().unwrap() {
0 => {},
1 => span.style.add_modifier = Modifier::BOLD,
2 => span.style.add_modifier = Modifier::DIM,
idx @ 30..=37 => {
span.style.fg = Some(COLOR_TABLE[(idx - 30) as usize])
},
_ => warn!("Unknown color {:#?}", values),
}
},
_ => warn!("Unknown sequence {:#?}", seq),
}
},
// search for newlines
for t in out.text.split_inclusive('\n') {
if !t.is_empty() {
spans.push(Span::styled(t.to_owned(), style));
}
if t.ends_with('\n') {
lines.push(Spans(core::mem::take(&mut spans)));
}
}
}
if span.content.len() != 0 {
spans.push(span);
}
if !spans.is_empty() {
lines.push(spans);
lines.push(Spans(spans));
}
let mut lines = lines.into_iter().map(Spans).collect::<Vec<_>>();
self.inner.lock().unwrap().lines.append(&mut lines);
Ok(buf.len())
}
// We can potentially use this to reduce locking frequency?
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}