Selaa lähdekoodia

- fixes to _wputch to get positioning and wrap working properly

- fixes to wborder (same)
- addition of a few minor functions
tags/v0.9.3
Dan Lynch 18 vuotta sitten
vanhempi
commit
f778500739
2 muutettua tiedostoa jossa 74 lisäystä ja 25 poistoa
  1. 44
    7
      src/core/curses.c
  2. 30
    18
      src/include/curses.h

+ 44
- 7
src/core/curses.c Näytä tiedosto

@@ -31,6 +31,7 @@ WINDOW _stdscr = {
31 31
 	.ori_x = 0,
32 32
 	.curs_y = 0,
33 33
 	.curs_x = 0,
34
+	.scr = curscr,
34 35
 };
35 36
 
36 37
 /*
@@ -50,15 +51,15 @@ static void _wputch ( WINDOW *win, chtype ch, int wrap ) {
50 51
 	win->scr->movetoyx( win->scr, win->ori_y + win->curs_y,
51 52
 				      win->ori_x + win->curs_x );
52 53
 	win->scr->putc(win->scr, ch);
53
-	if ( ++(win->curs_x) > win->width ) {
54
+	if ( ++(win->curs_x) == win->width ) {
54 55
 		if ( wrap == WRAP ) {
55 56
 			win->curs_x = 0;
56 57
 			/* specification says we should really scroll,
57 58
 			   but we have no buffer to scroll with, so we
58 59
 			   can only overwrite back at the beginning of
59 60
 			   the window */
60
-			win->curs_y += ( ( win->curs_y - win->height ) == 0 ?
61
-					 -(win->curs_y) : 1 );
61
+			if ( ++(win->curs_y) == win->height )
62
+				win->curs_y = 0;
62 63
 		} else {
63 64
 			(win->curs_x)--;
64 65
 		}
@@ -130,7 +131,10 @@ int wmove ( WINDOW *win, int y, int x ) {
130 131
 		return ERR;
131 132
 	}
132 133
 
133
-	win->scr->movetoyx( win->scr, y, x );
134
+	win->curs_y = y;
135
+	win->curs_x = x;
136
+	win->scr->movetoyx( win->scr, win->ori_y + win->curs_y, 
137
+			    	      win->ori_x + win->curs_x );
134 138
 	return OK;
135 139
 }
136 140
 
