source: trunk/tools/neercs/term/term.h @ 2216

Last change on this file since 2216 was 2020, checked in by sam, 8 years ago

neercs: F3 toggles fancy shit drawing.

File size: 4.3 KB
Line 
1//
2// Neercs
3//
4
5#if !defined __TERM_TERM_H__
6#define __TERM_TERM_H__
7
8#include "term/pty.h"
9
10struct Iso2022Conversion
11{
12    Iso2022Conversion() { Reset(); }
13    void Reset();
14
15    /* cs = coding system/coding method: */
16    /* (with standard return) */
17    /* '@' = ISO-2022, */
18    /* 'G' = UTF-8 without implementation level, */
19    /* '8' = UTF-8 (Linux console and imitators), */
20    /* and many others that are rarely used; */
21    /* (without standard return) */
22    /* '/G' = UTF-8 Level 1, */
23    /* '/H' = UTF-8 Level 2, */
24    /* '/I' = UTF-8 Level 3, */
25    /* and many others that are rarely used */
26    uint32_t cs;
27    /* ctrl8bit = allow 8-bit controls */
28    uint8_t ctrl8bit;
29    /* cn[0] = C0 control charset (0x00 ... 0x1f):
30     * '@' = ISO 646,
31     * '~' = empty,
32     * and many others that are rarely used */
33    /* cn[1] = C1 control charset (0x80 ... 0x9f):
34     * 'C' = ISO 6429-1983,
35     * '~' = empty,
36     * and many others that are rarely used */
37    uint32_t cn[2];
38    /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e,
39     *                              94x94-char. 0x21/0x21 ... 0x7e/0x7e),
40     * and
41     * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe,
42     *                              96-char. 0xa0 ... 0xff,
43     *                              94x94-char. 0xa1/0xa1 ... 0xfe/0xfe,
44     *                              96x96-char. 0xa0/0xa0 ... 0xff/0xff):
45     * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */
46    uint8_t glr[2];
47    /* gn[i] = G0/G1/G2/G3 graphic charset state:
48     * (94-char. sets)
49     * '0' = DEC ACS (VT100 and imitators),
50     * 'B' = US-ASCII,
51     * and many others that are rarely used for e.g. various national ASCII variations;
52     * (96-char. sets)
53     * '.A' = ISO 8859-1 "Latin 1" GR,
54     * '.~' = empty 96-char. set,
55     * and many others that are rarely used for e.g. ISO 8859-n GR;
56     * (double-byte 94x94-charsets)
57     * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978),
58     * '$A' = Chinese Character Set (GB 2312),
59     * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983),
60     * '$C' = Korean Graphic Character Set (KSC 5601:1987),
61     * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212),
62     * '$E' = CCITT Chinese Set (GB 2312 + GB 8565),
63     * '$G' = CNS 11643 plane 1,
64     * '$H' = CNS 11643 plane 2,
65     * '$I' = CNS 11643 plane 3,
66     * '$J' = CNS 11643 plane 4,
67     * '$K' = CNS 11643 plane 5,
68     * '$L' = CNS 11643 plane 6,
69     * '$M' = CNS 11643 plane 7,
70     * '$O' = JIS X 0213 plane 1,
71     * '$P' = JIS X 0213 plane 2,
72     * '$Q' = JIS X 0213-2004 Plane 1,
73     * and many others that are rarely used for e.g. traditional
74     * ideographic Vietnamese and BlissSymbolics;
75     * (double-byte 96x96-charsets)
76     * none standardized or in use on terminals AFAIK (Mule does use
77     * some internally)
78     */
79    uint32_t gn[4];
80    /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */
81    uint8_t ss;
82};
83
84class Term : public Entity
85{
86public:
87    Term(ivec2 size);
88    ~Term();
89
90    char const *GetName() { return "<term>"; }
91    caca_canvas_t *GetCaca() { return m_caca; }
92
93protected:
94    virtual void TickGame(float seconds);
95    virtual void TickDraw(float seconds);
96
97private:
98    /* Terminal emulation main entry point */
99    size_t ReadAnsi(void const *data, size_t size);
100    size_t SendAnsi(char const *str);
101
102    /* Utility functions for terminal emulation */
103    void ReadGrcm(unsigned int argc, unsigned int const *argv);
104    inline int ReadChar(unsigned char c, int *x, int *y);
105    inline int ReadDuplet(unsigned char const *buffer, unsigned int *skip,
106                          int top, int bottom, int width, int height);
107
108private:
109    Pty *m_pty;
110    caca_canvas_t *m_caca;
111    ivec2 m_size;
112
113    /* Terminal attributes */
114    char *m_title;
115
116    int m_bell, m_init, m_report_mouse;
117    int m_changed;                  /* content was updated */
118    Iso2022Conversion m_conv_state; /* charset mess */
119
120    uint8_t m_fg, m_bg;   /* ANSI-context fg/bg */
121    uint8_t m_dfg, m_dbg; /* Default fg/bg */
122    uint8_t m_bold, m_blink, m_italics, m_negative, m_concealed, m_underline;
123    uint8_t m_faint, m_strike, m_proportional; /* unsupported */
124    uint32_t m_clearattr;
125
126    /* Mostly for fancy shit */
127    void DrawFancyShit();
128    float m_time;
129    bool m_debug;
130};
131
132#endif // __TERM_TERM_H__
133
Note: See TracBrowser for help on using the repository browser.