Notcurses 3.0.16
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
in.c File Reference
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "automaton.h"
#include "internal.h"
#include "unixsig.h"
#include "render.h"
#include "in.h"
Include dependency graph for in.c:

Go to the source code of this file.

Data Structures

struct  cursorloc
 
struct  inputctx
 

Typedefs

typedef struct cursorloc cursorloc
 
typedef int ipipe
 
typedef struct inputctx inputctx
 

Functions

void sigwinch_handler (int signo)
 
int ncinput_shovel (inputctx *ictx, const void *buf, int len)
 
int init_inputlayer (tinfo *ti, FILE *infp, int lmargin, int tmargin, int rmargin, int bmargin, ncsharedstats *stats, unsigned drain, int linesigs_enabled)
 
int stop_inputlayer (tinfo *ti)
 
int inputready_fd (const inputctx *ictx)
 
uint32_t notcurses_get (notcurses *nc, const struct timespec *absdl, ncinput *ni)
 
int notcurses_getvec (notcurses *n, const struct timespec *absdl, ncinput *ni, int vcount)
 
uint32_t ncdirect_get (ncdirect *n, const struct timespec *absdl, ncinput *ni)
 
int get_cursor_location (inputctx *ictx, const char *u7, unsigned *y, unsigned *x)
 
int notcurses_linesigs_disable (notcurses *nc)
 
int notcurses_linesigs_enable (notcurses *n)
 
struct initial_responsesinputlayer_get_responses (inputctx *ictx)
 

Typedef Documentation

◆ cursorloc

typedef struct cursorloc cursorloc

◆ inputctx

typedef struct inputctx inputctx

◆ ipipe

typedef int ipipe

Definition at line 46 of file in.c.

Function Documentation

◆ get_cursor_location()

int get_cursor_location ( inputctx ictx,
const char *  u7,
unsigned *  y,
unsigned *  x 
)

Definition at line 2810 of file in.c.

2810 {
2811 pthread_mutex_lock(&ictx->clock);
2812 while(ictx->cvalid == 0){
2813 if(ictx->coutstanding == 0){
2814 if(tty_emit(u7, ictx->ti->ttyfd)){
2815 pthread_mutex_unlock(&ictx->clock);
2816 return -1;
2817 }
2818 ++ictx->coutstanding;
2819 }
2820 pthread_cond_wait(&ictx->ccond, &ictx->clock);
2821 }
2822 const cursorloc* cloc = &ictx->csrs[ictx->cread];
2823 if(++ictx->cread == ictx->csize){
2824 ictx->cread = 0;
2825 }
2826 --ictx->cvalid;
2827 if(y){
2828 *y = cloc->y;
2829 }
2830 if(x){
2831 *x = cloc->x;
2832 }
2833 pthread_mutex_unlock(&ictx->clock);
2834 return 0;
2835}
int y
Definition notcurses.h:1905
int int x
Definition notcurses.h:1905
Definition in.c:41
int y
Definition in.c:42
int x
Definition in.c:42
pthread_cond_t ccond
Definition in.c:90
cursorloc * csrs
Definition in.c:78
pthread_mutex_t clock
Definition in.c:89
int cvalid
Definition in.c:82
int cread
Definition in.c:85
int coutstanding
Definition in.c:80
tinfo * ti
Definition in.c:91
int csize
Definition in.c:81
int ttyfd
Definition termdesc.h:109
Here is the caller graph for this function:

◆ init_inputlayer()

int init_inputlayer ( tinfo ti,
FILE *  infp,
int  lmargin,
int  tmargin,
int  rmargin,
int  bmargin,
ncsharedstats stats,
unsigned  drain,
int  linesigs_enabled 
)

Definition at line 2638 of file in.c.

2640 {
2641 inputctx* ictx = create_inputctx(ti, infp, lmargin, tmargin, rmargin,
2642 bmargin, stats, drain, linesigs_enabled);
2643 if(ictx == NULL){
2644 return -1;
2645 }
2646 if(pthread_create(&ictx->tid, NULL, input_thread, ictx)){
2647 free_inputctx(ictx);
2648 return -1;
2649 }
2650 ti->ictx = ictx;
2651 loginfo("spun up input thread");
2652 return 0;
2653}
#define loginfo(fmt,...)
Definition logging.h:42
Definition in.c:52
pthread_t tid
Definition in.c:92
struct inputctx * ictx
Definition termdesc.h:181
return NULL
Definition termdesc.h:229
Here is the caller graph for this function:

◆ inputlayer_get_responses()

struct initial_responses * inputlayer_get_responses ( inputctx ictx)

Definition at line 2921 of file in.c.

