From 896e763d38bb91d3f3c8c5ebc26f431c58933bbc Mon Sep 17 00:00:00 2001 From: Joursoir Date: Tue, 2 Nov 2021 11:41:24 +0300 Subject: tbi/win: make wvprintf() --- lib/tbi/win.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/tbi/win.h | 13 +++++++++++++ 2 files changed, 52 insertions(+) (limited to 'lib/tbi') diff --git a/lib/tbi/win.c b/lib/tbi/win.c index 3486c7a..f3f25a3 100644 --- a/lib/tbi/win.c +++ b/lib/tbi/win.c @@ -2,6 +2,8 @@ #include #include #include +#include // UnicodeVSPrint() +#include #include #include "screen.h" @@ -186,3 +188,40 @@ BOOLEAN mvwvline(struct window *w, INT32 x, INT32 y, CHAR16 ch, INT32 n) return TRUE; } +UINTN EFIAPI wvprintf(struct window *w, CONST CHAR16 *fmt, VA_LIST args) +{ + INT32 x, y; + UINTN i, length, max_length, walker_size; + CHAR16 *fmt_walker; + + ASSERT(w != NULL); + ASSERT(fmt != NULL); + + x = w->curx; + y = w->cury; + + walker_size = w->width * sizeof(CHAR16); + fmt_walker = AllocateZeroPool(walker_size); + if(!fmt_walker) + return 0; + + UnicodeVSPrint(fmt_walker, walker_size, fmt, args); + length = StrLen(fmt_walker); + max_length = w->width - x; + if(length >= max_length) { + length = max_length; + + w->curx = 0; + if(++w->cury >= w->height) + w->cury = 0; + } + else + w->curx += length; + + CopyMem(w->text[y] + x, fmt_walker, length * 2); // multiply by 2 because CHAR16 + for(i = 0; i < length; i++) + w->attr[y][x + i] = w->cur_attr; + FreePool(fmt_walker); + return length; +} + diff --git a/lib/tbi/win.h b/lib/tbi/win.h index 404cdd1..18f0153 100644 --- a/lib/tbi/win.h +++ b/lib/tbi/win.h @@ -133,4 +133,17 @@ BOOLEAN mvwhline(struct window *w, INT32 x, INT32 y, CHAR16 ch, INT32 n); */ BOOLEAN mvwvline(struct window *w, INT32 x, INT32 y, CHAR16 ch, INT32 n); +/* + * Prints output based on a null-terminated unicode format string + and a arguments list + * + * w: the window on which to operate + * fmt: a null-terminated unicode format string + * arg: the variable argument list + * + * return: the number of unicode chars in the produced output buffer + not including the null-terminator +*/ +UINTN EFIAPI wvprintf(struct window *w, CONST CHAR16 *fmt, VA_LIST args); + #endif /* UFM_TBI_WINDOW_H */ -- cgit v1.2.3-18-g5258