From 89031dfc49477d282154fbb568d800f700615d4b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 20 Feb 2025 21:31:27 +0100 Subject: m + add libterminput_init and libterminput_destroy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libterminput.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'libterminput.h') diff --git a/libterminput.h b/libterminput.h index ce82ad0..5cd634d 100644 --- a/libterminput.h +++ b/libterminput.h @@ -691,6 +691,46 @@ struct libterminput_unmarshaller { }; +/** + * Initialises the parser + * + * Calling this function is optional + * + * Before calling this function, it is important to call + * `memset(ctx, 0, sizeof(*ctx))` so that `ctx` is properly + * marked as fully uninitialised (this is needed because + * the execution of the function is resumed by calling it + * again after EINTR or EAGAIN failure) + * + * In the current version, this function doesn't do anything, + * however future versions (or other implementations) may + * read to and write from the terminal, read the process's + * environment variables, or read from the filesystem in + * order to detect the particular quirks of the terminal + * + * @param ctx Parser state + * @param fd The file descriptor to the terminal + * @return 0 on success, -1 on failure + * + * It is unspecified which errors will cause this function + * to fail, however it should avoid failing for any other + * reason than EINTR and EAGAIN + * + * @since 1.1 + */ +int libterminput_init(struct libterminput_state *ctx, int fd); + +/** + * Deallocate any resources allocated by `libterminput_init` + * + * `ctx` is no longer usable after this function returns + * + * @param ctx Parser state + * + * @since 1.1 + */ +void libterminput_destroy(struct libterminput_state *ctx); + /** * Get input from the terminal * -- cgit v1.2.3-70-g09d2