2921 {
2922 struct initial_responses* iresp;
2923 pthread_mutex_lock(&ictx->ilock);
2924 while(ictx->initdata || !ictx->initdata_complete){
2925 pthread_cond_wait(&ictx->icond, &ictx->ilock);
2926 }
2927 iresp = ictx->initdata_complete;
2928 ictx->initdata_complete = NULL;
2929 pthread_mutex_unlock(&ictx->ilock);
2930 if(ictx->failed){
2931 logpanic("aborting after automaton construction failure");
2932 free(iresp);
2933 return NULL;
2934 }
2935 return iresp;
2936}
#define logpanic(fmt,...)
Definition logging.h:22
bool failed
Definition in.c:112
pthread_mutex_t ilock
Definition in.c:87
pthread_cond_t icond
Definition in.c:88
struct initial_responses * initdata_complete
Definition in.c:110
struct initial_responses * initdata
Definition in.c:109

◆ inputready_fd()

int inputready_fd ( const inputctx ictx)

Definition at line 2672 of file in.c.

2672 {
2673#ifndef __MINGW32__
2674 return ictx->readypipes[0];
2675#else
2676 (void)ictx;
2677 logerror("readiness descriptor unavailable on windows");
2678 return -1;
2679#endif
2680}
#define logerror(fmt,...)
Definition logging.h:32
ipipe readypipes[2]
Definition in.c:103
Here is the caller graph for this function:

◆ ncdirect_get()

uint32_t ncdirect_get ( ncdirect n,
const struct timespec *  absdl,
ncinput ni 
)

Definition at line 2798 of file in.c.

2798 {
2799 if(n->eof){
2800 logerror("already got EOF");
2801 return -1;
2802 }
2803 uint32_t r = internal_get(n->tcache.ictx, absdl, ni);
2804 if(r == NCKEY_EOF){
2805 n->eof = 1;
2806 }
2807 return r;
2808}
int r
Definition fbuf.h:226
#define NCKEY_EOF
Definition nckeys.h:183
vopts n
Definition notcurses.h:3506
Here is the caller graph for this function:

◆ ncinput_shovel()

int ncinput_shovel ( inputctx ictx,
const void *  buf,
int  len 
)

Definition at line 2476 of file in.c.

2476 {
2477 process_melange(ictx, buf, &len);
2478 if(len){
2479 logwarn("dropping %d byte%s", len, len == 1 ? "" : "s");
2480 inc_input_errors(ictx);
2481 }
2482 return 0;
2483}
#define logwarn(fmt,...)
Definition logging.h:37
API int API int const nccell unsigned len
Definition notcurses.h:2592

◆ notcurses_get()

uint32_t notcurses_get ( notcurses nc,
const struct timespec *  absdl,
ncinput ni 
)

Definition at line 2776 of file in.c.

2776 {
2777 uint32_t ret = internal_get(nc->tcache.ictx, absdl, ni);
2778 return ret;
2779}
tinfo tcache
Definition internal.h:360
Here is the caller graph for this function:

◆ notcurses_getvec()

int notcurses_getvec ( notcurses n,
const struct timespec *  absdl,
ncinput ni,
int  vcount 
)

Definition at line 2782 of file in.c.

2783 {
2784 for(int v = 0 ; v < vcount ; ++v){
2785 uint32_t u = notcurses_get(n, absdl, &ni[v]);
2786 if(u == (uint32_t)-1){
2787 if(v == 0){
2788 return -1;
2789 }
2790 return v;
2791 }else if(u == 0){
2792 return v;
2793 }
2794 }
2795 return vcount;
2796}
uint32_t notcurses_get(notcurses *nc, const struct timespec *absdl, ncinput *ni)
Definition in.c:2776
struct ncvisual_options v
Definition notcurses.h:3501
Here is the call graph for this function:

◆ notcurses_linesigs_disable()

int notcurses_linesigs_disable ( notcurses nc)

Definition at line 2875 of file in.c.

2875 {
2876 return linesigs_disable(&nc->tcache);
2877}
Here is the caller graph for this function:

◆ notcurses_linesigs_enable()

int notcurses_linesigs_enable ( notcurses n)

Definition at line 2917 of file in.c.

2917 {
2918 return linesigs_enable(&n->tcache);
2919}
Here is the caller graph for this function:

◆ sigwinch_handler()

void sigwinch_handler ( int  signo)

Definition at line 31 of file in.c.

31 {
32 if(signo == SIGWINCH){
33 resize_seen = signo;
35 }else if(signo == SIGCONT){
36 cont_seen = signo;
38 }
39}
sig_atomic_t sigcont_seen_for_render
Definition render.c:7
Here is the caller graph for this function:

◆ stop_inputlayer()

int stop_inputlayer ( tinfo ti)

Definition at line 2655 of file in.c.

2655 {
2656 int ret = 0;
2657 if(ti){
2658 // FIXME cancellation on shutdown does not yet work on windows #2192
2659#ifndef __MINGW32__
2660 if(ti->ictx){
2661 loginfo("tearing down input thread");
2662 ret |= cancel_and_join("input", ti->ictx->tid, NULL);
2664 free_inputctx(ti->ictx);
2665 ti->ictx = NULL;
2666 }
2667#endif
2668 }
2669 return ret;
2670}
int set_fd_nonblocking(int fd, unsigned state, unsigned *oldstate)
int stdinfd
Definition in.c:58
unsigned stdio_blocking_save
Definition termdesc.h:182
Here is the call graph for this function:
Here is the caller graph for this function: