Files
mango/include/socks/tty.h
2023-03-20 20:41:39 +00:00

96 lines
3.1 KiB
C

#ifndef SOCKS_TTY_H_
#define SOCKS_TTY_H_
#include <socks/status.h>
#include <socks/queue.h>
#include <stdint.h>
/* The TTY system.
TTYs are an enhanced version of the console object. Rather than a simple output
device for log messages, TTYs are intended to support fully-featured interactive
user sessions, including advanced display manipulation (if applicable) and
buffered user input.
A TTY object is split into 2 parts:
- tty_t: This represents the terminal session, and tracks things like the cursor
position, input buffer, flags, etc.
- tty_driver_t: This is a set of function callbacks that the TTY can use to
manipulate the output device. This could represent a char-based framebuffer
device, a serial port, etc.
*/
#ifdef __cplusplus
extern "C" {
#endif
/* opaque context pointer for use by the tty driver */
typedef void *tty_driver_ctx_t;
typedef enum tty_driver_type {
/* For TTYs operating on simple IO devices like serial ports.
Allows writing characters, receiving characters, and not much else. */
TTY_DRIVER_SIMPLE,
/* For TTYs operating on more capable display interfaces.
Allows putting characters at arbitrary locations, scrolling, etc */
TTY_DRIVER_FULL,
} tty_driver_type_t;
/* TTY cursor status. The extra cursor styles are just for completeness,
the important one to support (if possible), is TTY_CURSOR_NONE.
The others can be interpreted as "just turn on a cursor of any style". */
typedef enum tty_cursor {
TTY_CURSOR_ULINE,
TTY_CURSOR_BLOCK,
TTY_CURSOR_NONE,
} tty_cursor_t;
/* direction to use for scrolling. The important one to support is
TTY_SCROLL_DOWN for when output overflows the display */
typedef enum tty_scroll_dir {
TTY_SCROLL_DOWN,
TTY_SCROLL_UP,
} tty_scroll_dir_t;
/* character attribute. this could be as simple as VGA's 16-colour palette
plus an extra bit for bright, or a full 24-bit RGB value with bold and underline
support, depending on what the driver supports. */
typedef uint64_t tty_attrib_t;
typedef struct tty_driver {
char tty_name[16];
tty_driver_type_t tty_type;
queue_entry_t tty_list;
void (*tty_init)(tty_driver_ctx_t *ctx);
void (*tty_deinit)(tty_driver_ctx_t ctx);
void (*tty_clear)(tty_driver_ctx_t ctx, int x, int y, int width, int height);
void (*tty_putc)(tty_driver_ctx_t ctx, int c, int xpos, int ypos, tty_attrib_t attrib);
void (*tty_set_cursor)(tty_driver_ctx_t ctx, tty_cursor_t cur);
void (*tty_move_cursor)(tty_driver_ctx_t ctx, int x, int y);
void (*tty_scroll)(tty_driver_ctx_t ctx, tty_scroll_dir_t dir, int lines);
} tty_driver_t;
typedef struct tty {
int tty_xcur, tty_ycur;
unsigned int tty_iflag, tty_oflag, tty_lflag;
tty_driver_ctx_t tty_dctx;
const tty_driver_t *tty_driver;
} tty_t;
extern kern_status_t tty_driver_register(tty_driver_t *drv);
extern kern_status_t tty_driver_unregister(tty_driver_t *drv);
extern tty_t *tty_create(void);
extern void tty_destroy(tty_t *tty);
extern int tty_read(tty_t *tty, char *s, unsigned long len);
extern int tty_write(tty_t *tty, const char *s, unsigned long len);
#ifdef __cplusplus
}
#endif
#endif