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

make cursive work with ncurses v6.0.1 #778

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

correabuscar
Copy link
Contributor

@correabuscar correabuscar commented Apr 11, 2024

but first: ncurses-rs needs the changes in this PR: jeaye/ncurses-rs#220 (or ideally the ones in this PR jeaye/ncurses-rs#218 , depending on which PR gets merged I'll (re)test the below)

ncurses crate v 6.0.1 is published and enough.

However pancurses doesn't need these changes looks like, for cursive to work with it, so 0.17 seems good (but cursive's examples are not tested with 0.17).

The following were used successfully:

  • cargo build
  • cargo test
  • cargo build --all-features
  • cargo test --all-features
  • cargo build --all-targets
  • cargo test --all-targets
  • cargo build --all-targets --all-features
  • cargo test --all-targets --all-features
  • cargo build --features="ncurses-backend"
  • cargo test --features="ncurses-backend"
  • cargo build --features="ncurses-backend" --all-targets
  • cargo test --features="ncurses-backend" --all-targets

... on each of these target environments:

Legend:

  • ❌ = known not to work

  • = untested

  • = works

  • Gentoo 2.15 default/linux/amd64/23.0/split-usr/no-multilib (stable) -won't build but it would've if Makes the build more robust and fixes compile errors and warnings jeaye/ncurses-rs#218 was merged.

    • some examples tested
    • all examples tested
  • NixOS (if PKG_CONFIG_PATH is set to the dir containing ncurses.pc file, or used nix-shell command in cursive repo dir)

    • some examples tested
    • all examples tested
  • Fedora 39

    • some examples tested
    • all examples tested
  • Ubuntu Desktop 22.04.4 LTS (needs libncurses-dev)

    • tested to work without pkg-config and pkgconf installed.
    • tested to work with pkg-config installed.
  • FreeBSD 14.0-RELEASE

    • some examples tested
    • all examples tested
  • OpenBSD 7.5 GENERIC

    • needs one of LC_CTYPE=en_US.UTF-8 or LANG=en_US.UTF-8 to be set otherwise it looks as if it doesn't have wide chars support so cursive and pancuses examples look pretty broken.
  • MacOS Mojave v10.14.6 (with this)

    • some examples tested
    • all examples tested
  • Windows 11 WSL1 Arch Linux Linux DESKTOP 4.4.0-22621-Microsoft #2506-Microsoft Fri Jan 01 08:00:00 PST 2016 x86_64 GNU/Linux

    • some examples tested
    • all examples tested

TODO:

  • compiles(and passes cargo test) with pancurses (dep) 0.17 but this means it uses v5.101.0 of ncurses crate for pancurses and v 6.0.1 for cursive, see cargo tree --all-features | less (search for ncurses)
  • compiles(and passes cargo test) with pancurses main branch from github with this PR in.
  • does cursive need version bump in this PR? ie. version = "0.21.0" or shall this be left to be done by the repo owner ?!
  • use exact ncurses-rs version in Cargo.toml after it gets published, ie. so it's not lower than that version, because then it would break compilation of cursive. Note that pancurses doesn't need a version bump (see above), although the examples I'm running are through the PR-ed pancurses only.
  • maybe bump pancurses in Cargo.toml too, after it gets its PR for the v6 ncurses-rs usage.
  • add cargo test --example select_test -- --nocapture in addition to the suggested --bin which doesn't work.
  • fix all warnings (because they were introduced by this PR / the upgrade to ncurses-rs v6)
  • run cargo clippy and fix:
    • errors (there were none)
    • warnings
      • pre this PR warnings
        • via cargo clippy --all-targets
        • via cargo clippy --all-targets --all-features
  • passes cargo test --features="ncurses-backend,ansi,toml"
  • get rid of old irrelevant commits that this PR introduced, since they're now mostly obsolete due to new cursive commits.
  • I'm watching(github notifications All Activity) the entire repo for any future-reported breakage, to address it.
  • test that examples compile and run seemingly ok(for on which OS/distro see above) via cargo run --features="ncurses-backend" --example NAME:
    • advanced_user_data
    • ansi via cargo run --features="ncurses-backend,ansi" --example ansi
    • autocomplete
    • builder via cargo run --features="ncurses-backend,builder" --example builder (but looks better with crossterm-backend which is now the default I noticed)
    • colors
    • ctrl_c
    • debug_console
    • dialog
    • edit
    • fixed_layout
    • focus
    • hello_world
    • key_codes
    • linear
    • list_view
    • logs (note: the default aka crossterm-backend has no flickering on bottom line which is great)
    • lorem
    • markup
    • menubar
    • mines
    • mutation
    • panels
    • parse
    • pause
    • position
    • progress
    • radio
    • refcell_view
    • scroll
    • select
    • select_test via cargo test --features="ncurses-backend" --example select_test -- --nocapture
    • slider
    • status
    • status_bar_ext
    • stopwatch
    • tcp_server
    • terminal_default
    • text_area
    • theme
    • theme_editor
    • theme_manual
    • themed_view
    • user_data
    • vpv
    • window_title
  • test each of those in showcases:
    • RustyChat: Chat client made using Rust and Cursive.
    • checkline: Checkbox line picker from stdin to stdout.
    • clock-cli: A clock with stopwatch and countdown timer functionalities.
    • fui: Add CLI & form interface to your program.
    • game2048-rs: a tui game2048 using Rust and cursive.
    • git-branchless: Branchless workflow for Git.
    • grin-tui: Minimal implementation of the MimbleWimble protocol.
    • kakikun: A paint and ASCII art application for the terminal.
    • launchk: Manage launchd agents and daemons on macOS.
    • mythra: CLI to search for music.
    • ncspot: Cross-platform ncurses Spotify client.
    • rbmenu-tui: A TUI for bookmark management.
    • retris: A simple implementation of the classic tetris game.
    • ripasso: A simple password manager written in Rust.
    • rusty-man: Browse rustdoc documentation.
    • saci-rs: Simple API Client Interface.
    • so: A terminal interface for Stack Overflow.
    • sudoku-tui: Play sudoku on the command line.
    • tap: An audio player for the terminal with fuzzy finder.
    • ttyloop: Clone of the mobile game Loop.
    • wiki-tui: A simple and easy to use Wikipedia Text User Interface

@correabuscar correabuscar changed the title make it work with ncurses-rs v6 make cursive work with ncurses-rs v6 Apr 11, 2024
@correabuscar

This comment was marked as resolved.

@gyscos
Copy link
Owner

gyscos commented May 24, 2024

Hi, and thanks a lot for the work! Sorry for the delay.

My main concern is, as you mentioned, the unconditional re-allocation. The fact that ncurses re-allocates as well is not an excuse, because:

  • It's still an extra re-allocation, making something non-ideal even worse.
  • We could (should?) one day switch to using addnstr which might not need to be zero-terminated (though the current rest rust wrapper still re-allocates it).
  • Other backends might not re-allocate. (Nevermind, I somehow missed that this was all ncurses-backend-specific.)

Using a smarter "replace if" method that returns something like a Cow could be an option to avoid allocation in the general case, only paying the price when there's actually a \0.

Another option would be to only keep the string prefix up to that \0, ignoring the rest (this is what would have happened using the C library directly).

@correabuscar correabuscar force-pushed the make_it_work_with_ncurses_v6 branch 3 times, most recently from fc4b68d to 61fc866 Compare May 24, 2024 19:39
correabuscar added a commit to correabuscar/cursive that referenced this pull request May 24, 2024
otherwise, nothing would get printed, silently.

for print_at() and print_at_rep() only!

why delete \0 instead of replace? read this:
gyscos#778 (comment)

this also fixes warnings about unused Result
@correabuscar

This comment was marked as outdated.

correabuscar added a commit to correabuscar/cursive that referenced this pull request May 25, 2024
...before sending the &str to ncurses backend,
this is done for cursive's print_at() and print_at_rep() only!
otherwise, nothing would get printed, silently.

Why delete \0 instead of replace with eg. space?
this explains it best:
gyscos#778 (comment)

This also fixes warnings about unused Result.

Closes: gyscos#780
correabuscar added a commit to correabuscar/cursive that referenced this pull request May 25, 2024
...before sending the &str to ncurses backend,
this is done for cursive's print_at() and print_at_rep() only!
otherwise, nothing would get printed, silently.

Why delete \0 instead of replace with eg. space?
this explains it best:
gyscos#778 (comment)

This also fixes warnings about unused Result.

Closes: gyscos#780
correabuscar added a commit to correabuscar/cursive that referenced this pull request May 28, 2024
as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
correabuscar added a commit to correabuscar/cursive that referenced this pull request May 28, 2024
as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
correabuscar added a commit to correabuscar/cursive that referenced this pull request May 28, 2024
as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
correabuscar added a commit to correabuscar/cursive that referenced this pull request May 28, 2024
as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
correabuscar added a commit to correabuscar/cursive that referenced this pull request May 28, 2024
as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
@correabuscar
Copy link
Contributor Author

correabuscar commented Jun 6, 2024

Now this PR is clean(ish), we're waiting for one of these two ncurses-rs PRs to get in:

Keeping the PR in draft until then. Maybe even have the optional pancurses one(PR) get in, even though cursive works without that one in.

PS: that CI failure is due to TERM not being set or something(that PR jeaye/ncurses-rs#218 would actually tell us about it or any other(but not all) weird errors more precisely).

@gyscos
Copy link
Owner

gyscos commented Jun 6, 2024

PS: that CI failure is due to TERM not being set or something(that PR jeaye/ncurses-rs#218 would actually tell us about it or any other(but not all) weird errors more precisely).

Do you mean the TERM variable is not set at compile time? I think that shouldn't be required - it's not uncommon to build without a terminal at all (from CI, or even from some IDEs), and lying about a TERM doesn't sound like a very clean option. Might be our only option at this point, which is a bummer.

@correabuscar

This comment was marked as resolved.

correabuscar added a commit to correabuscar/cursive that referenced this pull request Jun 6, 2024
newterm https://github.com/jeaye/ncurses-rs/blob/3aa22bc279e4929e3ab69d49f75a18eda3e431e9/src/lib.rs#L1023-L1029
CString::new https://doc.rust-lang.org/std/ffi/struct.CString.html#method.new

bubble up this newterm error

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>

preserve original error in the panic report

otherwise, we'd not know why ncurses-rs newterm errored

directly include the variable name in the format! expression

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
@correabuscar correabuscar force-pushed the make_it_work_with_ncurses_v6 branch 2 times, most recently from 580aa85 to 1a9bee7 Compare June 6, 2024 21:08
correabuscar added a commit to correabuscar/cursive that referenced this pull request Jun 6, 2024
newterm https://github.com/jeaye/ncurses-rs/blob/3aa22bc279e4929e3ab69d49f75a18eda3e431e9/src/lib.rs#L1023-L1029
CString::new https://doc.rust-lang.org/std/ffi/struct.CString.html#method.new

bubble up this newterm error

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>

preserve original error in the panic report

otherwise, we'd not know why ncurses-rs newterm errored

directly include the variable name in the format! expression

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
correabuscar added a commit to correabuscar/cursive that referenced this pull request Jun 7, 2024
newterm https://github.com/jeaye/ncurses-rs/blob/3aa22bc279e4929e3ab69d49f75a18eda3e431e9/src/lib.rs#L1023-L1029
CString::new https://doc.rust-lang.org/std/ffi/struct.CString.html#method.new

bubble up this newterm error

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>

preserve original error in the panic report

otherwise, we'd not know why ncurses-rs newterm errored

directly include the variable name in the format! expression

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
correabuscar added a commit to correabuscar/cursive that referenced this pull request Jun 10, 2024
newterm https://github.com/jeaye/ncurses-rs/blob/3aa22bc279e4929e3ab69d49f75a18eda3e431e9/src/lib.rs#L1023-L1029
CString::new https://doc.rust-lang.org/std/ffi/struct.CString.html#method.new

bubble up this newterm error

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>

preserve original error in the panic report

otherwise, we'd not know why ncurses-rs newterm errored

directly include the variable name in the format! expression

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
correabuscar added a commit to correabuscar/cursive that referenced this pull request Jun 20, 2024
newterm https://github.com/jeaye/ncurses-rs/blob/3aa22bc279e4929e3ab69d49f75a18eda3e431e9/src/lib.rs#L1023-L1029
CString::new https://doc.rust-lang.org/std/ffi/struct.CString.html#method.new

bubble up this newterm error

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>

preserve original error in the panic report

otherwise, we'd not know why ncurses-rs newterm errored

directly include the variable name in the format! expression

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
@correabuscar

This comment was marked as outdated.

@correabuscar
Copy link
Contributor Author

Reopening because jeaye/ncurses-rs#220 got in, so this PR might work now, bare with me while I re-test everything in OP...

@correabuscar correabuscar reopened this Jul 12, 2024
@correabuscar correabuscar changed the title make cursive work with ncurses-rs v6 make cursive work with ncurses v6.0.1 Jul 12, 2024
correabuscar and others added 3 commits July 12, 2024 20:38
which means that ncurses-rs already has the
needed changes in this PR:
jeaye/ncurses-rs#220
and/or from this PR:
jeaye/ncurses-rs#218
newterm https://github.com/jeaye/ncurses-rs/blob/3aa22bc279e4929e3ab69d49f75a18eda3e431e9/src/lib.rs#L1023-L1029
CString::new https://doc.rust-lang.org/std/ffi/struct.CString.html#method.new

bubble up this newterm error

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>

preserve original error in the panic report

otherwise, we'd not know why ncurses-rs newterm errored

directly include the variable name in the format! expression

as suggested here: gyscos#778 (comment)

Co-authored-by: Alexandre Bury <alexandre.bury@gmail.com>
@correabuscar
Copy link
Contributor Author

correabuscar commented Jul 12, 2024

I don't have the virtual machines anymore, so I've only tested Gentoo...
PR uses v6.0.1 of ncurses crate which was just published.

EDIT: I should note that for cursive to fully use the ncurses crate v6 instead of v5, cursive would have to use a pancurses version that uses v6 which isn't yet published (waiting for this PR to get in, but hopefully it would be bumped to v 0.18.0 and published then cursive can point to that version), else both v6 and v5 would be used with the ncurses-backend feature.

@correabuscar correabuscar marked this pull request as ready for review July 12, 2024 19:14
@gyscos
Copy link
Owner

gyscos commented Jul 12, 2024

Good job here, and glad it paid off :)

@gyscos gyscos merged commit cc4f36f into gyscos:main Jul 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants