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

[BUG] Italic Effect with ncurses-backend #729

Closed
timdubbins opened this issue Apr 26, 2023 · 2 comments
Closed

[BUG] Italic Effect with ncurses-backend #729

timdubbins opened this issue Apr 26, 2023 · 2 comments
Labels

Comments

@timdubbins
Copy link
Contributor

timdubbins commented Apr 26, 2023

Firstly, thank you for your work on Cursive!

Possible bug:

Effect::Italic does not apply when using the ncurses backend. Switching to crossterm and the effect is applied. This occurs using the with_effect() method when implementing View.

To reproduce:

use cursive::theme::Effect;
use cursive::view::{Resizable, View};
use cursive::Cursive;

fn main() {
    let mut siv = cursive::default();

    siv.add_global_callback('q', Cursive::quit);

    // Simple view with Bold and Italic effects.
    siv.add_layer(MyView::new().fixed_size((40, 4)));

    siv.run();
}

struct MyView {}

impl MyView {
    fn new() -> Self {
        Self {}
    }
}

impl View for MyView {
    fn draw(&self, printer: &cursive::Printer) {
        printer.with_effect(Effect::Bold, |printer| {
            printer.print((0, 0), "Hello, World! - Bold")
        });

        printer.with_effect(Effect::Italic, |printer| {
            printer.print((0, 1), "Hello, World! - Italic")
        });

        printer.print((0, 3), "Press q to quit the application")
    }
}

with Cargo.toml dependencies set as:
cursive = { version = "0.20", features = ["ncurses-backend"] } (to reproduce the bug)
or
cursive = { version = "0.20", features = ["crossterm-backend"] } (the expected behaviour)
(on macOS Monterey 12.4)

I'm not sure if this is a bug with cursive or a limitation of ncurses?
Thanks again!

@timdubbins timdubbins added the bug label Apr 26, 2023
@gyscos
Copy link
Owner

gyscos commented Apr 26, 2023

Hi, and thanks for the report!

Indeed, I can reproduce the issue on macOS.
On linux though, italic is properly rendered.

So I suspect the issue is in the ncurses implementation on macOS. We're using ncurses::A_ITALIC, which should abstract over the actual terminal (this is the main point of ncurses), but there can always be issues there.

(We could try a C ncurses example to see if the problem is with ncurses itself or the rust wrapper.)

Unfortunately I'm not sure there's much we could do here, and using a different backend as you did is probably the best solution. You may want to also use the buffered backend to improve performance (I'm still working on integrating that in cursive itself).

@timdubbins
Copy link
Contributor Author

Hi, thanks for your response.

I ran a C ncurses example but got a compile error when setting A_ITALIC. It turns out the ncurses installed on mac is really old and doesn't include this attribute. I thought I was up-to-date with my ncurses package but brew info ncurses yields the caveat:

ncurses is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ncurses first in your PATH, run:
  echo 'export PATH="/usr/local/opt/ncurses/bin:$PATH"' >> ~/.zshrc

For compilers to find ncurses you may need to set:
  export LDFLAGS="-L/usr/local/opt/ncurses/lib"
  export CPPFLAGS="-I/usr/local/opt/ncurses/include"

For pkg-config to find ncurses you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/ncurses/lib/pkgconfig"

So this is a user-end issue, my bad!

Setting export PKG_CONFIG_PATH="/usr/local/opt/ncurses/lib/pkgconfig" resolves this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants