Browse Source

- 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 years ago
parent
commit
f778500739
2 changed files with 74 additions and 25 deletions
  1. 44
    7
      src/core/curses.c
  2. 30
    18
      src/include/curses.h

+ 44
- 7
src/core/curses.c View File

31
 	.ori_x = 0,
31
 	.ori_x = 0,
32
 	.curs_y = 0,
32
 	.curs_y = 0,
33
 	.curs_x = 0,
33
 	.curs_x = 0,
34
+	.scr = curscr,
34
 };
35
 };
35
 
36
 
36
 /*
37
 /*
50
 	win->scr->movetoyx( win->scr, win->ori_y + win->curs_y,
51
 	win->scr->movetoyx( win->scr, win->ori_y + win->curs_y,
51
 				      win->ori_x + win->curs_x );
52
 				      win->ori_x + win->curs_x );
52
 	win->scr->putc(win->scr, ch);
53
 	win->scr->putc(win->scr, ch);
53
-	if ( ++(win->curs_x) > win->width ) {
54
+	if ( ++(win->curs_x) == win->width ) {
54
 		if ( wrap == WRAP ) {
55
 		if ( wrap == WRAP ) {
55
 			win->curs_x = 0;
56
 			win->curs_x = 0;
56
 			/* specification says we should really scroll,
57
 			/* specification says we should really scroll,
57
 			   but we have no buffer to scroll with, so we
58
 			   but we have no buffer to scroll with, so we
58
 			   can only overwrite back at the beginning of
59
 			   can only overwrite back at the beginning of
59
 			   the window */
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
 		} else {
63
 		} else {
63
 			(win->curs_x)--;
64
 			(win->curs_x)--;
64
 		}
65
 		}
130
 		return ERR;
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
 	return OK;
138
 	return OK;
135
 }
139
 }
136
 
140
 
253
 WINDOW *initscr ( void ) {
257
 WINDOW *initscr ( void ) {
254
 	/* determine console size */
258
 	/* determine console size */
255
 	/* initialise screen */
259
 	/* initialise screen */
260
+	stdscr->width = 80;
261
+	stdscr->height = 25;
256
 	/* set previously unknown window attributes */
262
 	/* set previously unknown window attributes */
257
 	/* refresh screen */
263
 	/* refresh screen */
258
 	return stdscr;
264
 	return stdscr;
274
 	win->height = nlines;
280
 	win->height = nlines;
275
 	win->width = ncols;
281
 	win->width = ncols;
276
 	win->scr = stdscr->scr;
282
 	win->scr = stdscr->scr;
283
+	win->parent = NULL;
284
+	win->child = NULL;
277
 	return win;
285
 	return win;
278
 }
286
 }
279
 
287
 
433
 	wmove(win,0,0);
441
 	wmove(win,0,0);
434
 
442
 
435
 	_wputch(win,tl,WRAP);
443
 	_wputch(win,tl,WRAP);
436
-	while ( win->width - win->curs_x ) {
444
+	while ( ( win->width - 1 ) - win->curs_x ) {
437
 		_wputch(win,ts,WRAP);
445
 		_wputch(win,ts,WRAP);
438
 	}
446
 	}
439
 	_wputch(win,tr,WRAP);
447
 	_wputch(win,tr,WRAP);
440
 
448
 
441
 	while ( ( win->height - 1 ) - win->curs_y ) {
449
 	while ( ( win->height - 1 ) - win->curs_y ) {
442
 		_wputch(win,ls,WRAP);
450
 		_wputch(win,ls,WRAP);
443
-		wmove(win,win->curs_y,win->width-1);
451
+		wmove(win,win->curs_y,(win->width)-1);
444
 		_wputch(win,rs,WRAP);
452
 		_wputch(win,rs,WRAP);
445
 	}
453
 	}
446
 
454
 
447
 	_wputch(win,bl,WRAP);
455
 	_wputch(win,bl,WRAP);
448
-	while ( win->width - win->curs_x ) {
456
+	while ( ( win->width -1 ) - win->curs_x ) {
449
 		_wputch(win,bs,WRAP);
457
 		_wputch(win,bs,WRAP);
450
 	}
458
 	}
