Skip to content
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

Windows 7, crossterm, SetUnderlineColor error #555

Closed
rigelminer opened this issue Oct 3, 2023 · 13 comments · Fixed by #570
Closed

Windows 7, crossterm, SetUnderlineColor error #555

rigelminer opened this issue Oct 3, 2023 · 13 comments · Fixed by #570
Labels
Type: Bug Something isn't working

Comments

@rigelminer
Copy link

Description

When using ratatui with crossterm backend on Windows 7, the application fails to render with an error Custom { kind: Other, error: "SetUnderlineColor not supported by winapi." }

To Reproduce

Render UI with ratatui 0.23.0 on Windows 7

Expected behavior

The UI renders successfully

Environment

  • OS: Windows 7
  • Terminal Emulator: cmd.exe
  • Crate version: 0.23.0
  • Backend: crossterm

Additional context

The error originates here https://github.com/crossterm-rs/crossterm/blob/master/src/style.rs#L251. SetUnderlineColor command is called in ratatui here: https://github.com/ratatui-org/ratatui/blob/main/src/backend/crossterm.rs#L167 <-- commenting out this line fixes the issue.
I'm not experiencing this problem with the original tui-rs as it doesn't call SetUnderlineColor.

Is there a way to make the code call SetUnderlineColor only when the underline color functionality is used? I promise not to use on Win 7 😄

@rigelminer rigelminer added the Type: Bug Something isn't working label Oct 3, 2023
@kdheepak
Copy link
Collaborator

kdheepak commented Oct 3, 2023

Thanks for reporting! I'm using Ratatui on Windows and I'm surprised I didn't run into this yet. Does this happen for you when you style a cell a particular way or does it happen even if you apply no styling?

@rigelminer
Copy link
Author

rigelminer commented Oct 3, 2023

No worries!
I believe this is specific to Windows 7. Crossterm is probably using ansi for setting colours on newer versions of Windows.

Does this happen for you when you style a cell a particular way or does it happen even if you apply no styling?

Looks like it fails even when applying Style::default()

@joshka
Copy link
Member

joshka commented Oct 3, 2023

How is Windows 7 still a thing? LOL

The colored underline behavior was added recently with a feature flag behind crossterm. We might have to replace that with a "colored-underline" flag or something like that instead.

@rigelminer
Copy link
Author

How is Windows 7 still a thing? LOL

Haha, I know right? Some of our users are running Windows 7. I had to install it myself to troubleshoot.

We might have to replace that with a "colored-underline" flag or something like that instead.

That would be great, thanks! The less intrusive the fix the better - otherwise it's not worth the effort, considering the issue is only present on Win 7. It's that unconditional SetUnderlineColor(CColor::Reset) call that's causing the problem.

@kdheepak
Copy link
Collaborator

kdheepak commented Oct 3, 2023

You'll also run into the issue if you manually set underline color, right? For example this line:

https://github.com/ratatui-org/ratatui/blob/45413365146ede5472dc28e0ee1970d245e2fa02/src/backend/crossterm.rs#L156-L156

@joshka What do you think about change the following:

https://github.com/ratatui-org/ratatui/blob/45413365146ede5472dc28e0ee1970d245e2fa02/src/backend/crossterm.rs#L163-L169

to something like this instead:

        if let Err(e) = queue!(self.writer, SetUnderlineColor(CColor::Reset)) {
            log::error!("Unable to set underline color: {e}");
        }
        queue!(
            self.writer,
            SetForegroundColor(CColor::Reset),
            SetBackgroundColor(CColor::Reset),
            SetAttribute(CAttribute::Reset)
        )

@joshka
Copy link
Member

joshka commented Oct 3, 2023

That's going to spam logs hard - it's better to not do something when it can error than do it many times.

@sigmaSd
Copy link

sigmaSd commented Oct 7, 2023

I think you can raise issue/pr upstream (even though response will be slow) , usually unsupported apis are just ignored like here https://github.com/crossterm-rs/crossterm/blob/master/src/style.rs#L321

I think this case should be the same, it provably just wasn't noticed.

@rigelminer
Copy link
Author

@sigmaSd Thanks. Raised the issue crossterm-rs/crossterm#831.

joshka added a commit that referenced this issue Oct 18, 2023
Windows 7 doesn't support the underline color attribute, so we need to
make it optional. This commit adds a feature flag for the underline
color attribute - it is enabled by default, but can be disabled by
passing `--no-default-features` to cargo.

We could specically check for Windows 7 and disable the feature flag
automatically, but I think it's better for this check to be done by the
crossterm crate, since it's the one that actually knows about the
underlying terminal.

To disable the feature flag in an application that supports Windows 7,
add the following to your Cargo.toml:

```toml
ratatui = { version = "0.24.0", default-features = false, features = ["crossterm"] }
```

Fixes #555
joshka added a commit that referenced this issue Oct 18, 2023
Windows 7 doesn't support the underline color attribute, so we need to
make it optional. This commit adds a feature flag for the underline
color attribute - it is enabled by default, but can be disabled by
passing `--no-default-features` to cargo.

