aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tbi
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-11-02 11:41:24 +0300
committerJoursoir <chat@joursoir.net>2021-11-02 11:41:24 +0300
commit896e763d38bb91d3f3c8c5ebc26f431c58933bbc (patch)
treeded5ddc9c2a013c1573d369324ffa77d16058bdd /lib/tbi
parentd4ce900ed5fc6a15b71421d1a65b374366983f9a (diff)
downloadufm-896e763d38bb91d3f3c8c5ebc26f431c58933bbc.tar.gz
ufm-896e763d38bb91d3f3c8c5ebc26f431c58933bbc.tar.bz2
ufm-896e763d38bb91d3f3c8c5ebc26f431c58933bbc.zip
tbi/win: make wvprintf()
Diffstat (limited to 'lib/tbi')
-rw-r--r--lib/tbi/win.c39
-rw-r--r--lib/tbi/win.h13
2 files changed, 52 insertions, 0 deletions
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 <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/ShellLib.h>
+#include <Library/PrintLib.h> // UnicodeVSPrint()
+#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#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 */