diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-01-18 23:33:32 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-01-18 23:33:32 -0700 |
commit | 0bdd1441fc95f70f2f86c89c20eb866a9ca2787b (patch) | |
tree | 1e082943e1942cf1020c64a13610ed9cadb246a5 /src/interfaceconsole.cpp | |
parent | 2d490ab892c7067eccd524dc67b5e12cf759f8fd (diff) | |
download | stage-0bdd1441fc95f70f2f86c89c20eb866a9ca2787b.tar.gz stage-0bdd1441fc95f70f2f86c89c20eb866a9ca2787b.tar.bz2 stage-0bdd1441fc95f70f2f86c89c20eb866a9ca2787b.tar.xz stage-0bdd1441fc95f70f2f86c89c20eb866a9ca2787b.zip |
Rearranged rendering code.
Diffstat (limited to 'src/interfaceconsole.cpp')
-rw-r--r-- | src/interfaceconsole.cpp | 218 |
1 files changed, 5 insertions, 213 deletions
diff --git a/src/interfaceconsole.cpp b/src/interfaceconsole.cpp index 94b45b9..caa13bf 100644 --- a/src/interfaceconsole.cpp +++ b/src/interfaceconsole.cpp | |||
@@ -7,6 +7,8 @@ | |||
7 | 7 | ||
8 | #include <bu/plugger.h> | 8 | #include <bu/plugger.h> |
9 | 9 | ||
10 | #include "smlrenderervt100.h" | ||
11 | |||
10 | PluginInterface3( plugin_interface_console, console, InterfaceConsole, | 12 | PluginInterface3( plugin_interface_console, console, InterfaceConsole, |
11 | Interface, "Mike Buland", 1, 0 ); | 13 | Interface, "Mike Buland", 1, 0 ); |
12 | 14 | ||
@@ -35,219 +37,9 @@ void InterfaceConsole::run( Game *pGame ) | |||
35 | } | 37 | } |
36 | } | 38 | } |
37 | 39 | ||
38 | void InterfaceConsole::appendToken( Bu::String &sCurLine, | 40 | void InterfaceConsole::display( const class SmlNode *pSml ) |
39 | Bu::String &sNextToken, int &iLineLen, int &iNextLen ) | ||
40 | { | ||
41 | if( iLineLen + iNextLen + 1 >= 78 ) | ||
42 | { | ||
43 | sio << sCurLine << sio.nl; | ||
44 | iLineLen = 0; | ||
45 | sCurLine = sNextToken; | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | sCurLine += sNextToken; | ||
50 | } | ||
51 | iLineLen += iNextLen + 1; | ||
52 | sCurLine += " "; | ||
53 | iNextLen = 0; | ||
54 | sNextToken.clear(); | ||
55 | } | ||
56 | |||
57 | Bu::String InterfaceConsole::getVt100Style( const StyleStack &sStyle ) | ||
58 | { | ||
59 | #ifdef WIN32 | ||
60 | // Windows...we don't do colors for windows... | ||
61 | return ""; | ||
62 | #endif | ||
63 | |||
64 | if( sStyle.isEmpty() ) | ||
65 | { | ||
66 | return "\x1B[0m"; | ||
67 | } | ||
68 | |||
69 | int sCurStyle = 0; | ||
70 | for( StyleStack::const_iterator i = sStyle.begin(); i; i++ ) | ||
71 | { | ||
72 | // sio << "Merging in: " << Fmt::hex() << *i << sio.nl; | ||
73 | if( ((sCurStyle&stTypeMask) & ((*i)&stTypeMask)) == 0 ) | ||
74 | { | ||
75 | sCurStyle |= *i; | ||
76 | // sio << " -> curStyle = " << Fmt::hex() << *i << sio.nl; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | Bu::String sRet; | ||
81 | |||
82 | // sio << "Color: " << Fmt::hex() << sCurStyle << sio.nl; | ||
83 | switch( sCurStyle&stColor ) | ||
84 | { | ||
85 | case stRed: | ||
86 | sRet += "\x1B[1;31m"; | ||
87 | break; | ||
88 | |||
89 | case stGreen: | ||
90 | sRet += "\x1B[1;32m"; | ||
91 | break; | ||
92 | } | ||
93 | |||
94 | return sRet; | ||
95 | } | ||
96 | |||
97 | void InterfaceConsole::display( const SmlNode *pNode ) | ||
98 | { | 41 | { |
99 | Bu::String sCurLine; | 42 | SmlRendererVt100 rend; |
100 | Bu::String sNextToken; | 43 | rend.render( sio, pSml ); |
101 | int iLineLen = 0; | ||
102 | int iNextLen = 0; | ||
103 | int iState = 0; | ||
104 | typedef Bu::List<SmlNode::SmlNodeList::const_iterator> NodeStack; | ||
105 | NodeStack sNode; | ||
106 | |||
107 | StyleStack sStyle; | ||
108 | |||
109 | sNode.push( pNode->getChildren().begin() ); | ||
110 | |||
111 | for(;;) | ||
112 | { | ||
113 | if( !sNode.peek() ) | ||
114 | { | ||
115 | sNode.pop(); | ||
116 | if( sNode.isEmpty() ) | ||
117 | break; | ||
118 | if( sNode.peek() ) | ||
119 | { | ||
120 | // sio << "Pop'd: " << (*sNode.peek())->getText() << sio.nl; | ||
121 | Bu::String sTag = (*sNode.peek())->getText(); | ||
122 | if( sTag == "green" || sTag == "red" ) | ||
123 | { | ||
124 | sStyle.pop(); | ||
125 | sNextToken += getVt100Style( sStyle ); | ||
126 | } | ||
127 | sNode.peek()++; | ||
128 | continue; | ||
129 | } | ||
130 | } | ||
131 | if( sNode.isEmpty() ) | ||
132 | { | ||
133 | break; | ||
134 | } | ||
135 | const SmlNode *pNode = (*sNode.peek()); | ||
136 | switch( pNode->getType() ) | ||
137 | { | ||
138 | case SmlNode::typeRoot: | ||
139 | throw Bu::ExceptionBase("Invalid root."); | ||
140 | |||
141 | case SmlNode::typeText: | ||
142 | { | ||
143 | // sio << "Process text node: " << pNode->getText() << | ||
144 | // sio.nl; | ||
145 | Bu::String::const_iterator iBgn = pNode->getText().begin(); | ||
146 | Bu::String::const_iterator iEnd = iBgn; | ||
147 | int iTmpLen = 0; | ||
148 | for(;iBgn;) | ||
149 | { | ||
150 | switch( iState ) | ||
151 | { | ||
152 | case 0: // begining of paragraph | ||
153 | if( iBgn && ( *iBgn == ' ' || *iBgn == '\n' || | ||
154 | *iBgn == '\r' || *iBgn == '\t' ) ) | ||
155 | { | ||
156 | iBgn++; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | // Here is where you would indent paragraphs | ||
161 | iEnd = iBgn; | ||
162 | iState = 1; | ||
163 | } | ||
164 | break; | ||
165 | |||
166 | case 1: // non-whitespace | ||
167 | if( !iEnd ) | ||
168 | { | ||
169 | sNextToken.append( iBgn, iEnd ); | ||
170 | iBgn = iEnd; | ||
171 | iNextLen += iTmpLen; | ||
172 | iTmpLen = 0; | ||
173 | } | ||
174 | else if( *iEnd == ' ' || *iEnd == '\n' || | ||
175 | *iEnd == '\r' || *iEnd == '\t' ) | ||
176 | { | ||
177 | sNextToken.append( iBgn, iEnd ); | ||
178 | iNextLen += iTmpLen; | ||
179 | iTmpLen = 0; | ||
180 | iState = 2; | ||
181 | iBgn = iEnd; | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | iEnd++; | ||
186 | iTmpLen++; | ||
187 | } | ||
188 | break; | ||
189 | |||
190 | case 2: // Whitespace | ||
191 | if( iBgn && (*iBgn == ' ' || *iBgn == '\n' || | ||
192 | *iBgn == '\r' || *iBgn == '\t') ) | ||
193 | { | ||
194 | iBgn++; | ||
195 | } | ||
196 | else | ||
197 | { | ||
198 | iEnd = iBgn; | ||
199 | iState = 1; | ||
200 | appendToken( sCurLine, sNextToken, | ||
201 | iLineLen, iNextLen ); | ||
202 | } | ||
203 | break; | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | break; | ||
208 | |||
209 | case SmlNode::typeTag: | ||
210 | if( pNode->getChildren().isEmpty() ) | ||
211 | { | ||
212 | if( pNode->getText() == "break" ) | ||
213 | { | ||
214 | appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); | ||
215 | if( !sCurLine.isEmpty() ) | ||
216 | sio << sCurLine << sio.nl; | ||
217 | sCurLine.clear(); | ||
218 | iLineLen = 0; | ||
219 | iState = 0; | ||
220 | } | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | // sio << "Push'd: " << pNode->getText() << sio.nl; | ||
225 | Bu::String sTag = pNode->getText(); | ||
226 | if( sTag == "green" ) | ||
227 | { | ||
228 | sStyle.push( stGreen ); | ||
229 | } | ||
230 | else if( sTag == "red" ) | ||
231 | { | ||
232 | sStyle.push( stRed ); | ||
233 | } | ||
234 | sNextToken += getVt100Style( sStyle ); | ||
235 | sNode.push( pNode->getChildren().begin() ); | ||
236 | continue; | ||
237 | /* for( SmlNode::SmlNodeList::const_iterator i = | ||
238 | pNode->getChildren().begin(); i; i++ ) | ||
239 | { | ||
240 | s | ||
241 | smlToConsole( *i, sCurLine, sNextToken, iLineLen, iState ); | ||
242 | } | ||
243 | */ | ||
244 | } | ||
245 | break; | ||
246 | } | ||
247 | sNode.peek()++; | ||
248 | } | ||
249 | if( !sNextToken.isEmpty() ) | ||
250 | appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); | ||
251 | sio << sCurLine << sio.nl; | ||
252 | } | 44 | } |
253 | 45 | ||