OTHERS: add termbox, termion, pancurses

pull/783/head
nick black 4 years ago
parent 718abd648a
commit 84746f1f31
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -3,12 +3,15 @@
* [NCURSES](https://invisible-island.net/ncurses/) (C)
* [caca](http://caca.zoy.org/wiki/libcaca) (C)
* [Newt](https://pagure.io/newt) (C)
* [termbox](https://github.com/nsf/termbox) (C+Python)
* [libtickit](http://www.leonerd.org.uk/code/libtickit/) (C)
* [FINAL CUT](https://github.com/gansm/finalcut) (C++)
* [CPPurses](https://github.com/a-n-t-h-o-n-y/CPPurses) (C++)
* [ImTui](https://github.com/ggerganov/imtui) (C++)
* [tui-rs](https://github.com/fdehau/tui-rs) (Rust)
* [termion](https://github.com/redox-os/termion) (Rust)
* [crossterm](https://github.com/crossterm-rs/crossterm) (Rust)
* [pancurses](https://github.com/ihalila/pancurses) (Rust)
* [termwiz](https://github.com/wez/wezterm/tree/master/termwiz) (Rust)
* [blessed-contrib](https://github.com/yaronn/blessed-contrib) (Javascript)
* [tty-cursor](https://github.com/piotrmurach/tty-cursor) (Ruby)

@ -371,7 +371,7 @@ inline int ncplane_cursor_move_yx(ncplane* n, int y, int x){
n->x = x;
}
if(y >= n->leny){
logerror(n->nc, "Target y %d >= length %d\n", y, n->leny);
logerror(n->nc, "Target y %d >= height %d\n", y, n->leny);
return -1;
}else if(y < 0){
if(y < -1){
@ -403,7 +403,10 @@ ncplane* ncplane_dup(const ncplane* n, void* opaque){
ncplane_destroy(newn);
return NULL;
}else{
ncplane_cursor_move_yx(newn, n->y, n->x);
if(ncplane_cursor_move_yx(newn, n->y, n->x) < 0){
ncplane_destroy(newn);
return NULL;
}
newn->attrword = attr;
newn->channels = chan;
memmove(newn->fb, n->fb, sizeof(*n->fb) * dimx * dimy);
@ -1191,6 +1194,7 @@ cell_obliterate(ncplane* n, cell* c){
// increment y by 1 and rotate the framebuffer up one line. x moves to 0.
static inline void
scroll_down(ncplane* n){
fprintf(stderr, "SCROLL!\n");
n->x = 0;
if(n->y == n->leny - 1){
n->logrow = (n->logrow + 1) % n->leny;
@ -1214,6 +1218,8 @@ int ncplane_putc_yx(ncplane* n, int y, int x, const cell* c){
}
scroll_down(n);
}
if(c->gcluster == '\n'){ fprintf(stderr, "YARP YARP\n"); }
if(ncplane_cursor_move_yx(n, y, x)){
return -1;
}
@ -1506,6 +1512,7 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
// through the linebreaker, and advance text.
// FIXME what about a long word? do we want to leave the big gap?
const int dimx = ncplane_dim_x(n);
const int dimy = ncplane_dim_y(n);
const char* linestart = text;
int x = 0; // number of columns consumed for this line
do{
@ -1517,7 +1524,7 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
// might catch a space, in which case we want breaker updated. if it's
// not a space, it won't be printed, and we carry the word forward.
// FIXME what ought be done with \n or multiple spaces?
//fprintf(stderr, "laying out [%s] at %d (%d)\n", linestart, x, dimx);
fprintf(stderr, "laying out [%s] at %d (%d)\n", linestart, x, dimx);
while(*text && x <= dimx){
wchar_t w;
size_t consumed = mbrtowc(&w, text, MB_CUR_MAX, &mbstate);
@ -1552,6 +1559,7 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
x += width;
text += consumed;
}
fprintf(stderr, "OUT! %s\n", linestart);
int carrycols = 0;
// if we have no breaker, we got a word that was longer than our line;
// print what we can and move along. if *text is nul, we're done.
@ -1565,7 +1573,8 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
totalcols += (breaker - linestart);
const int xpos = ncplane_align(n, align, x);
// blows out if we supply a y beyond leny
if(ncplane_putnstr_yx(n, y, xpos, breaker - linestart, linestart) < 0){
fprintf(stderr, "y: %d %d %.*s\n", y, breaker - linestart, breaker - linestart, linestart);
if(ncplane_putnstr_yx(n, y, xpos, breaker - linestart, linestart) <= 0){
if(bytes){
*bytes = linestart - beginning;
}
@ -1578,7 +1587,20 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
}else{
linestart = breaker + 1;
}
++y; // FIXME scrolling!??!!
fprintf(stderr, "OUT2! %s\n", linestart);
if(++y >= dimy){
if(n->scrolling){
if(ncplane_putsimple_yx(n, -1, -1, '\n') < 0){
fprintf(stderr, "NO NEWLINE!\n");
if(bytes){
*bytes = linestart - beginning;
}
return -1;
}
--y;
}
}
fprintf(stderr, "LOOKING AT: [%c]\n", *text);
}while(*text);
if(bytes){
*bytes = text - beginning;

@ -188,13 +188,47 @@ TEST_CASE("TextLayout") {
auto sp = ncplane_new(nc_, 2, 13, 0, 0, nullptr);
REQUIRE(sp);
size_t bytes;
const char boundstr[] = "quantum balls scratchy?!";
const char boundstr[] = "quantum balls scratchy no?!";
CHECK(0 < ncplane_puttext(sp, 0, NCALIGN_LEFT, boundstr, &bytes));
CHECK(0 == notcurses_render(nc_));
CHECK(bytes == strlen(boundstr));
char* line = ncplane_contents(sp, 0, 0, -1, -1);
REQUIRE(line);
CHECK(0 == strcmp(line, "quantum ballsscratchy?!"));
CHECK(0 == strcmp(line, "quantum ballsscratchy no?!"));
free(line);
ncplane_destroy(sp);
}
SUBCASE("LayoutLongNoScroll") {
auto sp = ncplane_new(nc_, 2, 13, 0, 0, nullptr);
REQUIRE(sp);
size_t bytes;
const char boundstr[] = "quantum balls scratchy no?! truly! arrrrp";
int res = ncplane_puttext(sp, 0, NCALIGN_LEFT, boundstr, &bytes);
CHECK(0 > res);
CHECK(0 == notcurses_render(nc_));
CHECK(bytes < strlen(boundstr));
char* line = ncplane_contents(sp, 0, 0, -1, -1);
REQUIRE(line);
CHECK(0 == strcmp(line, "quantum ballsscratchy no?!"));
free(line);
ncplane_destroy(sp);
}
SUBCASE("LayoutLongScroll") {
auto sp = ncplane_new(nc_, 2, 13, 0, 0, nullptr);
REQUIRE(sp);
ncplane_set_scrolling(sp, true);
size_t bytes;
const char boundstr[] = "quantum balls scratchy?! true! arrrrp";
CHECK(0 < ncplane_puttext(sp, 0, NCALIGN_LEFT, boundstr, &bytes));
CHECK(0 == notcurses_render(nc_));
sleep(1);
CHECK(bytes == strlen(boundstr));
char* line = ncplane_contents(sp, 0, 0, -1, -1);
REQUIRE(line);
CHECK(0 == strcmp(line, "scratchy?! true! arrrrp"));
fprintf(stderr, "LINE: [%s]\n", line);
free(line);
ncplane_destroy(sp);
}

Loading…
Cancel
Save