Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
reader.c File Reference
#include "internal.h"
Include dependency graph for reader.c:

Go to the source code of this file.

Functions

void ncreader_destroy (ncreader *n, char **contents)
 
ncreaderncreader_create (ncplane *n, const ncreader_options *opts)
 
int ncreader_clear (ncreader *n)
 
ncplanencreader_plane (ncreader *n)
 
int ncreader_move_left (ncreader *n)
 
int ncreader_move_right (ncreader *n)
 
int ncreader_move_up (ncreader *n)
 
int ncreader_move_down (ncreader *n)
 
int ncreader_write_egc (ncreader *n, const char *egc)
 
bool ncreader_offer_input (ncreader *n, const ncinput *ni)
 
char * ncreader_contents (const ncreader *n)
 

Function Documentation

◆ ncreader_clear()

int ncreader_clear ( ncreader n)

Definition at line 73 of file reader.c.

73 {
74 ncplane_erase(n->ncp);
75 ncplane_erase(n->textarea);
76 n->xproject = 0;
77 return 0;
78}
void ncplane_erase(ncplane *n)
Definition notcurses.c:2458
vopts n
Definition notcurses.h:3502
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreader_contents()

char * ncreader_contents ( const ncreader n)

Definition at line 413 of file reader.c.

413 {
414 return ncplane_contents(n->ncp, 0, 0, 0, 0);
415}
char * ncplane_contents(ncplane *nc, int begy, int begx, unsigned leny, unsigned lenx)
Definition notcurses.c:3228
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreader_create()

ncreader * ncreader_create ( ncplane n,
const ncreader_options opts 
)

Definition at line 26 of file reader.c.

26 {
27 ncreader_options zeroed = {0};
28 if(!opts){
29 opts = &zeroed;
30 }
32 logwarn("provided unsupported flags %016" PRIx64, opts->flags);
33 }
34 ncreader* nr = malloc(sizeof(*nr));
35 if(nr == NULL){
37 return NULL;
38 }
39 nr->ncp = n;
40 // do *not* bind it to the visible plane; we always want it offscreen,
41 // to the upper left of the true origin
42 struct ncplane_options nopts = {
43 .y = -ncplane_dim_y(n),
44 .x = -ncplane_dim_x(n),
45 .rows = ncplane_dim_y(n),
46 .cols = ncplane_dim_x(n),
47 .name = "text",
48 };
51 free(nr);
52 return NULL;
53 }
54
56 nr->xproject = 0;
57 nr->tchannels = opts->tchannels;
58 nr->tattrs = opts->tattrword;
61 ncplane_set_channels(nr->ncp, opts->tchannels);
62 ncplane_set_styles(nr->ncp, opts->tattrword);
63 if(ncplane_set_widget(n, nr, (void(*)(void*))ncreader_destroy_internal)){
66 free(nr);
67 return NULL;
68 }
69 return nr;
70}
free(duplicated)
#define logwarn(fmt,...)
Definition logging.h:37
ncplane * notcurses_stdplane(notcurses *nc)
Definition notcurses.c:699
void ncplane_set_channels(ncplane *n, uint64_t channels)
Definition notcurses.c:1494
void ncplane_set_styles(ncplane *n, unsigned stylebits)
Definition notcurses.c:2071
int ncplane_destroy(ncplane *ncp)
Definition notcurses.c:1018
notcurses * ncplane_notcurses(const ncplane *n)
Definition notcurses.c:2626
ncplane * ncplane_create(ncplane *n, const ncplane_options *nopts)
Definition notcurses.c:707
const struct ncplane_options * opts
Definition notcurses.h:3483
#define NCREADER_OPTION_NOCMDKEYS
Definition notcurses.h:4615
#define NCREADER_OPTION_HORSCROLL
Definition notcurses.h:4611
#define NCREADER_OPTION_CURSOR
Definition notcurses.h:4618
uint64_t tchannels
Definition internal.h:215
bool no_cmd_keys
Definition internal.h:220
bool horscroll
Definition internal.h:219
ncplane * ncp
Definition internal.h:214
ncplane * textarea
Definition internal.h:217
int xproject
Definition internal.h:218
uint32_t tattrs
Definition internal.h:216
bool manage_cursor
Definition internal.h:221
return NULL
Definition termdesc.h:229
Here is the call graph for this function:

◆ ncreader_destroy()

void ncreader_destroy ( ncreader n,
char **  contents 
)

Definition at line 17 of file reader.c.

