Debian Codegraph @

terps/tads/tads3/lib/adv3/console.t

raw
1 #charset "us-ascii"
2
3 /*
4 * Copyright (c) 2000, 2006 Michael J. Roberts. All Rights Reserved.
5 *
6 * TADS 3 Library - console input/output manager
7 *
8 * This module defines the low-level functions for handling input and
9 * output via the traditional interpreter's user interface, using the
10 * local keyboard and console via the "tads-io" function set.
11 *
12 * The functions in this module are designed primarily for internal use
13 * within the library itself. Games should use the higher level objects
14 * and functions defined in input.t and output.t instead of directly
15 * calling the functions defined here. The reason for separating these
16 * functions is so that we can substitute the Web UI versions for games
17 * that wish to use the Web UI insetad of the traditional console UI.
18 */
19
20 /* include the library header */
21 #include "adv3.h"
22
23
24 /* ------------------------------------------------------------------------ */
25 /*
26 * Initialize the user interface. The library calls this once at the
27 * start of the interpreter session to set up the UI. For the console
28 * interpreter, we don't need to do anything here; the interpreter takes
29 * care of setting up the display window for us.
30 */
31 initUI()
32 {
33 }
34
35 /*
36 * Initialize the display. The library calls this at the start of the
37 * game, and after each RESTART, to set up the layout of the game window.
38 */
39 initDisplay()
40 {
41 /* set the interpreter window title */
42 gameMain.setGameTitle();
43
44 /* set up the ABOUT box */
45 gameMain.setAboutBox();
46 }
47
48 /*
49 * Shut down the user interface. The library calls this once just before
50 * the game is about to terminate.
51 */
52 terminateUI()
53 {
54 /* we don't need to do any work to close the display */
55 }
56
57 /* ------------------------------------------------------------------------ */
58 /*
59 * Check to see if we're in HTML mode
60 */
61 checkHtmlMode()
62 {
63 /*
64 * The HTML mode depends on the interpreter's capabilities. If this
65 * is a full multimedia interpreter - i.e., HTML-class - then we
66 * operate in HTML mode. Otherwise we operate in plain text mode.
67 *
68 * Note that the text-mode interpreters actually do interpret HTML in
69 * the output stream, but most markups don't do anything in text
70 * mode. Knowing the mode is thus useful in a couple of ways. In
71 * some cases we simply avoid the overhead of generating a bunch of
72 * HTML that will just be ignored. In other cases, we display
73 * something a little differently in text mode, to compensate for the
74 * lack of the effect we use in HTML mode.
75 */
76 return systemInfo(SysInfoInterpClass) == SysInfoIClassHTML;
77 }
78
79 /* ------------------------------------------------------------------------ */
80 /*
81 * Write text to the main game window
82 */
83 aioSay(txt)
84 {
85 /* call the interpreter's console output writer */
86 tadsSay(txt);
87 }
88
89 /* ------------------------------------------------------------------------ */
90 /*
91 * Get a line of input from the keyboard, with timeout
92 */
93 aioInputLineTimeout(timeout)
94 {
95 /* call the interpreter's console input reader */
96 return inputLineTimeout(timeout);
97 }
98
99 /*
100 * Cancel a suspended input line
101 */
102 aioInputLineCancel(reset)
103 {
104 /* call the interpreter's console input line handler */
105 inputLineCancel(reset);
106 }
107
108
109 /* ------------------------------------------------------------------------ */
110 /*
111 * Read an input event
112 */
113 aioInputEvent(timeout)
114 {
115 /* call the interpreter's console event reader */
116 return inputEvent(timeout);
117 }
118
119
120 /* ------------------------------------------------------------------------ */
121 /*
122 * Show a "More" prompt
123 */
124 aioMorePrompt()
125 {
126 /* call the interpreter's console More prompt generator */
127 morePrompt();
128 }
129
130
131 /* ------------------------------------------------------------------------ */
132 /*
133 * Show a file selector dialog
134 */
135 aioInputFile(prompt, dialogType, fileType, flags)
136 {
137 /* call the interpreter's console file dialog handler */
138 return inputFile(prompt, dialogType, fileType, flags);
139 }
140
141 /* ------------------------------------------------------------------------ */
142 /*
143 * Show an input dialog
144 */
145 aioInputDialog(icon, prompt, buttons, defaultButton, cancelButton)
146 {
147 /* call the interpreter's native input dialog handler */
148 return inputDialog(icon, prompt, buttons, defaultButton, cancelButton);
149 }
150
151 /* ------------------------------------------------------------------------ */
152 /*
153 * Set/remove the output logging file
154 */
155 aioSetLogFile(fname, logType?)
156 {
157 /* set the log file in the interpreter console */
158 return setLogFile(fname, logType);
159 }
160
161 /* ------------------------------------------------------------------------ */
162 /*
163 * Clear the screen
164 */
165 aioClearScreen()
166 {
167 /* clear the local interpreter console screen */
168 clearScreen();
169
170 /* re-initialize any <ABOUTBOX> tag */
171 gameMain.setAboutBox();
172 }
173
174 /* ------------------------------------------------------------------------ */
175 /*
176 * Generate a string to show hyperlinked text. If we're not in HTML
177 * mode, we'll simply return the text without the hyperlink; otherwise,
178 * we'll return the text with a hyperlink to the given HREF.
179 *
180 * If the display text is included, we'll generate the entire link,
181 * including the <A HREF> tag, the hyperlinked text contents, and the
182 * </A> end tag. If the text is omitted, we'll simply generate the <A
183 * HREF> tag itself, leaving it to the caller to display the text and the
184 * </A>.
185 *
186 * The optional 'flags' is a combination of AHREF_xxx flags indicating
187 * any special properties of the hyperlink.
188 */
189 aHref(href, txt?, title?, flags = 0)
190 {
191 /* check for HTML mode */
192 if (outputManager.htmlMode)
193 {
194 /* figure the <a> properties based on the flags */
195 local props = '';
196 if ((flags & AHREF_Plain) != 0)
197 props += 'plain ';
198
199 /*
200 * We're in HTML mode - generate a <a> tag enclosing the text.
201 * If there's text, include the text and </a> end tag, otherwise
202 * just show the <a> tag itself.
203 */
204 return '<a <<props>> href="<<href>>"<<
205 (title != nil ? ' title="' + title + '"' : '')
206 >>><.a><<
207 (txt != nil ? txt + '<./a></a>' : '')>>';
208 }
209 else
210 {
211 /* plain text mode - just return the text unchanged */
212 return txt;
213 }
214 }
215
216
217 /* ------------------------------------------------------------------------ */
218 /*
219 * Generate a string to show hyperlinked text, with alternate text if
220 * we're not in HTML mode. If we're in HTML mode, we'll return
221 * linkedTxt linked to the given HREF; if we're in plain text mode,
222 * we'll return the alternate text as-is.
223 */
224 aHrefAlt(href, linkedText, altText, title?)
225 {
226 /* check HTML mode */
227 if (outputManager.htmlMode)
228 {
229 /* we're in HTML mode - generate an <A> tag for the linked text */
230 return '<a href="<<href>>"<<
231 (title != nil ? ' title="' + title + '"' : '')
232 >>><.a><<linkedText>><./a></a>';
233 }
234 else
235 {
236 /* plain text mode - just return the alternate text */
237 return altText;
238 }
239 }
240
241 /* ------------------------------------------------------------------------ */
242 /*
243 * Generate HTML to wrap the left/right portions of the status line. The
244 * basic status line has three stages: stage 0 precedes the left portion,
245 * stage 1 comes between the left and right portions, and stage 2 follows
246 * the right portion. If we're listing exits, we get two more stages:
247 * stage 3 precedes the exit listing, stage 4 follows it.
248 */
249 statusHTML(stage)
250 {
251 switch (stage)
252 {
253 case 1:
254 /* return the right-alignment tab between the two sections */
255 return '<tab align=right>';
256
257 case 3:
258 case 4:
259 /* show a line break before and after the exit listing */
260 return '<br>';
261
262 default:
263 /* other stages don't require any special text */
264 return '';
265 }
266 }
267
268
269 /* ------------------------------------------------------------------------ */
270 /*
271 * The banner window for the status line.
272 */
273 statuslineBanner: BannerWindow
274 /* close the window */
275 removeBanner()
276 {
277 /* remove the banner */
278 inherited();
279
280 /* tell the statusLine object to refigure the display mode */
281 statusLine.statusDispMode = nil;
282 }
283
284 /* initialize */
285 initBannerWindow()
286 {
287 /* if we're already initialized, do nothing */
288 if (inited_)
289 return;
290
291 /* inherit the default handling (to set our 'inited_' flag) */
292 inherited();
293
294 /* tell the status line to initialize its banner window */
295 statusLine.initBannerWindow(self);
296 }
297
298 /*
299 * Set the color scheme. We simply show a <BODY> tag that selects
300 * the parameterized colors STATUSBG and STATUSTEXT. (These are
301 * called "parameterized" colors because they don't select specific
302 * colors, but rather select whatever colors the interpreter wishes
303 * to use for the status line. In many cases, the interpreter lets
304 * the user select these colors via a Preferences dialog.)
305 */
306 setColorScheme()
307 {
308 /* set up the interpreter's standard status line colors */
309 "<body bgcolor=statusbg text=statustext>";
310 }
311 ;
312