Home | History | Annotate | Download | only in mucurses
      1 #include <curses.h>
      2 #include <stdio.h>
      3 #include <stddef.h>
      4 #include <gpxe/vsprintf.h>
      5 #include "mucurses.h"
      6 
      7 /** @file
      8  *
      9  * MuCurses printing functions
     10  *
     11  */
     12 
     13 FILE_LICENCE ( GPL2_OR_LATER );
     14 
     15 /**
     16  * Add a single-byte character and rendition to a window and advance
     17  * the cursor
     18  *
     19  * @v *win	window to be rendered in
     20  * @v ch	character to be added at cursor
     21  * @ret rc	return status code
     22  */
     23 int waddch ( WINDOW *win, const chtype ch ) {
     24 	_wputch( win, ch, WRAP );
     25 	return OK;
     26 }
     27 
     28 /**
     29  * Add string of single-byte characters to a window
     30  *
     31  * @v *win	window to be rendered in
     32  * @v *str	standard c-style string
     33  * @v n		max number of chars from string to render
     34  * @ret rc	return status code
     35  */
     36 int waddnstr ( WINDOW *win, const char *str, int n ) {
     37 	_wputstr( win, str, WRAP, n );
     38 	return OK;
     39 }
     40 
     41 struct printw_context {
     42 	struct printf_context ctx;
     43 	WINDOW *win;
     44 };
     45 
     46 static void _printw_handler ( struct printf_context *ctx, unsigned int c ) {
     47 	struct printw_context *wctx =
     48 		container_of ( ctx, struct printw_context, ctx );
     49 
     50 	_wputch( wctx->win, c | wctx->win->attrs, WRAP );
     51 }
     52 
     53 /**
     54  * Print formatted output in a window
     55  *
     56  * @v *win	subject window
     57  * @v *fmt	formatted string
     58  * @v varglist	argument list
     59  * @ret rc	return status code
     60  */
     61 int vw_printw ( WINDOW *win, const char *fmt, va_list varglist ) {
     62 	struct printw_context wctx;
     63 
     64 	wctx.win = win;
     65 	wctx.ctx.handler = _printw_handler;
     66 	vcprintf ( &(wctx.ctx), fmt, varglist );
     67 	return OK;
     68 }
     69 
     70 /**
     71  * Print formatted output to a window
     72  *
     73  * @v *win	subject window
     74  * @v *fmt	formatted string
     75  * @v ...	string arguments
     76  * @ret rc	return status code
     77  */
     78 int wprintw ( WINDOW *win, const char *fmt, ... ) {
     79 	va_list args;
     80 	int i;
     81 
     82 	va_start ( args, fmt );
     83 	i = vw_printw ( win, fmt, args );
     84 	va_end ( args );
     85 	return i;
     86 }
     87