17 {
18 if(n){
19 if(contents){
20 *contents = ncreader_contents(n);
21 }
22 ncreader_destroy_internal(n);
23 }
24}
char * ncreader_contents(const ncreader *n)
Definition reader.c:413
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreader_move_down()

int ncreader_move_down ( ncreader n)

Definition at line 202 of file reader.c.

202 {
203 unsigned y = n->ncp->y;
204 if(y >= n->textarea->leny - 1){
205 // are we on the last row of the textarea? if so, we can't move.
206 return -1;
207 }
208 ++y;
209 ncplane_cursor_move_yx(n->textarea, y, -1);
210 ncplane_cursor_move_yx(n->ncp, y, -1);
211 ncreader_redraw(n);
212 return 0;
213}
int ncplane_cursor_move_yx(ncplane *n, int y, int x)
Definition notcurses.c:720
int y
Definition notcurses.h:1905
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreader_move_left()

int ncreader_move_left ( ncreader n)

Definition at line 115 of file reader.c.

115 {
116 int viewx = n->ncp->x;
117 int textx = n->textarea->x;
118 int y = n->ncp->y;
119//fprintf(stderr, "moving left: tcurs: %dx%d vcurs: %dx%d xproj: %d\n", y, textx, y, viewx, n->xproject);
120 if(textx == 0){
121 // are we on the first column of the textarea? if so, we must also be on
122 // the first column of the viewarea. try to move up.
123 if(y == 0){
124 return -1; // no move possible
125 }
126 viewx = n->ncp->lenx - 1; // FIXME find end of particular row
127 --y;
128 textx = n->textarea->lenx - 1;
129 n->xproject = n->textarea->x - n->ncp->x;
130 }else{
131 // if we're on the first column of the viewarea, but not the first column
132 // of the textarea, we must be able to scroll to the left. do so.
133 // if we're not on the last column anywhere, move cursor right everywhere.
134 if(viewx == 0){
135 --n->xproject;
136 }else{
137 --viewx;
138 }
139 --textx;
140 }
141 ncplane_cursor_move_yx(n->textarea, y, textx);
142 ncplane_cursor_move_yx(n->ncp, y, viewx);
143//fprintf(stderr, "moved left: tcurs: %dx%d vcurs: %dx%d xproj: %d\n", y, textx, y, viewx, n->xproject);
144 ncreader_redraw(n);
145 return 0;
146}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreader_move_right()

int ncreader_move_right ( ncreader n)

Definition at line 152 of file reader.c.

152 {
153 unsigned textx = n->textarea->x;
154 unsigned y = n->ncp->y;
155 unsigned viewx = n->ncp->x;
156//fprintf(stderr, "moving right: tcurs: %dx%d vcurs: %dx%d xproj: %d\n", y, textx, y, viewx, n->xproject);
157 if(textx >= n->textarea->lenx - 1){
158 // are we on the last column of the textarea? if so, we must also be on
159 // the first column of the viewarea. try to move down.
160 if(y >= n->textarea->leny - 1){
161 return -1; // no move possible
162 }
163 viewx = 0;
164 ++y;
165 textx = viewx;
166 n->xproject = 0;
167 }else{
168 // if we're on the first column of the viewarea, but not the first column
169 // of the textarea, we must be able to scroll to the left. do so.
170 // if we're not on the last column anywhere, move cursor right everywhere.
171 if(viewx >= n->ncp->lenx - 1){
172 ++n->xproject;
173 }else{
174 ++viewx;
175 }
176 ++textx;
177 }
178 ncplane_cursor_move_yx(n->textarea, y, textx);
179 ncplane_cursor_move_yx(n->ncp, y, viewx);
180//fprintf(stderr, "moved right: tcurs: %dx%d vcurs: %dx%d xproj: %d\n", y, textx, y, viewx, n->xproject);
181 ncreader_redraw(n);
182 return 0;
183}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreader_move_up()

int ncreader_move_up ( ncreader n)

Definition at line 187 of file reader.c.

187 {
188 int y = n->ncp->y;
189 if(y == 0){
190 // are we on the last row of the textarea? if so, we can't move.
191 return -1;
192 }
193 --y;
194 ncplane_cursor_move_yx(n->textarea, y, -1);
195 ncplane_cursor_move_yx(n->ncp, y, -1);
196 ncreader_redraw(n);
197 return 0;
198}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreader_offer_input()

bool ncreader_offer_input ( ncreader n,
const ncinput ni 
)

Definition at line 371 of file reader.c.