@@ -253,6 +257,8 @@ inline chtype getbkgd ( WINDOW *win ) {
253 257
 WINDOW *initscr ( void ) {
254 258
 	/* determine console size */
255 259
 	/* initialise screen */
260
+	stdscr->width = 80;
261
+	stdscr->height = 25;
256 262
 	/* set previously unknown window attributes */
257 263
 	/* refresh screen */
258 264
 	return stdscr;
@@ -274,6 +280,8 @@ WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
274 280
 	win->height = nlines;
275 281
 	win->width = ncols;
276 282
 	win->scr = stdscr->scr;
283
+	win->parent = NULL;
284
+	win->child = NULL;
277 285
 	return win;
278 286
 }
279 287
 
@@ -433,19 +441,19 @@ int wborder ( WINDOW *win, chtype ls, chtype rs,
433 441
 	wmove(win,0,0);
434 442
 
435 443
 	_wputch(win,tl,WRAP);
436
-	while ( win->width - win->curs_x ) {
444
+	while ( ( win->width - 1 ) - win->curs_x ) {
437 445
 		_wputch(win,ts,WRAP);
438 446
 	}
439 447
 	_wputch(win,tr,WRAP);
440 448
 
441 449
 	while ( ( win->height - 1 ) - win->curs_y ) {
442 450
 		_wputch(win,ls,WRAP);
443
-		wmove(win,win->curs_y,win->width-1);
451
+		wmove(win,win->curs_y,(win->width)-1);
444 452
 		_wputch(win,rs,WRAP);
445 453
 	}
446 454
 
447 455
 	_wputch(win,bl,WRAP);
448
-	while ( win->width - win->curs_x ) {
456
+	while ( ( win->width -1 ) - win->curs_x ) {
449 457
 		_wputch(win,bs,WRAP);
450 458
 	}
451 459
 	_wputch(win,br,NOWRAP); /* do not wrap last char to leave
@@ -507,3 +515,32 @@ int wcolour_set ( WINDOW *win, short colour_pair_number, void *opts ) {
507 515
 	return OK;
508 516
 }
509 517
 
518
+/**
519
+ * Delete character under the cursor in a window
520
+ *
521
+ * @v *win	subject window
522
+ * @ret rc	return status code
523
+ */
524
+int wdelch ( WINDOW *win ) {
525
+	struct cursor_pos pos;
526
+
527
+	_store_curs_pos( win, &pos );
528
+	_wputch( win, (unsigned)' ', NOWRAP );
529
+	_restore_curs_pos( win, &pos );
530
+
531
+	return OK;
532
+}
533
+
534
+/**
535
+ * Delete line under a window's cursor
536
+ *
537
+ * @v *win	subject window
538
+ * @ret rc	return status code
539
+ */
540
+int wdeleteln ( WINDOW *win ) {
541
+	/* let's just set the cursor to the beginning of the line and
542
+	   let wclrtoeol do the work :) */
543
+	wmove( win, win->curs_y, 0 );
544
+	wclrtoeol( win );
545
+	return OK;
546
+}

+ 30
- 18
src/include/curses.h Näytä tiedosto

@@ -65,6 +65,8 @@ typedef struct _curses_window {
65 65
 	unsigned int curs_x, curs_y;
66 66
 	/** window dimensions */
67 67
 	unsigned int width, height;
68
+	/** parent/child ptrs */
69
+	struct _curses_window *parent, *child;
68 70
 } WINDOW;
69 71
 
70 72
 extern WINDOW _stdscr;
@@ -289,12 +291,12 @@ extern int curs_set ( int );
289 291
 extern int def_prog_mode ( void );
290 292
 extern int def_shell_mode ( void );
291 293
 extern int delay_output ( int );
292
-extern int delch ( void );
293
-extern int deleteln ( void );
294
+/*extern int delch ( void );*/
295
+/*extern int deleteln ( void );*/
294 296
 extern void delscreen ( SCREEN * ); 
295 297
 extern int delwin ( WINDOW * );
296 298
 extern WINDOW *derwin ( WINDOW *, int, int, int, int );
297
-extern int doupdate ( void );
299
+/*extern int doupdate ( void );*/
298 300
 extern WINDOW *dupwin ( WINDOW * );
299 301
 extern int echo ( void );
300 302
 extern int echochar ( const chtype );
@@ -324,8 +326,6 @@ extern int init_color ( short, short, short, short );
324 326
 extern int init_pair ( short, short, short );
325 327
 extern int innstr ( char *, int );
326 328
 extern int insch ( chtype );
327
-extern int insdelln ( int );
328
-extern int insertln ( void );
329 329
 extern int insnstr ( const char *, int );
330 330
 extern int insstr ( const char * );
331 331
 extern int instr ( char * );
@@ -346,7 +346,7 @@ extern int meta ( WINDOW *, bool );
346 346
 /*extern int mvaddnstr ( int, int, const char *, int );*/
347 347
 /*extern int mvaddstr ( int, int, const char * );*/
348 348
 extern int mvcur ( int, int, int, int );
349
-extern int mvdelch ( int, int );
349
+/*extern int mvdelch ( int, int );*/
350 350
 extern int mvderwin ( WINDOW *, int, int );
351 351
 extern int mvgetch ( int, int );
352 352
 extern int mvgetnstr ( int, int, char *, int );
@@ -368,7 +368,7 @@ extern int mvvline ( int, int, chtype, int );
368 368
 /*extern int mvwaddchstr ( WINDOW *, int, int, const chtype * );*/
369 369
 /*extern int mvwaddnstr ( WINDOW *, int, int, const char *, int );*/
370 370
 /*extern int mvwaddstr ( WINDOW *, int, int, const char * );*/
371
-extern int mvwdelch ( WINDOW *, int, int );
371
+/*extern int mvwdelch ( WINDOW *, int, int );*/
372 372
 extern int mvwgetch ( WINDOW *, int, int );
373 373
 extern int mvwgetnstr ( WINDOW *, int, int, char *, int );
374 374
 extern int mvwgetstr ( WINDOW *, int, int, char * );
@@ -407,21 +407,17 @@ extern int printw ( char *, ... );
407 407
 extern int putp ( const char * );
408 408
 extern void qiflush ( void );
409 409
 extern int raw ( void );
410
-extern int redrawwin ( WINDOW * );
411
-extern int refresh ( void );
410
+/*extern int redrawwin ( WINDOW * );*/
411
+/*extern int refresh ( void );*/
412 412
 extern int reset_prog_mode ( void );
413 413
 extern int reset_shell_mode ( void );
414 414
 extern int resetty ( void );
415 415
 extern int ripoffline ( int, int  ( *) ( WINDOW *, int) );
416 416
 extern int savetty ( void );
417 417
 extern int scanw ( char *, ... );
418
-extern int scr_dump ( const char * );
419
-extern int scr_init ( const char * );
420 418
 extern int scrl ( int );
421 419
 extern int scroll ( WINDOW * );
422 420
 extern int scrollok ( WINDOW *, bool );
423
-extern int scr_restore ( const char * );
424
-extern int scr_set ( const char * );
425 421
 extern int setscrreg ( int, int );
426 422
 extern SCREEN *set_term ( SCREEN * );
427 423
 extern int setupterm ( char *, int, int * );
@@ -503,18 +499,16 @@ extern int winchnstr ( WINDOW *, chtype *, int );
503 499
 extern int winchstr ( WINDOW *, chtype * );
504 500
 extern int winnstr ( WINDOW *, char *, int );
505 501
 extern int winsch ( WINDOW *, chtype );
506
-extern int winsdelln ( WINDOW *, int );
507
-extern int winsertln ( WINDOW * );
508 502
 extern int winsnstr ( WINDOW *, const char *, int );
509 503
 extern int winsstr ( WINDOW *, const char * );
510 504
 extern int winstr ( WINDOW *, char * );
511 505
 extern int wmove ( WINDOW *, int, int );
512 506
 extern int wnoutrefresh ( WINDOW * );
513 507
 extern int wprintw ( WINDOW *, char *, ... );
514
-extern int wredrawln ( WINDOW *, int, int );
515
-extern int wrefresh ( WINDOW * );
508
+/*extern int wredrawln ( WINDOW *, int, int );*/
509
+/*extern int wrefresh ( WINDOW * );*/
516 510
 extern int wscanw ( WINDOW *, char *, ... );
517
-extern int wscrl ( WINDOW *, int );
511
+/*extern int wscrl ( WINDOW *, int );*/
518 512
 extern int wsetscrreg ( WINDOW *, int, int );
519 513
 extern int wstandend ( WINDOW * );
520 514
 extern int wstandout ( WINDOW * );
@@ -580,6 +574,14 @@ static inline int clrtoeol ( void ) {
580 574
 	return wclrtoeol( stdscr );
581 575
 }
582 576
 
577
+static inline int delch ( void ) {
578
+	return wdelch ( stdscr );
579
+}
580
+
581
+static inline int deleteln ( void ) {
582
+	return wdeleteln( stdscr );
583
+}
584
+
583 585
 static inline int move ( int y, int x ) {
584 586
 	return wmove ( stdscr, y, x );
585 587
 }
@@ -609,6 +611,11 @@ static inline int mvaddstr ( int y, int x, const char *str ) {
609 611
 		 ? ERR : waddnstr ( stdscr, str, -1 ) );
610 612
 }
611 613
 
614
+static inline int mvdelch ( int y, int x ) {
615
+	return ( wmove ( stdscr, y, x ) == ERR
616
+		 ? ERR : wdelch ( stdscr ) );
617
+}
618
+
612 619
 static inline int mvwaddch ( WINDOW *win, int y, int x, const chtype ch ) {
613 620
 	return ( wmove( win, y, x ) == ERR 
614 621
 		 ? ERR : waddch ( win, ch ) );
@@ -634,6 +641,11 @@ static inline int mvwaddstr ( WINDOW *win, int y, int x, const char *str ) {
634 641
 		 ? ERR : waddnstr ( win, str, -1 ) );
635 642
 }
636 643
 
644
+static inline int mvwdelch ( WINDOW *win, int y, int x ) {
645
+	return ( wmove ( win, y, x ) == ERR
646
+		 ? ERR : wdelch ( win ) );
647
+}
648
+
637 649
 static inline int waddchstr ( WINDOW *win, const chtype *chstr ) {
638 650
 	return waddchnstr ( win, chstr, -1 );
639 651
 }

Loading…
Peruuta
Tallenna