diff options
author | FreeArtMan <dos21h@gmail.com> | 2016-05-10 22:42:11 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2016-05-10 22:42:11 +0100 |
commit | 44dedb90f005bb0de9bddbd592a5c78f28bc67d1 (patch) | |
tree | 274b9cea44df3f96a965c564e26cdac42d3af94f /libterm | |
parent | bb426577c85f6d97cc28ab677e98e2b1f73eadac (diff) | |
download | ihe-44dedb90f005bb0de9bddbd592a5c78f28bc67d1.tar.gz ihe-44dedb90f005bb0de9bddbd592a5c78f28bc67d1.zip |
Replace cmd first part
Diffstat (limited to 'libterm')
-rw-r--r-- | libterm/debug.h | 69 | ||||
-rw-r--r-- | libterm/screen_modes.h | 15 | ||||
-rw-r--r-- | libterm/term.h | 70 | ||||
-rw-r--r-- | libterm/term_gui.h | 24 | ||||
-rw-r--r-- | libterm/term_io.h | 32 |
5 files changed, 210 insertions, 0 deletions
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 <termios.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include <unistd.h> + +#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 <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <stdint.h> + +#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 |