You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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