Files
mango/include/socks/tty.h

99 lines
3.1 KiB
C

#ifndef SOCKS_TTY_H_
#define SOCKS_TTY_H_
#include <socks/status.h>
#include <socks/queue.h>
#include <socks/object.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:
- struct tty: This represents the terminal session, and tracks things like the cursor
position, input buffer, flags, etc.
- struct tty_driver: 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;
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 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". */
enum tty_cursor {
TTY_CURSOR_ULINE,
TTY_CURSOR_BLOCK,
TTY_CURSOR_NONE,
};
/* direction to use for scrolling. The important one to support is
TTY_SCROLL_DOWN for when output overflows the display */
enum tty_scroll_dir {
TTY_SCROLL_DOWN,
TTY_SCROLL_UP,
};
/* 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;
struct tty_driver {
struct object tty_base;
char tty_name[16];
enum tty_driver_type tty_type;
struct queue_entry 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, enum tty_cursor cur);
void (*tty_move_cursor)(tty_driver_ctx_t ctx, int x, int y);
void (*tty_scroll)(tty_driver_ctx_t ctx, enum tty_scroll_dir dir, int lines);
};
struct tty {
int tty_xcur, tty_ycur;
unsigned int tty_iflag, tty_oflag, tty_lflag;
tty_driver_ctx_t tty_dctx;
const struct tty_driver *tty_driver;
};
extern kern_status_t tty_driver_register(struct tty_driver *drv);
extern kern_status_t tty_driver_unregister(struct tty_driver *drv);
extern struct tty *tty_create(void);
extern void tty_destroy(struct tty *tty);
extern int tty_read(struct tty *tty, char *s, unsigned long len);
extern int tty_write(struct tty *tty, const char *s, unsigned long len);
#ifdef __cplusplus
}
#endif
#endif