2006-06-08 19:23:37 +02:00
|
|
|
#include <curses.h>
|
2007-01-19 02:13:12 +01:00
|
|
|
#include <stdio.h>
|
2006-06-08 19:23:37 +02:00
|
|
|
#include <stddef.h>
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/vsprintf.h>
|
2006-12-18 17:52:21 +01:00
|
|
|
#include "mucurses.h"
|
2006-06-08 19:23:37 +02:00
|
|
|
|
2006-06-21 12:31:20 +02:00
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* MuCurses printing functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-03-02 13:04:57 +01:00
|
|
|
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
2009-05-01 16:41:06 +02:00
|
|
|
|
2006-06-21 12:31:20 +02:00
|
|
|
/**
|
|
|
|
* Add a single-byte character and rendition to a window and advance
|
|
|
|
* the cursor
|
|
|
|
*
|
|
|
|
* @v *win window to be rendered in
|
|
|
|
* @v ch character to be added at cursor
|
|
|
|
* @ret rc return status code
|
|
|
|
*/
|
|
|
|
int waddch ( WINDOW *win, const chtype ch ) {
|
|
|
|
_wputch( win, ch, WRAP );
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add string of single-byte characters to a window
|
|
|
|
*
|
|
|
|
* @v *win window to be rendered in
|
|
|
|
* @v *str standard c-style string
|
|
|
|
* @v n max number of chars from string to render
|
|
|
|
* @ret rc return status code
|
|
|
|
*/
|
|
|
|
int waddnstr ( WINDOW *win, const char *str, int n ) {
|
|
|
|
_wputstr( win, str, WRAP, n );
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct printw_context {
|
2006-06-08 19:23:37 +02:00
|
|
|
struct printf_context ctx;
|
|
|
|
WINDOW *win;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void _printw_handler ( struct printf_context *ctx, unsigned int c ) {
|
|
|
|
struct printw_context *wctx =
|
|
|
|
container_of ( ctx, struct printw_context, ctx );
|
|
|
|
|
|
|
|
_wputch( wctx->win, c | wctx->win->attrs, WRAP );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print formatted output in a window
|
|
|
|
*
|
|
|
|
* @v *win subject window
|
|
|
|
* @v *fmt formatted string
|
|
|
|
* @v varglist argument list
|
|
|
|
* @ret rc return status code
|
|
|
|
*/
|
|
|
|
int vw_printw ( WINDOW *win, const char *fmt, va_list varglist ) {
|
2007-01-05 15:48:20 +01:00
|
|
|
struct printw_context wctx;
|
2006-06-08 19:23:37 +02:00
|
|
|
|
2007-01-05 15:48:20 +01:00
|
|
|
wctx.win = win;
|
|
|
|
wctx.ctx.handler = _printw_handler;
|
2006-06-08 19:23:37 +02:00
|
|
|
vcprintf ( &(wctx.ctx), fmt, varglist );
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print formatted output to a window
|
|
|
|
*
|
|
|
|
* @v *win subject window
|
|
|
|
* @v *fmt formatted string
|
|
|
|
* @v ... string arguments
|
|
|
|
* @ret rc return status code
|
|
|
|
*/
|
|
|
|
int wprintw ( WINDOW *win, const char *fmt, ... ) {
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start ( args, fmt );
|
|
|
|
i = vw_printw ( win, fmt, args );
|
|
|
|
va_end ( args );
|
|
|
|
return i;
|
|
|
|
}
|