From 44dedb90f005bb0de9bddbd592a5c78f28bc67d1 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Tue, 10 May 2016 22:42:11 +0100 Subject: Replace cmd first part --- libterm/debug.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ libterm/screen_modes.h | 15 +++++++++++ libterm/term.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ libterm/term_gui.h | 24 +++++++++++++++++ libterm/term_io.h | 32 +++++++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 libterm/debug.h create mode 100644 libterm/screen_modes.h create mode 100644 libterm/term.h create mode 100644 libterm/term_gui.h create mode 100644 libterm/term_io.h (limited to 'libterm') diff --git a/libterm/debug.h b/libterm/debug.h new file mode 100644 index 0000000..a79ea77 --- /dev/null +++ b/libterm/debug.h @@ -0,0 +1,69 @@ +#ifndef __LIBTERM_DEBUG_UTILS_H +#define __LIBTERM_DEBUG_UTILS_H + +//what about kprintf? + +//config options +#define PRINTF printf +#define COLORIZE +#define PRINT_LINENUM +#define PRINT_FILENAME +#define PRINT_DEBUG + + +//use color +#ifdef COLORIZE + #define D_COLOR "1;32m" + #define D_COLOR_S "\033[" D_COLOR + #define D_COLOR_E "\033[0m" + #define E_COLOR "1;31m" + #define E_COLOR_S "\033[" E_COLOR + #define E_COLOR_E "\033[0m" +#else + #define D_COLOR + #define D_COLOR_S + #define D_COLOR_E + #define E_COLOR + #define E_COLOR_S + #define E_COLOR_E +#endif + +//print debug line +#ifdef PRINT_LINENUM + #define PRINT_LINE_F "LINE:%d " + #define PRINT_LINE_D __LINE__ +#else + #define PRINT_LINE_F "" + #define PRINT_LINE_D "" +#endif + +//print +#ifdef PRINT_FILENAME + #define PRINT_FILE_F "FILE:%s " + #define PRINT_FILE_D __FILE__ +#else + #define PRINT_FILE_F "" + #define PRINT_FILE_D "" +#endif + +//print debug string +#ifdef PRINT_DEBUG + #define PRINT_DEBUG_F "Debug: " +#else + #define PRINT_DEBUG_F "" +#endif + +#define PRINT( format, args ... ) PRINTF( D_COLOR_S PRINT_DEBUG_F \ + PRINT_FILE_F PRINT_LINE_F format D_COLOR_E, PRINT_FILE_D, \ + PRINT_LINE_D, ##args); + +#define ERROR( format, args ... ) PRINTF( E_COLOR_S PRINT_DEBUG_F \ + PRINT_FILE_F PRINT_LINE_F format E_COLOR_E, PRINT_FILE_D, \ + PRINT_LINE_D, ##args); + +#define PNL() PRINT("\n"); + +#define ENL() ERROR("\n"); + + +#endif diff --git a/libterm/screen_modes.h b/libterm/screen_modes.h new file mode 100644 index 0000000..261cbf5 --- /dev/null +++ b/libterm/screen_modes.h @@ -0,0 +1,15 @@ +#ifndef __LIBTERM_SCREEN_MODES_H +#define __LIBTERM_SCREEN_MODES_H + +typedef enum +{ + SCREEN_MODE_NONE=0, + SCREEN_MODE_80x25 +} screen_mode_e; + +typedef struct term_screen_mode +{ + screen_mode_e mode; +} term_screen_mode; + +#endif diff --git a/libterm/term.h b/libterm/term.h new file mode 100644 index 0000000..df3d7b1 --- /dev/null +++ b/libterm/term.h @@ -0,0 +1,70 @@ +#ifndef __LIBTERM_TERM_H +#define __LIBTERM_TERM_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "screen_modes.h" +#include "debug.h" + +enum TERM_KEY_ACTION { + KEY_NULL = 0, /* NULL */ + CTRL_A = 1, /* Ctrl+a */ + CTRL_B = 2, /* Ctrl-b */ + CTRL_C = 3, /* Ctrl-c */ + CTRL_D = 4, /* Ctrl-d */ + CTRL_E = 5, /* Ctrl-e */ + CTRL_F = 6, /* Ctrl-f */ + CTRL_H = 8, /* Ctrl-h */ + TAB = 9, /* Tab */ + CTRL_K = 11, /* Ctrl+k */ + CTRL_L = 12, /* Ctrl+l */ + ENTER = 13, /* Enter */ + CTRL_N = 14, /* Ctrl-n */ + CTRL_P = 16, /* Ctrl-p */ + CTRL_T = 20, /* Ctrl-t */ + CTRL_U = 21, /* Ctrl+u */ + CTRL_W = 23, /* Ctrl+w */ + ESC = 27, /* Escape */ + QMARK = 63, /* ? */ + BACKSPACE = 127 /* Backspace */ +}; + + +#define TK_ENTER 13 +#define TK_ESC 27 +#define TK_BACKSPACE 8 + +typedef struct term_screen +{ + int ifd, ofd; + struct termios orig_i, orig_o; + struct termios raw_i, raw_o; + screen_mode_e mode; +} term_screen; + +int term_init( term_screen *ts ); +int term_set_speed( term_screen *ts, speed_t speed); +int term_get_maxcol( term_screen *ts ); +int term_get_maxrow( term_screen *ts ); +int term_cur_get_c( term_screen *ts ); +int term_cur_get_r( term_screen *ts ); +int term_cur_set_c( term_screen *ts, unsigned int pc ); +int term_cur_set_r( term_screen *ts, unsigned int pr ); +int term_cur_set_cr( term_screen *ts, unsigned int pc , unsigned int pr ); +int term_clr_scr( term_screen *ts ); +int term_set_raw_mode( term_screen *ts ); +int term_mode_rows( term_screen *ts ); +int term_mode_columns( term_screen *ts ); +void term_set_orig_mode( term_screen *ts ); + +#endif diff --git a/libterm/term_gui.h b/libterm/term_gui.h new file mode 100644 index 0000000..408382e --- /dev/null +++ b/libterm/term_gui.h @@ -0,0 +1,24 @@ +#ifndef __LIBTERM_TERM_GUI_H +#define __LIBTERM_TERM_GUI_H + +#include "term.h" +#include "term_io.h" + +typedef struct term_gui +{ + term_screen *ts; + int w; + int h; + int abs_x; + int abs_y; +} term_gui; + +int term_gui_init( term_gui *tg, term_screen *ts ); +int term_set_wh( term_screen *tg, int width, int height ); +int term_gui_input_box( term_gui *ts, int x, int y, int w, int h, char *prompt, + char *str, size_t sz ); +int term_gui_draw( term_gui *tg ); +int term_gui_destroy( term_gui *tg ); + + +#endif \ No newline at end of file diff --git a/libterm/term_io.h b/libterm/term_io.h new file mode 100644 index 0000000..48deb67 --- /dev/null +++ b/libterm/term_io.h @@ -0,0 +1,32 @@ +#ifndef __LIBTERM_PRINT_UTILS_H +#define __LIBTERM_PRINT_UTILS_H + +#include +#include +#include +#include + +#include "screen_modes.h" +#include "term.h" + +#define READLINE_NONE 0 //none +#define READLINE_ALPHA 1 //isalpsha +#define READLINE_TEXT 2 //[a-zA-Z0-9] + ispunct +#define READLINE_HIDDEN 3 //[a-zA-Z] +#define READLINE_NUMBER 4 //[0-9] +#define READLINE_SYMBOL 5 //not yet +#define READLINE_ALPHANUM 6 //not yet + + +int term_fprint( screen_mode_e mode, FILE *f ); +int term_print( term_screen *ts, const char *s, size_t n ); +int term_print_xy( term_screen *ts, const char *buf, size_t size, + int init_column, int init_row); +int term_draw_hline( term_screen *ts, int pc, int pr, int sz, char ch ); +int term_getc( term_screen *ts ); +int64_t term_getb( term_screen *ts ); +int term_putc( term_screen *ts, char c ); +int term_readline( term_screen *ts, char *str, size_t str_size, int flag ); +int term_printf( term_screen *ts, const char *format, ...); + +#endif -- cgit v1.2.3