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.

print.c 1.7KB

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