451
 	_wputch(win,br,NOWRAP); /* do not wrap last char to leave
459
 	_wputch(win,br,NOWRAP); /* do not wrap last char to leave
507
 	return OK;
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 View File

65
 	unsigned int curs_x, curs_y;
65
 	unsigned int curs_x, curs_y;
66
 	/** window dimensions */
66
 	/** window dimensions */
67
 	unsigned int width, height;
67
 	unsigned int width, height;
68
+	/** parent/child ptrs */
69
+	struct _curses_window *parent, *child;
68
 } WINDOW;
70
 } WINDOW;
69
 
71
 
70
 extern WINDOW _stdscr;
72
 extern WINDOW _stdscr;
289
 extern int def_prog_mode ( void );
291
 extern int def_prog_mode ( void );
290
 extern int def_shell_mode ( void );
292
 extern int def_shell_mode ( void );
291
 extern int delay_output ( int );
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
 extern void delscreen ( SCREEN * ); 
296
 extern void delscreen ( SCREEN * ); 
295
 extern int delwin ( WINDOW * );
297
 extern int delwin ( WINDOW * );
296
 extern WINDOW *derwin ( WINDOW *, int, int, int, int );
298
 extern WINDOW *derwin ( WINDOW *, int, int, int, int );
297
-extern int doupdate ( void );
299
+/*extern int doupdate ( void );*/
298
 extern WINDOW *dupwin ( WINDOW * );
300
 extern WINDOW *dupwin ( WINDOW * );
299
 extern int echo ( void );
301
 extern int echo ( void );
300
 extern int echochar ( const chtype );
302
 extern int echochar ( const chtype );
324
 extern int init_pair ( short, short, short );
326
 extern int init_pair ( short, short, short );
325
 extern int innstr ( char *, int );
327
 extern int innstr ( char *, int );
326
 extern int insch ( chtype );
328
 extern int insch ( chtype );
327
-extern int insdelln ( int );
328
-extern int insertln ( void );
329
 extern int insnstr ( const char *, int );
329
 extern int insnstr ( const char *, int );
330
 extern int insstr ( const char * );
330
 extern int insstr ( const char * );
331
 extern int instr ( char * );
331
 extern int instr ( char * );
346
 /*extern int mvaddnstr ( int, int, const char *, int );*/
346
 /*extern int mvaddnstr ( int, int, const char *, int );*/
347
 /*extern int mvaddstr ( int, int, const char * );*/
347
 /*extern int mvaddstr ( int, int, const char * );*/
348
 extern int mvcur ( int, int, int, int );
348
 extern int mvcur ( int, int, int, int );
349
-extern int mvdelch ( int, int );
349
+/*extern int mvdelch ( int, int );*/
350
 extern int mvderwin ( WINDOW *, int, int );
350
 extern int mvderwin ( WINDOW *, int, int );
351
 extern int mvgetch ( int, int );
351
 extern int mvgetch ( int, int );
352
 extern int mvgetnstr ( int, int, char *, int );
352
 extern int mvgetnstr ( int, int, char *, int );
368
 /*extern int mvwaddchstr ( WINDOW *, int, int, const chtype * );*/
368
 /*extern int mvwaddchstr ( WINDOW *, int, int, const chtype * );*/
369
 /*extern int mvwaddnstr ( WINDOW *, int, int, const char *, int );*/
369
 /*extern int mvwaddnstr ( WINDOW *, int, int, const char *, int );*/
370
 /*extern int mvwaddstr ( WINDOW *, int, int, const char * );*/
370
 /*extern int mvwaddstr ( WINDOW *, int, int, const char * );*/
371
-extern int mvwdelch ( WINDOW *, int, int );
371
+/*extern int mvwdelch ( WINDOW *, int, int );*/
372
 extern int mvwgetch ( WINDOW *, int, int );
372
 extern int mvwgetch ( WINDOW *, int, int );
373
 extern int mvwgetnstr ( WINDOW *, int, int, char *, int );
373
 extern int mvwgetnstr ( WINDOW *, int, int, char *, int );
374
 extern int mvwgetstr ( WINDOW *, int, int, char * );
374
 extern int mvwgetstr ( WINDOW *, int, int, char * );
407
 extern int putp ( const char * );
407
 extern int putp ( const char * );
408
 extern void qiflush ( void );
408
 extern void qiflush ( void );
409
 extern int raw ( void );
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
 extern int reset_prog_mode ( void );
