Add flanterm_fb_simple_init() and add basic usage to README

This commit is contained in:
mintsuki 2023-07-07 18:25:04 +02:00
parent 63359f43d4
commit b1a2c69aea
3 changed files with 50 additions and 5 deletions

5
README
View File

@ -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.

29
README.md Normal file
View File

@ -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 <flanterm/flanterm.h>
#include <flanterm/backends/fb.h>
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 <flanterm/flanterm.h>
const char msg[] = "Hello world\n";
flanterm_write(ft_ctx, msg, sizeof(msg));
```

View File

@ -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