mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-09 19:10:48 +00:00
162f9910c2
Tons of work on ncreel (#627, #749, #694) Improve reel demo: get input wired up once more, avoid the FPS demo at bottom, print pointer and line count in each tablet, use new ncreel API. Improve notcurses-ncreel explorer: kill memory leaks (#694), draw tablets better, use new ncreel API. Fix bug in ncreel core where cruft could be left on the screen, via a very gross brute force algorithm. I'll likely come back and make this a bit less ghastly in the future #749. Remove weird one-off input system from ncreel, residue from outcurses. Make some of the normalizing changes speced out in #627 * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * more terminal environment variable notes * TERMS.md: add Sakura, st * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * reel: tighten up reel following redraw * reel: fix upper-left corner of topless perimeter * ncreel: print linecount, return clipped value * reel: draw focused tablet relative to reel * reel: brute force decruftification, how embarrassing #749
231 lines
6.2 KiB
C++
231 lines
6.2 KiB
C++
#include "main.h"
|
|
#include <iostream>
|
|
|
|
auto panelcb(struct nctablet* t, int begx, int begy, int maxx, int maxy, bool cliptop) -> int {
|
|
CHECK(nctablet_ncplane(t));
|
|
CHECK(begx < maxx);
|
|
CHECK(begy < maxy);
|
|
CHECK(!nctablet_userptr(t));
|
|
CHECK(!cliptop);
|
|
// FIXME verify geometry is as expected
|
|
return 0;
|
|
}
|
|
|
|
TEST_CASE("Reels") {
|
|
auto nc_ = testing_notcurses();
|
|
if(!nc_){
|
|
return;
|
|
}
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
|
REQUIRE(n_);
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
SUBCASE("InitLinear") {
|
|
ncreel_options r = { };
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
}
|
|
|
|
SUBCASE("InitLinearInfinite") {
|
|
ncreel_options r{};
|
|
r.flags = NCREEL_OPTION_INFINITESCROLL;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
}
|
|
|
|
SUBCASE("InitCircular") {
|
|
ncreel_options r{};
|
|
r.flags = NCREEL_OPTION_INFINITESCROLL | NCREEL_OPTION_CIRCULAR;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
REQUIRE(0 == ncreel_destroy(nr));
|
|
}
|
|
|
|
// circular is not allowed to be true when infinitescroll is false
|
|
SUBCASE("FiniteCircleRejected") {
|
|
ncreel_options r{};
|
|
r.flags = NCREEL_OPTION_CIRCULAR;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(!nr);
|
|
}
|
|
|
|
// We ought be able to invoke ncreel_next() and ncreel_prev() safely,
|
|
// even if there are no tablets. They both ought return nullptr.
|
|
SUBCASE("MovementWithoutTablets") {
|
|
ncreel_options r{};
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
CHECK(!ncreel_next(nr));
|
|
// CHECK_EQ(0, ncreel_validate(n_, pr));
|
|
CHECK(!ncreel_prev(nr));
|
|
// CHECK_EQ(0, ncreel_validate(n_, pr));
|
|
}
|
|
|
|
SUBCASE("OneTablet") {
|
|
ncreel_options r{};
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
struct nctablet* t = ncreel_add(nr, nullptr, nullptr, panelcb, nullptr);
|
|
REQUIRE(t);
|
|
// CHECK_EQ(0, ncreel_validate(n_, pr));
|
|
CHECK(0 == ncreel_del(nr, t));
|
|
// CHECK_EQ(0, ncreel_validate(n_, pr));
|
|
}
|
|
|
|
SUBCASE("MovementWithOneTablet") {
|
|
ncreel_options r{};
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
struct nctablet* t = ncreel_add(nr, nullptr, nullptr, panelcb, nullptr);
|
|
REQUIRE(t);
|
|
// CHECK_EQ(0, ncreel_validate(n_, pr));
|
|
CHECK(ncreel_next(nr));
|
|
// CHECK_EQ(0, ncreel_validate(n_, pr));
|
|
CHECK(ncreel_prev(nr));
|
|
// CHECK_EQ(0, ncreel_validate(n_, pr));
|
|
CHECK(0 == ncreel_del(nr, t));
|
|
// CHECK_EQ(0, ncreel_validate(n_, pr));
|
|
}
|
|
|
|
SUBCASE("DeleteActiveTablet") {
|
|
ncreel_options r{};
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
struct nctablet* t = ncreel_add(nr, nullptr, nullptr, panelcb, nullptr);
|
|
REQUIRE(t);
|
|
CHECK(0 == ncreel_del(nr, ncreel_focused(nr)));
|
|
}
|
|
|
|
SUBCASE("NoBorder") {
|
|
ncreel_options r{};
|
|
r.bordermask = NCBOXMASK_LEFT | NCBOXMASK_RIGHT |
|
|
NCBOXMASK_TOP | NCBOXMASK_BOTTOM;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
}
|
|
|
|
SUBCASE("BadBorderBitsRejected") {
|
|
ncreel_options r{};
|
|
r.bordermask = NCBOXMASK_LEFT * 2;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(!nr);
|
|
}
|
|
|
|
SUBCASE("NoTabletBorder") {
|
|
ncreel_options r{};
|
|
r.tabletmask = NCBOXMASK_LEFT | NCBOXMASK_RIGHT |
|
|
NCBOXMASK_TOP | NCBOXMASK_BOTTOM;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
}
|
|
|
|
SUBCASE("NoTopBottomBorder") {
|
|
ncreel_options r{};
|
|
r.bordermask = NCBOXMASK_TOP | NCBOXMASK_BOTTOM;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
}
|
|
|
|
SUBCASE("NoSideBorders") {
|
|
ncreel_options r{};
|
|
r.bordermask = NCBOXMASK_LEFT | NCBOXMASK_RIGHT;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
}
|
|
|
|
SUBCASE("BadTabletBorderBitsRejected") {
|
|
ncreel_options r{};
|
|
r.tabletmask = NCBOXMASK_LEFT * 2;
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(!nr);
|
|
}
|
|
|
|
/*
|
|
// Make a target window occupying all but a containing perimeter of the
|
|
// specified WINDOW (which will usually be n_).
|
|
struct ncpanel* make_targwin(struct ncpanel* w) {
|
|
cchar_t cc;
|
|
int cpair = COLOR_GREEN;
|
|
CHECK_EQ(OK, setcchar(&cc, L"W", 0, 0, &cpair));
|
|
int x, y, xx, yy;
|
|
getbegyx(w, y, x);
|
|
getmaxyx(w, yy, xx);
|
|
yy -= 2;
|
|
xx -= 2;
|
|
++x;
|
|
++y;
|
|
WINDOW* ww = subwin(w, yy, xx, y, x);
|
|
CHECK_NE(nullptr, ww);
|
|
PANEL* p = new_panel(ww);
|
|
CHECK_NE(nullptr, p);
|
|
CHECK_EQ(OK, wbkgrnd(ww, &cc));
|
|
return p;
|
|
}
|
|
|
|
SUBCASE("InitWithinSubwin") {
|
|
ncreel_options r{};
|
|
r.loff = 1;
|
|
r.roff = 1;
|
|
r.toff = 1;
|
|
r.boff = 1;
|
|
CHECK_EQ(0, clear());
|
|
PANEL* base = make_targwin(n_);
|
|
REQUIRE_NE(nullptr, base);
|
|
WINDOW* basew = panel_window(base);
|
|
REQUIRE_NE(nullptr, basew);
|
|
struct ncreel* nr = ncreel_create(basew, &r);
|
|
REQUIRE_NE(nullptr, pr);
|
|
CHECK_EQ(0, ncreel_validate(basew, pr));
|
|
REQUIRE_EQ(0, ncreel_destroy(nr));
|
|
CHECK_EQ(OK, del_panel(base));
|
|
CHECK_EQ(OK, delwin(basew));
|
|
}
|
|
|
|
SUBCASE("SubwinNoncreelBorders") {
|
|
ncreel_options r{};
|
|
r.loff = 1;
|
|
r.roff = 1;
|
|
r.toff = 1;
|
|
r.boff = 1;
|
|
r.bordermask = NCBOXMASK_LEFT | NCBOXMASK_RIGHT |
|
|
NCBOXMASK_TOP | NCBOXMASK_BOTTOM;
|
|
CHECK_EQ(0, clear());
|
|
PANEL* base = make_targwin(n_);
|
|
REQUIRE_NE(nullptr, base);
|
|
WINDOW* basew = panel_window(base);
|
|
REQUIRE_NE(nullptr, basew);
|
|
struct ncreel* nr = ncreel_create(basew, &r);
|
|
REQUIRE_NE(nullptr, pr);
|
|
CHECK_EQ(0, ncreel_validate(basew, pr));
|
|
REQUIRE_EQ(0, ncreel_destroy(nr));
|
|
CHECK_EQ(OK, del_panel(base));
|
|
CHECK_EQ(OK, delwin(basew));
|
|
}
|
|
|
|
SUBCASE("SubwinNoOffsetGeom") {
|
|
ncreel_options r{};
|
|
CHECK_EQ(0, clear());
|
|
PANEL* base = make_targwin(n_);
|
|
REQUIRE_NE(nullptr, base);
|
|
WINDOW* basew = panel_window(base);
|
|
REQUIRE_NE(nullptr, basew);
|
|
struct ncreel* nr = ncreel_create(basew, &r);
|
|
REQUIRE_NE(nullptr, pr);
|
|
CHECK_EQ(0, ncreel_validate(basew, pr));
|
|
REQUIRE_EQ(0, ncreel_destroy(nr));
|
|
CHECK_EQ(OK, del_panel(base));
|
|
CHECK_EQ(OK, delwin(basew));
|
|
}
|
|
*/
|
|
|
|
SUBCASE("TransparentBackground") {
|
|
ncreel_options r{};
|
|
channels_set_bg_alpha(&r.bgchannel, 3);
|
|
struct ncreel* nr = ncreel_create(n_, &r);
|
|
REQUIRE(nr);
|
|
// FIXME
|
|
}
|
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
|
}
|