From bea8415263dddc1cb892c121446194688703bf27 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Fri, 15 May 2026 07:23:41 -0400 Subject: allow tyui to format text --- teensy/teensy_context.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'teensy/teensy_context.c') diff --git a/teensy/teensy_context.c b/teensy/teensy_context.c index 91b9b90..ad7c79e 100644 --- a/teensy/teensy_context.c +++ b/teensy/teensy_context.c @@ -1,6 +1,7 @@ #include "teensy_context.h" #include +#include #include #include "teensy_platform.h" @@ -99,3 +100,27 @@ void ty_sleep(uint64_t ms) ts.tv_nsec = (ms % 1000) * 1000000; nanosleep(&ts, NULL); } + +char *ty_format_args(const char *fmt, va_list list) +{ + va_list args; + va_copy(args, list); + int len = vsnprintf(NULL, 0, fmt, args); + char *text = ty_talloc(sizeof(char) * (len + 1)); + va_end(args); + + va_copy(args, list); + vsnprintf(text, len + 1, fmt, args); + va_end(args); + + return text; +} + +char *ty_format(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + char *text = ty_format_args(fmt, args); + va_end(args); + return text; +} -- cgit v1.3-2-g0d8e