Notcurses 3.0.13
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 2785 of file in.c.

2785 {
2786 pthread_mutex_lock(&ictx->clock);
2787 while(ictx->cvalid == 0){
2788 if(ictx->coutstanding == 0){
2789 if(tty_emit(u7, ictx->ti->ttyfd)){
2790 pthread_mutex_unlock(&ictx->clock);
2791 return -1;
2792 }
2793 ++ictx->coutstanding;
2794 }
2795 pthread_cond_wait(&ictx->ccond, &ictx->clock);
2796 }
2797 const cursorloc* cloc = &ictx->csrs[ictx->cread];
2798 if(++ictx->cread == ictx->csize){
2799 ictx->cread = 0;
2800 }
2801 --ictx->cvalid;
2802 if(y){
2803 *y = cloc->y;
2804 }
2805 if(x){
2806 *x = cloc->x;
2807 }
2808 pthread_mutex_unlock(&ictx->clock);
2809 return 0;
2810}
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 2627 of file in.c.

2629 {
2630 inputctx* ictx = create_inputctx(ti, infp, lmargin, tmargin, rmargin,
2631 bmargin, stats, drain, linesigs_enabled);
2632 if(ictx == NULL){
2633 return -1;
2634 }
2635 if(pthread_create(&ictx->tid, NULL, input_thread, ictx)){
2636 free_inputctx(ictx);
2637 return -1;
2638 }
2639 ti->ictx = ictx;
2640 loginfo("spun up input thread");
2641 return 0;
2642}
#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 2896 of file in.c.

2896 {
2897 struct initial_responses* iresp;
2898 pthread_mutex_lock(&ictx->ilock);
2899 while(ictx->initdata || !ictx->initdata_complete){
2900 pthread_cond_wait(&ictx->icond, &ictx->ilock);
2901 }
2902 iresp = ictx->initdata_complete;
2903 ictx->initdata_complete = NULL;
2904 pthread_mutex_unlock(&ictx->ilock);
2905 if(ictx->failed){
2906 logpanic("aborting after automaton construction failure");
2907 free(iresp);
2908 return NULL;
2909 }
2910 return iresp;
2911}
free(duplicated)
#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
Here is the call graph for this function:

◆ inputready_fd()

int inputready_fd ( const inputctx ictx)

Definition at line 2661 of file in.c.

2661 {
2662#ifndef __MINGW32__
2663 return ictx->readypipes[0];
2664#else
2665 (void)ictx;
2666 logerror("readiness descriptor unavailable on windows");
2667 return -1;
2668#endif
2669}
#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 2773 of file in.c.

2773 {
2774 if(n->eof){
2775 logerror("already got EOF");
2776 return -1;
2777 }
2778 uint32_t r = internal_get(n->tcache.ictx, absdl, ni);
2779 if(r == NCKEY_EOF){
2780 n->eof = 1;
2781 }
2782 return r;
2783}
int r
Definition fbuf.h:226
#define NCKEY_EOF
Definition nckeys.h:183
vopts n
Definition notcurses.h:3502
Here is the caller graph for this function:

◆ ncinput_shovel()

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

Definition at line 2463 of file in.c.

2463 {
2464 process_melange(ictx, buf, &len);
2465 if(len){
2466 logwarn("dropping %d byte%s", len, len == 1 ? "" : "s");
2467 inc_input_errors(ictx);
2468 }
2469 return 0;
2470}
#define logwarn(fmt,...)
Definition logging.h:37
API int API int const nccell unsigned len
Definition notcurses.h:2588

◆ notcurses_get()

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

Definition at line 2751 of file in.c.

2751 {
2752 uint32_t ret = internal_get(nc->tcache.ictx, absdl, ni);
2753 return ret;
2754}
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 2757 of file in.c.

2758 {
2759 for(int v = 0 ; v < vcount ; ++v){
2760 uint32_t u = notcurses_get(n, absdl, &ni[v]);
2761 if(u == (uint32_t)-1){
2762 if(v == 0){
2763 return -1;
2764 }
2765 return v;
2766 }else if(u == 0){
2767 return v;
2768 }
2769 }
2770 return vcount;
2771}
uint32_t notcurses_get(notcurses *nc, const struct timespec *absdl, ncinput *ni)
Definition in.c:2751
struct ncvisual_options v
Definition notcurses.h:3497
Here is the call graph for this function:

◆ notcurses_linesigs_disable()

int notcurses_linesigs_disable ( notcurses nc)

Definition at line 2850 of file in.c.

2850 {
2851 return linesigs_disable(&nc->tcache);
2852}
Here is the caller graph for this function:

◆ notcurses_linesigs_enable()

int notcurses_linesigs_enable ( notcurses n)

Definition at line 2892 of file in.c.

2892 {
2893 return linesigs_enable(&n->tcache);
2894}
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 2644 of file in.c.

2644 {
2645 int ret = 0;
2646 if(ti){
2647 // FIXME cancellation on shutdown does not yet work on windows #2192
2648#ifndef __MINGW32__
2649 if(ti->ictx){
2650 loginfo("tearing down input thread");
2651 ret |= cancel_and_join("input", ti->ictx->tid, NULL);
2653 free_inputctx(ti->ictx);
2654 ti->ictx = NULL;
2655 }
2656#endif
2657 }
2658 return ret;
2659}
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: