-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Strange symbols instead of colored text #800
Comments
Update: I just managed to compile my project using this line in Cargo.toml: cursive = { version = "0.20.0", default-features = false, features = ["toml", "crossterm-backend"]} Yes, as expected, everything works on version 0.20. However, if I use version cursive = { version = "0.21.1", default-features = false, features = ["toml", "crossterm-backend"]} Or this: cursive = { version = "0.21.1", features = ["toml"]} I see strange characters instead of colors, meaning the situation is the same to what I described earlier. You can check the screenshots to understand what I mean. |
Hi, and thanks for the report! The main issue is that Note that cursive does support styled text with You can parse ansi text into a You could instead directly build the cursive-native There is also |
Thank you so much for your response! I used the |
@gyscos, By the way, is there a way to remove ANSI codes from a string and get plain text without any styling? For example, I have let ansi_text = "some text".dark_grey().to_string();
let parsed = SpannedString::<Style>::plain(ansi_text);
format!("{}", parsed.source()).as_str(); but it didn’t work. Sorry if this is a silly question. |
You have a couple of ways to get that:
fn iterate_on_spans(styled: &cursive::utils::markup::StyledString) -> String {
styled.spans().map(|span| span.content).collect()
}
fn canonicalize(styled: &mut cursive::utils::markup::StyledString) -> String {
styled.canonicalize();
styled.source().to_string()
}
fn main() {
let mut styled = cursive::utils::markup::cursup::parse("/blue{This} /white{is} /red{sparta}!");
println!("`{}`", iterate_on_spans(&styled));
println!("`{}`", canonicalize(&mut styled));
} |
Thank you so much again for your response! Everything worked out, and it's all functioning perfectly. I really enjoyed working with Cursive; it's a very convenient library. I’ve finished my first project with it - xArpChat. Additionally, I completed the pull request with the example of colored text (#801). I gathered all your answers and included links to the documentation for the methods used. I'm closing the issue. Thank you so much again for your help! If you find my pull request appropriate, I would be very happy to become a contributor to Cursive. Also, I apologize if any of my words sounded rude, I don't know English well. |
I'm glad you found what you were looking for! And good luck on xArpChat! Feel free to ask question if you need support. |
Describe the bug
Hi! I am writing my own version of the project github.com/kognise/arpchat for educational purposes. I encountered an issue where strange symbols appear next to the colored text in my project. By colored text, I mean text styled using methods from
crossterm::style::stylize::Stylize
, for example,"some text".dark_grey().to_string()
. You can see what I mean in the screenshot. I will provide some code snippets for reproduction, but it would be easier to clone the project I mentioned above and run it.An interesting detail I noticed is that if I set the Cursive version to
0.20.0
, everything works as expected. But starting from version0.21.0
, it breaks. I can’t simply use version0.20.0
because it only works with that original project, where I tested the transitions between versions (it works on nightly old Rust). My project is written using the stable Rust version 1.81, and for some reason, it doesn’t compile with Cursive versions earlier than0.21.1
.I apologize if I missed something, and this is my mistake and not a bug. I’d be happy to collaborate.
To Reproduce
Another file:
Expected behavior
Colored text instead of strange symbols.
Screenshots
Cursive version 0.21 (changed just the version in
Cargo.toml
):Cursive version 0.20:
Environment
cursive::default()
. If I use use featurecrossterm-backend
, result stays the same.locale
in a terminal):System Locale: en-us;English (United States); Input Locale: en-us;English (United States)
The text was updated successfully, but these errors were encountered: