mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
unify ncinputlayer between direct and rendered mode #1525
This commit is contained in:
parent
36d1eaf37b
commit
e10a2f7a21
@ -771,9 +771,6 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ncinputlayer_init(&ret->input, stdin)){
|
||||
goto err;
|
||||
}
|
||||
const char* shortname_term;
|
||||
int termerr;
|
||||
if(setupterm(termtype, ret->ctermfd, &termerr) != OK){
|
||||
@ -781,10 +778,13 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
|
||||
goto err;
|
||||
}
|
||||
shortname_term = termname();
|
||||
if(ncvisual_init(NCLOGLEVEL_SILENT)){
|
||||
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8, 1)){
|
||||
goto err;
|
||||
}
|
||||
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8, 1)){
|
||||
if(ncinputlayer_init(&ret->tcache.input, stdin)){
|
||||
goto err;
|
||||
}
|
||||
if(ncvisual_init(NCLOGLEVEL_SILENT)){
|
||||
goto err;
|
||||
}
|
||||
update_term_dimensions(ret->ctermfd, NULL, NULL, &ret->tcache);
|
||||
@ -804,7 +804,7 @@ int ncdirect_stop(ncdirect* nc){
|
||||
int ret = 0;
|
||||
if(nc){
|
||||
ret |= ncdirect_stop_minimal(nc);
|
||||
input_free_esctrie(&nc->input.inputescapes);
|
||||
input_free_esctrie(&nc->tcache.input.inputescapes);
|
||||
free(nc);
|
||||
}
|
||||
return ret;
|
||||
|
@ -464,10 +464,10 @@ ncinputlayer_prestamp(ncinputlayer* nc, const struct timespec *ts,
|
||||
// infp has already been set non-blocking
|
||||
char32_t notcurses_getc(notcurses* nc, const struct timespec *ts,
|
||||
const sigset_t* sigmask, ncinput* ni){
|
||||
char32_t r = ncinputlayer_prestamp(&nc->input, ts, sigmask, ni,
|
||||
char32_t r = ncinputlayer_prestamp(&nc->tcache.input, ts, sigmask, ni,
|
||||
nc->margin_l, nc->margin_t);
|
||||
if(r != (char32_t)-1){
|
||||
uint64_t stamp = nc->input.input_events++; // need increment even if !ni
|
||||
uint64_t stamp = nc->tcache.input.input_events++; // need increment even if !ni
|
||||
if(ni){
|
||||
ni->seqnum = stamp;
|
||||
}
|
||||
@ -477,9 +477,9 @@ char32_t notcurses_getc(notcurses* nc, const struct timespec *ts,
|
||||
|
||||
char32_t ncdirect_getc(ncdirect* nc, const struct timespec *ts,
|
||||
sigset_t* sigmask, ncinput* ni){
|
||||
char32_t r = ncinputlayer_prestamp(&nc->input, ts, sigmask, ni, 0, 0);
|
||||
char32_t r = ncinputlayer_prestamp(&nc->tcache.input, ts, sigmask, ni, 0, 0);
|
||||
if(r != (char32_t)-1){
|
||||
uint64_t stamp = nc->input.input_events++; // need increment even if !ni
|
||||
uint64_t stamp = nc->tcache.input.input_events++; // need increment even if !ni
|
||||
if(ni){
|
||||
ni->seqnum = stamp;
|
||||
}
|
||||
|
@ -398,23 +398,6 @@ typedef struct nctabbed {
|
||||
nctabbed_options opts; // copied in nctabbed_create()
|
||||
} nctabbed;
|
||||
|
||||
typedef struct ncinputlayer {
|
||||
int ttyinfd; // file descriptor for processing input
|
||||
unsigned char inputbuf[BUFSIZ];
|
||||
// we keep a wee ringbuffer of input queued up for delivery. if
|
||||
// inputbuf_occupied == sizeof(inputbuf), there is no room. otherwise, data
|
||||
// can be read to inputbuf_write_at until we fill up. the first datum
|
||||
// available for the app is at inputbuf_valid_starts iff inputbuf_occupied is
|
||||
// not 0. the main purpose is working around bad predictions of escapes.
|
||||
unsigned inputbuf_occupied;
|
||||
unsigned inputbuf_valid_starts;
|
||||
unsigned inputbuf_write_at;
|
||||
// number of input events seen. does not belong in ncstats, since it must not
|
||||
// be reset (semantics are relied upon by widgets for mouse click detection).
|
||||
uint64_t input_events;
|
||||
struct esctrie* inputescapes; // trie of input escapes -> ncspecial_keys
|
||||
} ncinputlayer;
|
||||
|
||||
typedef struct ncdirect {
|
||||
palette256 palette; // 256-indexed palette can be used instead of/with RGB
|
||||
FILE* ttyfp; // FILE* for output tty
|
||||
@ -422,7 +405,6 @@ typedef struct ncdirect {
|
||||
tinfo tcache; // terminfo cache
|
||||
uint64_t channels; // current channels
|
||||
uint16_t stylemask; // current styles
|
||||
ncinputlayer input; // input layer; we're in cbreak mode
|
||||
struct termios tpreserved; // terminal state upon entry
|
||||
// some terminals (e.g. kmscon) return cursor coordinates inverted from the
|
||||
// typical order. we detect it the first time ncdirect_cursor_yx() is called.
|
||||
@ -503,7 +485,6 @@ typedef struct notcurses {
|
||||
|
||||
FILE* ttyfp; // FILE* for writing rasterized data
|
||||
int ttyfd; // file descriptor for controlling tty
|
||||
ncinputlayer input; // input layer; we're in cbreak mode
|
||||
FILE* renderfp; // debugging FILE* to which renderings are written
|
||||
tinfo tcache; // terminfo cache
|
||||
struct termios tpreserved; // terminal state upon entry
|
||||
|
@ -1068,10 +1068,10 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
|
||||
goto err;
|
||||
}
|
||||
ret->suppress_banner = opts->flags & NCOPTION_SUPPRESS_BANNERS;
|
||||
if(ncinputlayer_init(&ret->input, stdin)){
|
||||
if(ncinputlayer_init(&ret->tcache.input, stdin)){
|
||||
goto err;
|
||||
}
|
||||
if(set_fd_nonblocking(ret->input.ttyinfd, 1, &ret->stdio_blocking_save)){
|
||||
if(set_fd_nonblocking(ret->tcache.input.ttyinfd, 1, &ret->stdio_blocking_save)){
|
||||
goto err;
|
||||
}
|
||||
if(ncvisual_init(ret->loglevel)){
|
||||
@ -1185,7 +1185,7 @@ int notcurses_stop(notcurses* nc){
|
||||
int ret = 0;
|
||||
if(nc){
|
||||
ret |= notcurses_stop_minimal(nc);
|
||||
ret |= set_fd_nonblocking(nc->input.ttyinfd, nc->stdio_blocking_save, NULL);
|
||||
ret |= set_fd_nonblocking(nc->tcache.input.ttyinfd, nc->stdio_blocking_save, NULL);
|
||||
if(nc->stdplane){
|
||||
notcurses_drop_planes(nc);
|
||||
free_plane(nc->stdplane);
|
||||
@ -1209,7 +1209,7 @@ int notcurses_stop(notcurses* nc){
|
||||
egcpool_dump(&nc->pool);
|
||||
free(nc->lastframe);
|
||||
free(nc->rstate.mstream);
|
||||
input_free_esctrie(&nc->input.inputescapes);
|
||||
input_free_esctrie(&nc->tcache.input.inputescapes);
|
||||
// get any current stats loaded into stash_stats
|
||||
notcurses_stats_reset(nc, NULL);
|
||||
if(!nc->suppress_banner){
|
||||
@ -2589,11 +2589,11 @@ int notcurses_lex_margins(const char* op, notcurses_options* opts){
|
||||
}
|
||||
|
||||
int notcurses_inputready_fd(notcurses* n){
|
||||
return n->input.ttyinfd;
|
||||
return n->tcache.input.ttyinfd;
|
||||
}
|
||||
|
||||
int ncdirect_inputready_fd(ncdirect* n){
|
||||
return n->input.ttyinfd;
|
||||
return n->tcache.input.ttyinfd;
|
||||
}
|
||||
|
||||
uint32_t* ncplane_as_rgba(const ncplane* nc, ncblitter_e blit,
|
||||
|
@ -59,6 +59,23 @@ typedef enum {
|
||||
ESCAPE_MAX
|
||||
} escape_e;
|
||||
|
||||
typedef struct ncinputlayer {
|
||||
int ttyinfd; // file descriptor for processing input
|
||||
unsigned char inputbuf[BUFSIZ];
|
||||
// we keep a wee ringbuffer of input queued up for delivery. if
|
||||
// inputbuf_occupied == sizeof(inputbuf), there is no room. otherwise, data
|
||||
// can be read to inputbuf_write_at until we fill up. the first datum
|
||||
// available for the app is at inputbuf_valid_starts iff inputbuf_occupied is
|
||||
// not 0. the main purpose is working around bad predictions of escapes.
|
||||
unsigned inputbuf_occupied;
|
||||
unsigned inputbuf_valid_starts;
|
||||
unsigned inputbuf_write_at;
|
||||
// number of input events seen. does not belong in ncstats, since it must not
|
||||
// be reset (semantics are relied upon by widgets for mouse click detection).
|
||||
uint64_t input_events;
|
||||
struct esctrie* inputescapes; // trie of input escapes -> ncspecial_keys
|
||||
} ncinputlayer;
|
||||
|
||||
// terminal interface description. most of these are acquired from terminfo(5)
|
||||
// (using a database entry specified by TERM). some are determined via
|
||||
// heuristics based off terminal interrogation or the TERM environment
|
||||
@ -101,6 +118,7 @@ typedef struct tinfo {
|
||||
int (*pixel_shutdown)(int fd); // called during context shutdown
|
||||
int (*pixel_clear_all)(int fd); // called during startup, kitty only
|
||||
int sprixel_scale_height; // sprixel must be a multiple of this many rows
|
||||
ncinputlayer input; // input layer
|
||||
bool bitmap_supported; // do we support bitmaps (post pixel_query_done)?
|
||||
bool pixel_query_done; // have we yet performed pixel query?
|
||||
bool RGBflag; // "RGB" flag for 24bpc truecolor
|
||||
|
Loading…
x
Reference in New Issue
Block a user