371 {
372 if(ni->evtype == NCTYPE_RELEASE){
373 return false;
374 }
375 if(ncinput_ctrl_p(ni) && !n->no_cmd_keys){
376 return ncreader_ctrl_input(n, ni);
377 }else if(ncinput_alt_p(ni) && !n->no_cmd_keys){
378 return ncreader_alt_input(n, ni);
379 }
380 if(ncinput_alt_p(ni) || ncinput_ctrl_p(ni)){ // pass on all alts/ctrls if no_cmd_keys is set
381 return false;
382 }
383 if(ni->id == NCKEY_BACKSPACE){
384 return do_backspace(n);
385 }
386 // FIXME deal with multicolumn EGCs -- probably extract these and make them
387 // general ncplane_cursor_{left, right, up, down}()
388 if(ni->id == NCKEY_LEFT){
390 return true;
391 }else if(ni->id == NCKEY_RIGHT){
393 return true;
394 }else if(ni->id == NCKEY_UP){
396 return true;
397 }else if(ni->id == NCKEY_DOWN){
399 return true;
400 }else if(nckey_synthesized_p(ni->id)){
401 return false;
402 }
403
404 for (int c=0; ni->eff_text[c]!=0; c++){
405 unsigned char egc[5]={0};
406 if(notcurses_ucs32_to_utf8(&ni->eff_text[c], 1, egc, 4)>=0){
407 ncreader_write_egc(n, (char*)egc);
408 }
409 }
410 return true;
411}
const char * egc
Definition egcpool.h:173
const nccell * c
Definition egcpool.h:296
#define NCKEY_UP
Definition nckeys.h:37
#define NCKEY_BACKSPACE
Definition nckeys.h:43
#define NCKEY_DOWN
Definition nckeys.h:39
#define NCKEY_RIGHT
Definition nckeys.h:38
#define NCKEY_LEFT
Definition nckeys.h:40
int notcurses_ucs32_to_utf8(const uint32_t *ucs32, unsigned ucs32count, unsigned char *resultbuf, size_t buflen)
Definition notcurses.c:3301
@ NCTYPE_RELEASE
Definition notcurses.h:1198
int ncreader_move_up(ncreader *n)
Definition reader.c:187
int ncreader_move_down(ncreader *n)
Definition reader.c:202
int ncreader_write_egc(ncreader *n, const char *egc)
Definition reader.c:216
int ncreader_move_right(ncreader *n)
Definition reader.c:152
int ncreader_move_left(ncreader *n)
Definition reader.c:115
ncintype_e evtype
Definition notcurses.h:1218
uint32_t eff_text[NCINPUT_MAX_EFF_TEXT_CODEPOINTS]
Definition notcurses.h:1221
uint32_t id
Definition notcurses.h:1210
Here is the call graph for this function:

◆ ncreader_plane()

ncplane * ncreader_plane ( ncreader n)

Definition at line 80 of file reader.c.

80 {
81 return n->ncp;
82}
Here is the caller graph for this function:

◆ ncreader_write_egc()

int ncreader_write_egc ( ncreader n,
const char *  egc 
)

Definition at line 216 of file reader.c.

216 {
217 const int cols = ncstrwidth(egc, NULL, NULL);
218 if(cols < 0){
219 logerror("fed illegal UTF-8 [%s]", egc);
220 return -1;
221 }
222 if(n->textarea->x >= n->textarea->lenx - cols){
223 if(n->horscroll){
224 if(ncplane_resize_simple(n->textarea, n->textarea->leny, n->textarea->lenx + cols)){
225 return -1;
226 }
227 ++n->xproject;
228 }
229 }else if(n->ncp->x >= n->ncp->lenx){
230 ++n->xproject;
231 }
232 // use ncplane_putegc on both planes because it'll get cursor movement right
233 if(ncplane_putegc(n->textarea, egc, NULL) < 0){
234 return -1;
235 }
236 if(ncplane_putegc(n->ncp, egc, NULL) < 0){
237 return -1;
238 }
239 if(n->textarea->x >= n->textarea->lenx - cols){
240 if(!n->horscroll){
241 n->textarea->x = n->textarea->lenx - cols;
242 }
243 }
244 if(n->ncp->x >= n->ncp->lenx - cols){
245 n->ncp->x = n->ncp->lenx - cols;
246 }
247 ncreader_redraw(n);
248 return 0;
249}
#define logerror(fmt,...)
Definition logging.h:32
int ncstrwidth(const char *egcs, int *validbytes, int *validwidth)
Definition notcurses.c:3309
Here is the call graph for this function:
Here is the caller graph for this function: