From 4571b57ece81cee921c33529745b98f280666f51 Mon Sep 17 00:00:00 2001 From: Nick Black Date: Wed, 25 Dec 2019 10:11:24 -0500 Subject: [PATCH] Rust/FreeBSD (#221) * rust bindings * update release documentation with Rust info * panelreel tester: accept command-line options#180 * input: char32_t not wchar_t in output * freebsd compilation issues #196 --- doc/FreeBSD-Makefile | 16 +++++++++++++++ doc/release-checklist.md | 2 ++ rust/Cargo.lock | 6 ++++++ rust/Cargo.toml | 13 ++++++++++++ rust/src/lib.rs | 7 +++++++ src/lib/input.c | 8 ++++++-- src/planereel/main.cpp | 43 ++++++++++++++++++++++++++++++++++++---- 7 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 doc/FreeBSD-Makefile create mode 100644 rust/Cargo.lock create mode 100644 rust/Cargo.toml create mode 100644 rust/src/lib.rs diff --git a/doc/FreeBSD-Makefile b/doc/FreeBSD-Makefile new file mode 100644 index 000000000..79fe77d87 --- /dev/null +++ b/doc/FreeBSD-Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +PORTNAME=notcurses +DISTVERSION=0.9.2 +CATEGORIES=graphics +MASTER_SITES=https://nick-black.com/dankwiki/index.php/Notcurses + +MAINTAINER=dankamongmen@gmail.com +COMMENT=TUI library for modern terminal emulators + +USES=cmake +LICENSE=Apache-2.0 +USE_GITHUB=yes +GH_ACCOUNT=dankamongmen + +.include diff --git a/doc/release-checklist.md b/doc/release-checklist.md index 57cb71946..f41319cc6 100644 --- a/doc/release-checklist.md +++ b/doc/release-checklist.md @@ -1,5 +1,6 @@ * Verify version in CMakeLists.txt * Finalize Debian changelog with `dch -r` +* Update version in rust/Cargo.toml * git commit -a -m v$VERSION * Tag with `git tag -a v$VERSION -m "v$VERSION"` * `git push && git push origin --tags` @@ -16,5 +17,6 @@ * `makepkg --printsrcinfo > .SRCINFO` * Test that package builds with `makepkg` * `git commit -a` +* Upload new Rust crate with `cargo upload` * Update Debian changelog with `dch -v $NEXTVERSION-1` * Update CMakeLists.txt with next version diff --git a/rust/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 000000000..984a45654 --- /dev/null +++ b/rust/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "notcurses" +version = "0.9.2" + diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 000000000..27d2893aa --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "notcurses" +version = "0.9.2" +authors = ["nick black "] +edition = "2018" +license = "Apache-2.0" +description = "Rust bindings for the notcurses C library." +repository = "https://github.com/dankamongmen/notcurses" +homepage = "https://nick-black.com/dankwiki/index.php/Notcurses" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/rust/src/lib.rs b/rust/src/lib.rs new file mode 100644 index 000000000..31e1bb209 --- /dev/null +++ b/rust/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/src/lib/input.c b/src/lib/input.c index c07472eea..8fa63c302 100644 --- a/src/lib/input.c +++ b/src/lib/input.c @@ -1,6 +1,7 @@ #include // needed for some definitions, see terminfo(3ncurses) #include #include +#include #include #include "internal.h" @@ -74,7 +75,7 @@ notcurses_add_input_escape(notcurses* nc, const char* esc, char32_t special){ return -1; } if(!wchar_supppuab_p(special) && special != NCKEY_CSI){ - fprintf(stderr, "Not a supplementary-b PUA char: %lc (0x%x)\n", special, special); + fprintf(stderr, "Not a supplementary-b PUA char: %u (0x%x)\n", special, special); return -1; } esctrie** cur = &nc->inputescapes; @@ -249,7 +250,7 @@ static int block_on_input(FILE* fp, const struct timespec* ts, sigset_t* sigmask){ struct pollfd pfd = { .fd = fileno(fp), - .events = POLLIN | POLLRDHUP, + .events = POLLIN, .revents = 0, }; sigset_t scratchmask; @@ -261,6 +262,9 @@ block_on_input(FILE* fp, const struct timespec* ts, sigset_t* sigmask){ sigdelset(sigmask, SIGINT); sigdelset(sigmask, SIGQUIT); sigdelset(sigmask, SIGSEGV); +#ifdef POLLRDHUP + pfd.events |= POLLRDHUP; +#endif return ppoll(&pfd, 1, ts, sigmask); } diff --git a/src/planereel/main.cpp b/src/planereel/main.cpp index 6ee3d6e64..7661f8087 100644 --- a/src/planereel/main.cpp +++ b/src/planereel/main.cpp @@ -1,5 +1,8 @@ #include #include +#include +#include +#include #include // FIXME ought be able to get pr from tablet, methinks? @@ -27,11 +30,46 @@ int tabletfxn(struct tablet* t, int begx, int begy, int maxx, int maxy, return tctx->getLines() > maxy - begy ? maxy - begy : tctx->getLines(); } -int main(void){ +void usage(const char* argv0, std::ostream& c, int status){ + c << "usage: " << argv0 << " [ -h ] | [ -b bordermask ] [ -t tabletmask ]\n"; + c << " -b bordermask: hex panelreel border mask (0x0..0xf)\n"; + c << " -t tabletmask: hex tablet border mask (0x0..0xf)" << std::endl; + exit(status); +} + +void parse_args(int argc, char** argv, struct notcurses_options* opts, + struct panelreel_options* popts){ + int c; + while((c = getopt(argc, argv, "b:t:h")) != -1){ + switch(c){ + case 'b':{ + std::stringstream ss; + ss << std::hex << optarg; + ss >> popts->bordermask; + break; + }case 't': + // FIXME + break; + case 'h': + usage(argv[0], std::cout, EXIT_SUCCESS); + break; + default: + std::cerr << "Unknown option\n"; + usage(argv[0], std::cerr, EXIT_FAILURE); + break; + } + } + opts->suppress_bannner = true; + opts->clear_screen_start = true; +} + +int main(int argc, char** argv){ if(setlocale(LC_ALL, "") == nullptr){ return EXIT_FAILURE; } struct notcurses_options opts{}; + struct panelreel_options popts{}; + parse_args(argc, argv, &opts, &popts); struct notcurses* nc = notcurses_init(&opts, stdout); if(!nc){ return EXIT_FAILURE; @@ -52,11 +90,8 @@ int main(void){ notcurses_stop(nc); return EXIT_FAILURE; } - struct panelreel_options popts{}; channels_set_fg(&popts.focusedchan, 0xffffff); channels_set_bg(&popts.focusedchan, 0x00c080); - popts.bordermask = NCBOXMASK_BOTTOM | NCBOXMASK_TOP | - NCBOXMASK_RIGHT | NCBOXMASK_LEFT; struct panelreel* pr = panelreel_create(n, &popts, -1); if(!pr || notcurses_render(nc)){ notcurses_stop(nc);