con_terminal.hpp
00001 #if !defined(__CON_TERMINAL_HPP__)
00002 #define __CON_TERMINAL_HPP__
00003
00004
00005
00006
00007 #include "core/drivers/serial/con_console.hpp"
00008
00012 struct con_terminal : public con_console
00013 {
00014
00015
00016
00017 typedef uint16_t cursor_t;
00018 static_assert(is_unsigned<cursor_t>::conforms, "cursor_t must be an unsigned integer");
00019
00020 protected:
00021
00022
00023
00024 struct window_state
00025 {
00027 rect_t screen;
00029 rect_t window;
00031 cursor_t cursor_x, cursor_y;
00033 color_t fgcolor, bgcolor;
00034
00035 inline int goto_xy(const cursor_t x=0, const cursor_t y=0)
00036 {
00037 if ((x >= window.w) || (y >= window.h)) return -L4_EINVAL;
00038 cursor_x=x, cursor_y=y;
00039 return 0;
00040 }
00041
00042 inline void cr(void)
00043 {
00044 cursor_x=0;
00045 }
00046
00047 inline bool nl(const bool cr_mode=true)
00048 {
00049 if (cr_mode) cursor_x=0;
00050 if (cursor_y >= window.h-1) return true;
00051 cursor_y++;
00052 return false;
00053 }
00054 } default_state, state;
00055
00056
00057
00058
00059 struct vt100_attributes
00060 {
00061
00062 unsigned bright : 1, dim : 1,
00063 underscore : 1, blink : 1,
00064 reverse : 1, hidden : 1;
00065 signed fgcolor_ix : 4, bgcolor_ix : 4;
00066
00067 inline vt100_attributes(void)
00068 : bright(0), dim(0), underscore(0), blink(0), reverse(0), hidden(0),
00069 fgcolor_ix(-1), bgcolor_ix(-1)
00070 {}
00071 } attributes;
00072
00073 public:
00074
00075
00076
00077 con_terminal(color_t fgcolor=DEFAULT_FGCOLOR, color_t bgcolor=DEFAULT_BGCOLOR,
00078 const rect_t &margins=((rect_t){x: 0, y: 0, w: 0, h: 0}));
00079
00080 inline ~con_terminal(void)
00081 {}
00082
00083 inline int reset(void)
00084 {
00085 if (!is_open()) return -L4_EINVAL;
00086 screen=(state=default_state).screen;
00087 return clear_screen();
00088 }
00089
00090
00091
00092
00093 inline int scroll_screen(const int delta=-1) const
00094 {
00095 return vscroll(default_state.bgcolor, delta * font_height);
00096 }
00097
00098 inline int clear_screen(const cursor_t x=0, const cursor_t y=0,
00099 const cursor_t w=0, const cursor_t h=0) const
00100 {
00101 return fill(default_state.bgcolor, x * font_width, y * font_height,
00102 w * font_width, h * font_height);
00103 }
00104
00105 inline int goto_xy(const cursor_t x=0, const cursor_t y=0)
00106 {
00107 return state.goto_xy(x, y);
00108 }
00109
00110 int print(const char *text);
00111
00112 protected:
00113 int do_print_xy(cursor_t x, cursor_t y, const char *text, int length) const;
00114 int evaluate_escape_sequence(const uint8_t *&esc);
00115 int apply_attributes(const vt100_attributes &attrs=vt100_attributes());
00116 };
00117
00118 #endif
00119
00120
00121