-rw-r--r-- | terminal.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/terminal.cpp b/terminal.cpp new file mode 100644 index 0000000..f60ce8b --- a/dev/null +++ b/terminal.cpp | |||
@@ -0,0 +1,147 @@ | |||
1 | extern int TTTermType; | ||
2 | class CTTY; | ||
3 | struct_tType { | ||
4 | LPCTSTR m_Name; | ||
5 | CTTY* m_Termcap; | ||
6 | }; | ||
7 | extern _tType TTypes[]; | ||
8 | |||
9 | BOOL TerminalUpdateTitle(); | ||
10 | |||
11 | #include "TTY.cpp" | ||
12 | #include "VT100.cpp" | ||
13 | |||
14 | enum _TTSB{ | ||
15 | ttsbSend = 1, | ||
16 | ttsbIs = 0 | ||
17 | }; | ||
18 | |||
19 | _tType TTypes[] = { | ||
20 | {"VT102",&TT_VT100}, | ||
21 | {"DEC-VT102",&TT_VT100}, | ||
22 | {"VT100",&TT_VT100}, | ||
23 | {"DEC-VT100",&TT_VT100}, | ||
24 | {"ANSI",&TT_VT100}, | ||
25 | {"TTY",&TT_TTY}, | ||
26 | {"UNKNOWN",&TT_TTY}, | ||
27 | {"DUMB",&TT_TTY} | ||
28 | }; | ||
29 | intTType = -1; | ||
30 | CTTY* TTTerm = NULL; | ||
31 | int TTTermType = -1; | ||
32 | |||
33 | BOOL TerminalPullType(LPCTSTR ttype,LPCTSTR newName=NULL) | ||
34 | { | ||
35 | for(int tmp=0;tmp<(sizeof(TTypes)/sizeof(*TTypes));tmp++){ | ||
36 | if(!stricmp(ttype,TTypes[tmp].m_Name)){ | ||
37 | if(tmp){ | ||
38 | _tType t; | ||
39 | memmove(&t,&TTypes[tmp],sizeof(t)); | ||
40 | memmove(&TTypes[1],&TTypes[0],sizeof(*TTypes)*tmp); | ||
41 | memmove(&TTypes[0],&t,sizeof(TTypes[0])); | ||
42 | } | ||
43 | if(newName) | ||
44 | TTypes[0].m_Name=newName; | ||
45 | return TRUE; | ||
46 | } | ||
47 | } | ||
48 | return FALSE; | ||
49 | } | ||
50 | BOOL TerminalPrintTypes() | ||
51 | { | ||
52 | for(int tmp=0;tmp<(sizeof(TTypes)/sizeof(*TTypes));tmp++) | ||
53 | printf(" %s",TTypes[tmp].m_Name); | ||
54 | return TRUE; | ||
55 | } | ||
56 | |||
57 | BOOL TerminalUpdateTitle() | ||
58 | { | ||
59 | CHAR consoleTitle[1024]; | ||
60 | sprintf(consoleTitle,DAMN_KIN_NAME " %s:%s - %s",remoteHost,remoteProt,TTTerm->GetTitle()); | ||
61 | return SetConsoleTitle(consoleTitle); | ||
62 | } | ||
63 | |||
64 | BOOL SelectTermType(int tt) | ||
65 | { | ||
66 | if(tt<0) | ||
67 | tt=0; | ||
68 | if(tt>=(sizeof(TTypes)/sizeof(*TTypes))) | ||
69 | tt = sizeof(TTypes)/sizeof(*TTypes)-1; | ||
70 | TTTerm = TTypes[tt].m_Termcap; | ||
71 | TTTermType=tt; | ||
72 | VERIFY(TTTerm->Init()); | ||
73 | return TerminalUpdateTitle(); | ||
74 | } | ||
75 | BOOL TerminalOut(BYTE c) | ||
76 | { | ||
77 | ASSERT(TTTerm); | ||
78 | return TTTerm->Output(c); | ||
79 | } | ||
80 | BOOL TerminalIn(KEY_EVENT_RECORD k) | ||
81 | { | ||
82 | ASSERT(TTTerm); | ||
83 | if(k.uChar.AsciiChar){// Maybe fall for V-Processing if ENHANCED_KEY | ||
84 | // Workaround for ENTER's \r/\n dilemma.. *********** | ||
85 | // Maybe should be moved to termtype-dependant code | ||
86 | CHAR c = k.uChar.AsciiChar; | ||
87 | if(k.wVirtualKeyCode==VK_RETURN){ | ||
88 | if(c=='\r') | ||
89 | return TTTerm->Input('\r') && TTTerm->Input('\n'); | ||
90 | else if(c=='\n') | ||
91 | return TTTerm->Input('\n'); | ||
92 | } | ||
93 | return TTTerm->Input(c); | ||
94 | }else | ||
95 | return TTTerm->VInput(k.wVirtualKeyCode,k.dwControlKeyState); | ||
96 | } | ||
97 | BOOL TerminalIn(LPCTSTR str) | ||
98 | { | ||
99 | ASSERT(TTTerm); | ||
100 | while(*str) | ||
101 | TTTerm->Input(*(str++)); | ||
102 | return TRUE; | ||
103 | } | ||
104 | BOOL TerminalPreO() | ||
105 | { | ||
106 | ASSERT(TTTerm); | ||
107 | return TTTerm->PreOutput(); | ||
108 | } | ||
109 | BOOL TerminalPostO() | ||
110 | { | ||
111 | ASSERT(TTTerm); | ||
112 | return TTTerm->PostOutput(); | ||
113 | } | ||
114 | |||
115 | BOOL terminaltypeOnInit() | ||
116 | { | ||
117 | VERIFY(SetConsoleMode(hConsoleInput,0)); | ||
118 | TType = -1; | ||
119 | return SelectTermType(0); | ||
120 | } | ||
121 | BOOL terminaltypeOnDo() | ||
122 | { | ||
123 | TRACE0("DO TERMINAL-TYPE\n"); | ||
124 | return TRUE; | ||
125 | } | ||
126 | BOOL terminaltypeOnSB(LPBYTE data,UINT size) | ||
127 | { | ||
128 | if(!size) | ||
129 | return FALSE; | ||
130 | if(data[0]!=ttsbSend) | ||
131 | return FALSE; | ||
132 | TRACE0("SB TERMINAL-TYPE SEND\n"); | ||
133 | TType++; | ||
134 | if(TType>(sizeof(TTypes)/sizeof(*TTypes))) | ||
135 | TType=0; | ||
136 | int tt = TType; | ||
137 | if(tt>=(sizeof(TTypes)/sizeof(*TTypes))) | ||
138 | tt = sizeof(TTypes)/sizeof(*TTypes)-1; | ||
139 | VERIFY(SelectTermType(tt)); | ||
140 | int ds = strlen(TTypes[tt].m_Name)+1; | ||
141 | LPBYTE lpb = new BYTE[ds]; | ||
142 | lpb[0] = ttsbIs; | ||
143 | memmove(&lpb[1],TTypes[tt].m_Name,ds-1); | ||
144 | VERIFY(SubNegotiate(toTerminalType,lpb,ds)); | ||
145 | delete lpb; | ||
146 | return TRUE; | ||
147 | } | ||