From b1a2c69aea376eeae6854575396a35a75556c5ab Mon Sep 17 00:00:00 2001 From: mintsuki Date: Fri, 7 Jul 2023 18:25:04 +0200 Subject: [PATCH] Add flanterm_fb_simple_init() and add basic usage to README --- README | 5 ----- README.md | 29 +++++++++++++++++++++++++++++ backends/fb.h | 21 +++++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 04e8c80..0000000 --- a/README +++ /dev/null @@ -1,5 +0,0 @@ -Flanterm -======== - -Flanterm is a fast and reasonably complete terminal emulator with support for -multiple output backends. Included is a fast framebuffer backend. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3a5294 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Flanterm + +Flanterm is a fast and reasonably complete terminal emulator with support for +multiple output backends. Included is a fast framebuffer backend. + +### Quick usage + +To quickly set up and use a framebuffer Flanterm instance, it is possible to +use the `flanterm_fb_simple_init()` function as such: +```c +#include +#include + +struct flanterm_context *ft_ctx = flanterm_fb_simple_init( + framebuffer_ptr, framebuffer_width, framebuffer_height, framebuffer_pitch +); +``` +Where `framebuffer_{ptr,width,height,pitch}` represent the corresponding info +about the framebuffer to use for this given instance. + +To then print to the terminal instance, simply use the `flanterm_write()` +function on the given instance. For example: +```c +#include + +const char msg[] = "Hello world\n"; + +flanterm_write(ft_ctx, msg, sizeof(msg)); +``` diff --git a/backends/fb.h b/backends/fb.h index a4135dd..6741e04 100644 --- a/backends/fb.h +++ b/backends/fb.h @@ -123,6 +123,27 @@ struct flanterm_context *flanterm_fb_init( size_t margin ); +#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC +static inline struct flanterm_context *flanterm_fb_simple_init( + uint32_t *framebuffer, size_t width, size_t height, size_t pitch +) { + return flanterm_fb_init( + NULL, + NULL, + framebuffer, width, height, pitch, +#ifndef FLANTERM_FB_DISABLE_CANVAS + NULL, +#endif + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, 0, 0, 1, + 1, 1, + 0 + ); +} +#endif + #ifdef __cplusplus } #endif