We could specically check for Windows 7 and disable the feature flag
automatically, but I think it's better for this check to be done by the
crossterm crate, since it's the one that actually knows about the
underlying terminal.

To disable the feature flag in an application that supports Windows 7,
add the following to your Cargo.toml:

```toml
ratatui = { version = "0.24.0", default-features = false, features = ["crossterm"] }
```

Fixes #555
IlyaSelivanov pushed a commit to IlyaSelivanov/ratatui that referenced this issue Oct 19, 2023
Windows 7 doesn't support the underline color attribute, so we need to
make it optional. This commit adds a feature flag for the underline
color attribute - it is enabled by default, but can be disabled by
passing `--no-default-features` to cargo.

We could specically check for Windows 7 and disable the feature flag
automatically, but I think it's better for this check to be done by the
crossterm crate, since it's the one that actually knows about the
underlying terminal.

To disable the feature flag in an application that supports Windows 7,
add the following to your Cargo.toml:

```toml
ratatui = { version = "0.24.0", default-features = false, features = ["crossterm"] }
```

Fixes ratatui#555
@icecat89
Copy link

icecat89 commented Jul 12, 2024

man, i'm using even Windows 8.1 and steel have the same problem, i just wanted to make a simple “Hello World” TUI app...
in the Cargo.toml, the pakage and dependencies are like this:

[package]
name = "rata"
version = "0.1.0"
edition = "2021"

[dependencies]
ratatui = "0.27.0"

and then on the main.rs:

use std::io::{stdout, Result};

use ratatui::{
    backend::CrosstermBackend,
    crossterm::{
        event::{self, KeyCode, KeyEventKind},
        terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
        ExecutableCommand,
    },
    style::Stylize,
    widgets::Paragraph,
    Terminal,
};

fn main() -> Result<()> {
    stdout().execute(EnterAlternateScreen)?;
    enable_raw_mode()?;
    let mut terminal = Terminal::new(CrosstermBackend::new(stdout()))?;
    terminal.clear()?;

    loop {
        terminal.draw(|frame| {
            let area = frame.size();
            frame.render_widget(
                Paragraph::new("Hello Ratatui! (press 'q' to quit)")
                    .white()
                    .on_blue(),
                area,
            );
        })?;

        if event::poll(std::time::Duration::from_millis(16))? {
            if let event::Event::Key(key) = event::read()? {
                if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('q') {
                    break;
                }
            }
        }
    }

    stdout().execute(LeaveAlternateScreen)?;
    disable_raw_mode()?;
    Ok(())
}

whenever i run it on the cmd, it makes the design but gives an error:

Error: Custom { kind: Other, error: "SetUnderlineColor not supported by winapi." }
error: process didn't exit successfully: target\debug\rata.exe (exit code: 1)

there is no option to exit from the app, it's directly loged out with this error

hope someone will find a solution for me))

@joshka
Copy link
Member

joshka commented Jul 12, 2024

QQ: do you have a full backtrace for the error? That would be helpful to understand how this is feature gated on winapi (and would enable us to perhaps do the same thing, either in Ratatui or crossterm. It's probably more crossterm than Ratatui that should ignore this.

To disable underline colors in your app use the following in your Cargo.toml (basically don't enable the underline-color feature). This was fixed in #570 which is mentioned above in the "closed as completed" link.

ratatui = { version = "0.27.0", default-features = false, features = ["crossterm"] }

@icecat89
Copy link

icecat89 commented Jul 12, 2024

@joshka
So Tipeclly... I should desable the default-features ? And add crossterm?
The problem is not upp to this only...i tried also to make a simple counter app and the hole borders where like "???? " I think ratatui only support win10 and up...
Anyway... I'll try to do that now...maybee it's gonna be usefull...thank you

@joshka
Copy link
Member

joshka commented Jul 12, 2024

Hey, can you open another issue for any problems you're seeing with Windows 8 here. My guess for the borders is that your terminal is not using a font that has the symbols available. It's possible that Windows 8 works, but we don't really have any maintainers that regularly use Windows, so I wouldn't call it supported - merely tolerated ;)

I'd recommend grabbing a Windows 11 VM for your development purposes. See https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/. Obviously you know your reasons for using really old software, but it's not something I want to invest much time into generally. I hope you can appreciate that.

@icecat89
Copy link

icecat89 commented Jul 12, 2024

@joshka
Hi man...thanks for respo,
Well it's a great idea to put a Windows 11 as VM, but the main reason of why I steel use windows8. 1 is cz my computer config can't be enough for better versions.. Here's my config :
Intel Celeron G1620 2.7Ghz
4GB ram DDR3 1600Mhz
Intel HD graphics 228MB
You get the point now? I'm actually suffer from this...
But thanks anyway

I also were trying to learn about ratatui for making a good TUI for my socks5 proxy project..its a Windows tool tunneling it over named pipes...
So I what to organize it well...
For named pipes I couldn't use rust cz I didn't find a better option (crate) to use it for tht...even Tokio support it... So I used cpp for tht...
Thanks for such kind words , I'll open an issue later on... )) thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants