notcurses/include/notcurses.h

91 lines
3.7 KiB
C
Raw Normal View History

2019-11-17 05:04:41 -05:00
#ifndef NOTCURSES_NOTCURSES
#define NOTCURSES_NOTCURSES
2019-11-19 09:10:28 -05:00
#include <stdbool.h>
2019-11-17 05:04:41 -05:00
#ifdef __cplusplus
extern "C" {
#endif
const char* notcurses_version(void);
2019-11-21 06:38:21 -05:00
struct ncplane; // a drawable notcurses surface
struct notcurses; // notcurses state for a given terminal
2019-11-19 09:10:28 -05:00
// Configuration for notcurses_init().
typedef struct notcurses_options {
// The name of the terminfo database entry describing this terminal. If NULL,
// the environment variable TERM is used. Failure to open the terminal
// definition will result in failure to initialize notcurses.
const char* termtype;
// A file descriptor for this terminal on which we will generate output.
// Must be a valid file descriptor attached to a terminal, or notcurses will
// refuse to start. You'll usually want STDOUT_FILENO.
int outfd;
2019-11-19 09:10:28 -05:00
// If smcup/rmcup capabilities are indicated, notcurses defaults to making
2019-11-21 11:00:40 -05:00
// use of the "alternate screen". This flag inhibits use of smcup/rmcup.
2019-11-19 09:10:28 -05:00
bool inhibit_alternate_screen;
} notcurses_options;
2019-11-21 09:06:36 -05:00
// Initialize a notcurses context, corresponding to a connected terminal.
// Returns NULL on error, including any failure to initialize terminfo.
2019-11-19 09:10:28 -05:00
struct notcurses* notcurses_init(const notcurses_options* opts);
// Destroy a notcurses context.
int notcurses_stop(struct notcurses* nc);
2019-11-21 06:38:21 -05:00
// Get a reference to the standard plane (one matching our current idea of the
// terminal size) for this terminal. Invalidated following a call to
// notcurses_resize().
struct ncplane* notcurses_stdplane(struct notcurses* nc);
const struct ncplane* notcurses_stdplane_const(const struct notcurses* nc);
2019-11-18 00:05:32 -05:00
// Make the physical screen match the virtual screen. Changes made to the
// virtual screen (i.e. most other calls) will not be visible until after a
// successful call to notcurses_render().
int notcurses_render(struct notcurses* nc);
2019-11-21 06:38:21 -05:00
// Returns the dimensions of this ncplane.
2019-11-21 08:19:40 -05:00
void ncplane_dimyx(const struct ncplane* n, int* rows, int* cols);
2019-11-21 06:38:21 -05:00
// Return our current idea of the terminal dimensions in rows and cols.
static inline void
2019-11-21 08:19:40 -05:00
notcurses_term_dimyx(const struct notcurses* n, int* rows, int* cols){
ncplane_dimyx(notcurses_stdplane_const(n), rows, cols);
2019-11-21 06:38:21 -05:00
}
// Refresh our idea of the terminal's dimensions, reshaping the standard plane
// if necessary. Without a call to this function following a terminal resize
// (as signaled via SIGWINCH), notcurses_render() might not function properly.
// Following a call to notcurses_resize(), any references to the standard plane
// ought be considered invalidated.
int notcurses_resize(struct notcurses* n);
2019-11-17 09:53:59 -05:00
2019-11-19 09:10:28 -05:00
// Move the cursor to the specified position (the cursor needn't be visible).
// Returns -1 on error, including negative parameters, or ones exceeding the
2019-11-21 06:38:21 -05:00
// plane's dimensions.
2019-11-21 08:19:40 -05:00
int ncplane_movyx(struct ncplane* n, int y, int x);
// Get the current position of the cursor within n. y and/or x may be NULL.
void ncplane_posyx(const struct ncplane* n, int* y, int* x);
// Set the current cell in the specified plane to the provided wchar_t array.
// The array must not be more than one column worth of wchar_t's, among other
// restrictions. Advances the cursor by one cell.
int ncplane_putwc(struct ncplane* n, const wchar_t* wcs);
2019-11-19 09:10:28 -05:00
// Set the current fore/background color using RGB specifications. If the
// terminal does not support directly-specified 3x8b cells (24-bit "Direct
// Color", indicated by the "RGB" terminfo capability), the provided values
// will be interpreted in some lossy fashion. None of r, g, or b may exceed 255.
// "HP-like" terminals require setting foreground and background at the same
// time using "color pairs"; notcurses will manage color pairs transparently.
int ncplane_fg_rgb8(struct ncplane* n, int r, int g, int b);
int ncplane_bg_rgb8(struct ncplane* n, int r, int g, int b);
2019-11-17 05:04:41 -05:00
#ifdef __cplusplus
} // extern "C"
#endif
#endif