412
 extern int reset_prog_mode ( void );
413
 extern int reset_shell_mode ( void );
413
 extern int reset_shell_mode ( void );
414
 extern int resetty ( void );
414
 extern int resetty ( void );
415
 extern int ripoffline ( int, int  ( *) ( WINDOW *, int) );
415
 extern int ripoffline ( int, int  ( *) ( WINDOW *, int) );
416
 extern int savetty ( void );
416
 extern int savetty ( void );
417
 extern int scanw ( char *, ... );
417
 extern int scanw ( char *, ... );
418
-extern int scr_dump ( const char * );
419
-extern int scr_init ( const char * );
420
 extern int scrl ( int );
418
 extern int scrl ( int );
421
 extern int scroll ( WINDOW * );
419
 extern int scroll ( WINDOW * );
422
 extern int scrollok ( WINDOW *, bool );
420
 extern int scrollok ( WINDOW *, bool );
423
-extern int scr_restore ( const char * );
424
-extern int scr_set ( const char * );
425
 extern int setscrreg ( int, int );
421
 extern int setscrreg ( int, int );
426
 extern SCREEN *set_term ( SCREEN * );
422
 extern SCREEN *set_term ( SCREEN * );
427
 extern int setupterm ( char *, int, int * );
423
 extern int setupterm ( char *, int, int * );
503
 extern int winchstr ( WINDOW *, chtype * );
499
 extern int winchstr ( WINDOW *, chtype * );
504
 extern int winnstr ( WINDOW *, char *, int );
500
 extern int winnstr ( WINDOW *, char *, int );
505
 extern int winsch ( WINDOW *, chtype );
501
 extern int winsch ( WINDOW *, chtype );
506
-extern int winsdelln ( WINDOW *, int );
507
-extern int winsertln ( WINDOW * );
508
 extern int winsnstr ( WINDOW *, const char *, int );
502
 extern int winsnstr ( WINDOW *, const char *, int );
509
 extern int winsstr ( WINDOW *, const char * );
503
 extern int winsstr ( WINDOW *, const char * );
510
 extern int winstr ( WINDOW *, char * );
504
 extern int winstr ( WINDOW *, char * );
511
 extern int wmove ( WINDOW *, int, int );
505
 extern int wmove ( WINDOW *, int, int );
512
 extern int wnoutrefresh ( WINDOW * );
506
 extern int wnoutrefresh ( WINDOW * );
513
 extern int wprintw ( WINDOW *, char *, ... );
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
 extern int wscanw ( WINDOW *, char *, ... );
510
 extern int wscanw ( WINDOW *, char *, ... );
517
-extern int wscrl ( WINDOW *, int );
511
+/*extern int wscrl ( WINDOW *, int );*/
518
 extern int wsetscrreg ( WINDOW *, int, int );
512
 extern int wsetscrreg ( WINDOW *, int, int );
519
 extern int wstandend ( WINDOW * );
513
 extern int wstandend ( WINDOW * );
520
 extern int wstandout ( WINDOW * );
514
 extern int wstandout ( WINDOW * );
580
 	return wclrtoeol( stdscr );
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
 static inline int move ( int y, int x ) {
585
 static inline int move ( int y, int x ) {
584
 	return wmove ( stdscr, y, x );
586
 	return wmove ( stdscr, y, x );
585
 }
587
 }
609
 		 ? ERR : waddnstr ( stdscr, str, -1 ) );
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
 static inline int mvwaddch ( WINDOW *win, int y, int x, const chtype ch ) {
619
 static inline int mvwaddch ( WINDOW *win, int y, int x, const chtype ch ) {
613
 	return ( wmove( win, y, x ) == ERR 
620
 	return ( wmove( win, y, x ) == ERR 
614
 		 ? ERR : waddch ( win, ch ) );
621
 		 ? ERR : waddch ( win, ch ) );
634
 		 ? ERR : waddnstr ( win, str, -1 ) );
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
 static inline int waddchstr ( WINDOW *win, const chtype *chstr ) {
649
 static inline int waddchstr ( WINDOW *win, const chtype *chstr ) {
638
 	return waddchnstr ( win, chstr, -1 );
650
 	return waddchnstr ( win, chstr, -1 );
639
 }
651
 }

Loading…
Cancel
Save