Name | Executed | Routines | % | Executed | Lines | % | Unexecuted |
/home/matt/eu/rds/include/std/console.e | 0 | 20 | 0.00% | 14 | 129 | 10.85% | 115 |
Routine | Executed | Lines | Unexecuted | |
display() | 0 | 21 | 0.00% | 21 |
display_text_image() | 0 | 19 | 0.00% | 19 |
prompt_number() | 0 | 14 | 0.00% | 14 |
save_text_image() | 0 | 10 | 0.00% | 10 |
any_key() | 0 | 7 | 0.00% | 7 |
prompt_string() | 0 | 7 | 0.00% | 7 |
get_screen_char() | 0 | 5 | 0.00% | 5 |
colors_to_attr() | 0 | 4 | 0.00% | 4 |
allow_break() | 0 | 3 | 0.00% | 3 |
cursor() | 0 | 3 | 0.00% | 3 |
free_console() | 0 | 3 | 0.00% | 3 |
put_screen_char() | 0 | 3 | 0.00% | 3 |
attr_to_colors() | 0 | 2 | 0.00% | 2 |
check_break() | 0 | 2 | 0.00% | 2 |
maybe_any_key() | 0 | 2 | 0.00% | 2 |
positive_atom() | 0 | 2 | 0.00% | 2 |
positive_int() | 0 | 2 | 0.00% | 2 |
text_point() | 0 | 2 | 0.00% | 2 |
text_rows() | 0 | 2 | 0.00% | 2 |
wait_key() | 0 | 2 | 0.00% | 2 |
# | Executed | |
1 | -- (c) Copyright - See License.txt | |
2 | -- | |
3 | --**** | |
4 | -- == Console | |
5 | -- | |
6 | -- < | |
7 | namespace console | |
8 | ||
9 | include std/types.e | |
10 | include std/get.e | |
11 | include std/text.e | |
12 | include std/types.e | |
13 | include std/pretty.e | |
14 | public include std/graphcst.e | |
15 | ||
16 | -- machine() commands | |
17 | constant | |
18 | 4 | M_WAIT_KEY = 26, |
19 | 4 | M_ALLOW_BREAK = 42, |
20 | 4 | M_CHECK_BREAK = 43, |
21 | 4 | M_CURSOR = 6, |
22 | 4 | M_TEXTROWS = 12, |
23 | 4 | M_FREE_CONSOLE = 54, |
24 | 4 | M_GET_SCREEN_CHAR = 58, |
25 | 4 | M_PUT_SCREEN_CHAR = 59, |
26 | $ | |
27 | ||
28 | --**** | |
29 | -- === Cursor Style Constants | |
30 | -- | |
31 | -- In the cursor constants below, the second and fourth hex digits (from the | |
32 | -- left) determine the top and bottom row of pixels in the cursor. The first | |
33 | -- digit controls whether the cursor will be visible or not. For example, #0407 | |
34 | -- turns on the 4th through 7th rows. | |
35 | -- | |
36 | -- See Also: | |
37 | -- [[:cursor]] | |
38 | ||
39 | public constant | |
40 | 4 | NO_CURSOR = #2000, |
41 | 4 | UNDERLINE_CURSOR = #0607, |
42 | 4 | THICK_UNDERLINE_CURSOR = #0507, |
43 | 4 | HALF_BLOCK_CURSOR = #0407, |
44 | 4 | BLOCK_CURSOR = #0007 |
45 | ||
46 | --**** | |
47 | -- === Keyboard related routines | |
48 | ||
49 | --** | |
50 | -- Signature: | |
51 | -- | |
52 | -- | |
53 | -- Description: | |
54 | -- Return the key that was pressed by the user, without waiting. Special codes are returned for the function keys, arrow keys etc. | |
55 | -- | |
56 | -- Returns: | |
57 | -- An **integer**, either -1 if no key waiting, or the code of the next key waiting in keyboard buffer. | |
58 | -- | |
59 | -- Comments: | |
60 | -- The operating system can hold a small number of key-hits in its keyboard buffer. | |
61 | -- ##get_key##() will return the next one from the buffer, or -1 if the buffer is empty. | |
62 | -- | |
63 | -- Run the ##key.bat## program to see what key code is generated for each key on your | |
64 | -- keyboard. | |
65 | -- | |
66 | -- Example 1: | |
67 | -- | |
68 | -- integer n = get_key() | |
69 | -- if n=-1 then | |
70 | -- puts(1, "No key waiting.\n") | |
71 | -- end if | |
72 | -- | |
73 | -- | |
74 | -- See Also: | |
75 | -- [[:wait_key]] | |
76 | ||
77 | --** | |
78 | -- Set behavior of CTRL+C/CTRL+Break | |
79 | -- | |
80 | -- Parameters: | |
81 | -- # ##b## : a boolean, TRUE ( != 0 ) to enable the trapping of | |
82 | -- Ctrl-C/Ctrl-Break, FALSE ( 0 ) to disable it. | |
83 | -- | |
84 | -- Comments: | |
85 | -- When ##b## is 1 (true), CTRL+C and CTRL+Break can terminate | |
86 | -- your program when it tries to read input from the keyboard. When | |
87 | -- i is 0 (false) your program will not be terminated by CTRL+C or CTRL+Break. | |
88 | -- | |
89 | -- Initially your program can be terminated at any point where | |
90 | -- it tries to read from the keyboard. | |
91 | -- | |
92 | -- You can find out if the user has pressed Control-C or Control-Break by calling | |
93 | -- [[:check_break]](). | |
94 | -- | |
95 | -- Example 1: | |
96 | -- | |
97 | -- allow_break(0) -- don't let the user kill the program! | |
98 | -- | |
99 | -- | |
100 | -- See Also: | |
101 | -- [[:check_break]] | |
102 | ||
103 | 0 | |
104 | 0 | machine_proc(M_ALLOW_BREAK, b) |
105 | 0 | end procedure |
106 | ||
107 | --** | |
108 | -- Description: | |
109 | -- Returns the number of Control-C/Control-BREAK key presses. | |
110 | -- | |
111 | -- Returns: | |
112 | -- An **integer**, the number of times that CTRL+C or CTRL+Break have | |
113 | -- been pressed since the last call to ##check_break##(), or since the | |
114 | -- beginning of the program if this is the first call. | |
115 | -- | |
116 | -- Comments: | |
117 | -- This is useful after you have called [[:allow_break]](0) which | |
118 | -- prevents CTRL+C or CTRL+Break from terminating your | |
119 | -- program. You can use ##check_break##() to find out if the user | |
120 | -- has pressed one of these keys. You might then perform some action | |
121 | -- such as a graceful shutdown of your program. | |
122 | -- | |
123 | -- Neither CTRL+C or CTRL+Break will be returned as input | |
124 | -- characters when you read the keyboard. You can only detect | |
125 | -- them by calling ##check_break##(). | |
126 | -- | |
127 | -- Example 1: | |
128 | -- | |
129 | -- k = get_key() | |
130 | -- if check_break() then -- ^C or ^Break was hit once or more | |
131 | -- temp = graphics_mode(-1) | |
132 | -- puts(STDOUT, "Shutting down...") | |
133 | -- save_all_user_data() | |
134 | -- abort(1) | |
135 | -- end if | |
136 | -- | |
137 | -- | |
138 | -- See Also: | |
139 | -- [[:allow_break]] | |
140 | ||
141 | 0 | |
142 | 0 | return machine_func(M_CHECK_BREAK, 0) |
143 | end function | |
144 | ||
145 | --** | |
146 | -- Description: | |
147 | -- Waits for user to press a key, unless any is pending, and returns key code. | |
148 | -- | |
149 | -- Returns: | |
150 | -- An **integer**, which is a key code. If one is waiting in keyboard buffer, then return it. Otherwise, wait for one to come up. | |
151 | -- | |
152 | -- See Also: | |
153 | -- [[:get_key]], [[:getc]] | |
154 | ||
155 | 0 | |
156 | 0 | return machine_func(M_WAIT_KEY, 0) |
157 | end function | |
158 | ||
159 | --** | |
160 | -- Display a prompt to the user and wait for any key. | |
161 | -- | |
162 | -- Parameters: | |
163 | -- # ##prompt## : Prompt to display, defaults to "Press Any Key to continue..." | |
164 | -- # ##con## : Either 1 (stdout), or 2 (stderr). Defaults to 1. | |
165 | -- | |
166 | -- Comments: | |
167 | -- This wraps [[:wait_key]] by giving a clue that the user should press a key, and | |
168 | -- perhaps do some other things as well. | |
169 | -- | |
170 | -- Example 1: | |
171 | -- | |
172 | -- any_key() -- "Press Any Key to continue..." | |
173 | -- | |
174 | -- | |
175 | -- Example 2: | |
176 | -- | |
177 | -- any_key("Press Any Key to quit") | |
178 | -- | |
179 | -- | |
180 | -- See Also: | |
181 | -- [[:wait_key]] | |
182 | ||
183 | 0 | |
184 | 0 | if not find(con, {1,2}) then |
185 | 0 | con = 1 |
186 | end if | |
187 | 0 | puts(con, prompt) |
188 | 0 | wait_key() |
189 | 0 | puts(con, "\n") |
190 | 0 | end procedure |
191 | ||
192 | 4 | ifdef WIN32_GUI then |
193 | ||
194 | --** | |
195 | -- Description: | |
196 | -- Display a prompt to the user and wait for any key **only** if the user is | |
197 | -- running under a GUI environment. | |
198 | -- | |
199 | -- Parameters: | |
200 | -- # ##prompt## : Prompt to display, defaults to "Press Any Key to continue..." | |
201 | -- # ##con## : Either 1 (stdout), or 2 (stderr). Defaults to 1. | |
202 | -- | |
203 | -- Comments: | |
204 | -- This wraps [[:wait_key]] by giving a clue that the user should press a key, and | |
205 | -- perhaps do some other things as well. | |
206 | -- | |
207 | -- Example 1: | |
208 | -- | |
209 | -- any_key() -- "Press Any Key to continue..." | |
210 | -- | |
211 | -- | |
212 | -- Example 2: | |
213 | -- | |
214 | -- any_key("Press Any Key to quit") | |
215 | -- | |
216 | -- | |
217 | -- See Also: | |
218 | -- [[:wait_key]] | |
219 | ||
220 | public procedure maybe_any_key(sequence prompt="Press Any Key to continue...", integer con = 1) | |
221 | any_key(prompt, con) | |
222 | end procedure | |
223 | ||
224 | elsedef | |
225 | ||
226 | 0 | |
227 | 0 | end procedure |
228 | ||
229 | end ifdef | |
230 | ||
231 | --** | |
232 | -- Description: | |
233 | -- Prompts the user to enter a number, and returns only validated input. | |
234 | -- | |
235 | -- Parameters: | |
236 | -- # ##st## : is a string of text that will be displayed on the screen. | |
237 | -- # ##s## : is a sequence of two values {lower, upper} which determine the range of values | |
238 | -- that the user may enter. s can be empty, {}, if there are no restrictions. | |
239 | -- | |
240 | -- Returns: | |
241 | -- An **atom**, in the assigned range which the user typed in. | |
242 | -- | |
243 | -- Errors: | |
244 | -- If [[:puts]]() cannot display ##st## on standard output, or if the first or second element | |
245 | -- of ##s## is a sequence, a runtime error will be raised. | |
246 | -- | |
247 | -- If user tries cancelling the prompt by hitting Ctrl-Z, the program will abort as well, | |
248 | -- issuing a type check error. | |
249 | -- | |
250 | -- Comments: | |
251 | -- As long as the user enters a number that is less than lower or greater | |
252 | -- than upper, the user will be prompted again. | |
253 | -- | |
254 | -- If this routine is too simple for your needs, feel free to copy it and make your | |
255 | -- own more specialized version. | |
256 | -- | |
257 | -- Example 1: | |
258 | -- | |
259 | -- age = prompt_number("What is your age? ", {0, 150}) | |
260 | -- | |
261 | -- | |
262 | -- Example 2: | |
263 | -- | |
264 | -- t = prompt_number("Enter a temperature in Celcius:\n", {}) | |
265 | -- | |
266 | -- | |
267 | -- See Also: | |
268 | -- [[:puts]], [[:prompt_string]] | |
269 | -- | |
270 | ||
271 | 0 | |
272 | object answer | |
273 | ||
274 | 0 | while 1 do |
275 | 0 | puts(1, prompt) |
276 | 0 | answer = gets(0) -- make sure whole line is read |
277 | 0 | puts(1, '\n') |
278 | ||
279 | 0 | answer = value(answer) |
280 | 0 | if answer[1] != GET_SUCCESS or sequence(answer[2]) then |
281 | 0 | puts(1, "A number is expected - try again\n") |
282 | else | |
283 | 0 | if length(range) = 2 then |
284 | 0 | if range[1] <= answer[2] and answer[2] <= range[2] then |
285 | 0 | return answer[2] |
286 | else | |
287 | 0 | printf(1, "A number from %g to %g is expected here - try again\n", range) |
288 | end if | |
289 | else | |
290 | 0 | return answer[2] |
291 | end if | |
292 | end if | |
293 | 0 | end while |
294 | end function | |
295 | ||
296 | --** | |
297 | -- Prompt the user to enter a string of text. | |
298 | -- | |
299 | -- Parameters: | |
300 | -- # ##st## : is a string that will be displayed on the screen. | |
301 | -- | |
302 | -- Returns: | |
303 | -- A **sequence**, the string that the user typed in, stripped of any new-line character. | |
304 | -- | |
305 | -- Comments: | |
306 | -- If the user happens to type control-Z (indicates end-of-file), "" will be returned. | |
307 | -- | |
308 | -- Example 1: | |
309 | -- | |
310 | -- name = prompt_string("What is your name? ") | |
311 | -- | |
312 | -- | |
313 | -- See Also: | |
314 | -- [[:prompt_number]] | |
315 | ||
316 | 0 | |
317 | object answer | |
318 | ||
319 | 0 | puts(1, prompt) |
320 | 0 | answer = gets(0) |
321 | 0 | puts(1, '\n') |
322 | 0 | if sequence(answer) and length(answer) > 0 then |
323 | 0 | return answer[1..$-1] -- trim the \n |
324 | else | |
325 | 0 | return "" |
326 | end if | |
327 | end function | |
328 | ||
329 | --**** | |
330 | -- === Cross Platform Text Graphics | |
331 | ||
332 | 0 | |
333 | 0 | return x >= 1 |
334 | end type | |
335 | ||
336 | 0 | |
337 | 0 | return length(p) = 2 and p[1] >= 1 and p[2] >= 1 |
338 | and p[1] <= 200 and p[2] <= 500 -- rough sanity check | |
339 | end type | |
340 | ||
341 | 0 | |
342 | 0 | return x >= 1 |
343 | end type | |
344 | ||
345 | --** | |
346 | -- Signature: | |
347 | -- | |
348 | -- | |
349 | -- Description: | |
350 | -- Clear the screen using the current background color (may be set by [[:bk_color]]() ). | |
351 | -- | |
352 | -- See Also: | |
353 | -- [[:bk_color]] | |
354 | -- | |
355 | ||
356 | --** | |
357 | -- Get the value and attribute of the character at a given screen location. | |
358 | -- | |
359 | -- Parameters: | |
360 | -- # ##line## : the 1-base line number of the location | |
361 | -- # ##column## : the 1-base column number of the location | |
362 | -- # ##fgbg## : an integer, if 0 (the default) you get an attribute_code | |
363 | -- returned otherwise you get a foreground and background color | |
364 | -- number returned. | |
365 | -- | |
366 | -- Returns: | |
367 | -- * If fgbg is zero then a **sequence** of //two// elements, ##{character, attribute_code}## | |
368 | -- for the specified location. | |
369 | -- * If fgbg is not zero then a **sequence** of //three// elements, ##{characterfg_color, bg_color}## | |
370 | -- | |
371 | -- Comments: | |
372 | -- * This function inspects a single character on the //active page//. | |
373 | -- * The attribute_code is an atom that contains the foreground and background | |
374 | -- color of the character, and possibly other operating-system dependant | |
375 | -- information describing the appearance of the character on the screen. | |
376 | -- * The fg_color and bg_color are integers in the range 0 to 15, which correspond | |
377 | -- to... | |
378 | -- |= color number |= name | | |
379 | -- | 0 | black | | |
380 | -- | 1 | dark blue | | |
381 | -- | 2 | green | | |
382 | -- | 3 | cyan | | |
383 | -- | 4 | crimson | | |
384 | -- | 5 | purple | | |
385 | -- | 6 | brown | | |
386 | -- | 7 | light gray | | |
387 | -- | 8 | dark gray | | |
388 | -- | 9 | blue | | |
389 | -- | 10 | bright green | | |
390 | -- | 11 | light blue | | |
391 | -- | 12 | red | | |
392 | -- | 13 | magenta | | |
393 | -- | 14 | yellow | | |
394 | -- | 15 | white | | |
395 | -- | |
396 | -- * With get_screen_char() and [[:put_screen_char]]() you can save and restore | |
397 | -- a character on the screen along with its attribute_code. | |
398 | -- | |
399 | -- Example 1: | |
400 | -- | |
401 | -- -- read character and attributes at top left corner | |
402 | -- s = get_screen_char(1,1) | |
403 | -- -- s could be {'A', 92} | |
404 | -- -- store character and attributes at line 25, column 10 | |
405 | -- put_screen_char(25, 10, s) | |
406 | -- | |
407 | -- | |
408 | -- Example 2: | |
409 | -- | |
410 | -- -- read character and colors at line 25, column 10. | |
411 | -- s = get_screen_char(25,10, 1) | |
412 | -- -- s could be {'A', 12, 5} | |
413 | -- | |
414 | -- | |
415 | -- See Also: | |
416 | -- [[:put_screen_char]], [[:save_text_image]] | |
417 | ||
418 | 0 | |
419 | sequence ca | |
420 | ||
421 | 0 | ca = machine_func(M_GET_SCREEN_CHAR, {line, column}) |
422 | 0 | if fgbg then |
423 | 0 | ca = ca[1] & and_bits({ca[2], ca[2]/16}, 0x0F) |
424 | end if | |
425 | ||
426 | 0 | return ca |
427 | end function | |
428 | ||
429 | --** | |
430 | -- Stores/displays a sequence of characters with attributes at a given location. | |
431 | -- | |
432 | -- Parameters: | |
433 | -- # ##line## : the 1-based line at which to start writing | |
434 | -- # ##column## : the 1-based column at which to start writing | |
435 | -- # ##char_attr## : a sequence of alternated characters and attribute codes. | |
436 | -- | |
437 | -- Comments: | |
438 | -- | |
439 | -- ##char_attr## must be in the form ##{character, attribute code, character, attribute code, ...}##. | |
440 | -- | |
441 | -- Errors: | |
442 | -- The length of ##char_attr## must be a multiple of 2. | |
443 | -- | |
444 | -- Comments: | |
445 | -- | |
446 | -- The attributes atom contains the foreground color, background color, and possibly other platform-dependent information controlling how the character is displayed on the screen. | |
447 | -- If ##char_attr## has ##0## length, nothing will be written to the screen. The characters are written to the //active page//. | |
448 | -- It's faster to write several characters to the screen with a single call to ##put_screen_char##() than it is to write one character at a time. | |
449 | -- | |
450 | -- Example 1: | |
451 | -- | |
452 | -- -- write AZ to the top left of the screen | |
453 | -- -- (attributes are platform-dependent) | |
454 | -- put_screen_char(1, 1, {'A', 152, 'Z', 131}) | |
455 | -- | |
456 | -- | |
457 | -- See Also: | |
458 | -- [[:get_screen_char]], [[:display_text_image]] | |
459 | ||
460 | 0 | |
461 | 0 | machine_proc(M_PUT_SCREEN_CHAR, {line, column, char_attr}) |
462 | 0 | end procedure |
463 | ||
464 | ||
465 | --** | |
466 | -- Converts an attribute code to its foreground and background color components. | |
467 | -- | |
468 | -- Parameters: | |
469 | -- # ##attr_code## : integer, an attribute code. | |
470 | -- | |
471 | -- Returns: | |
472 | -- A sequence of two elements - {fgcolor, bgcolor} | |
473 | -- | |
474 | -- Example 1: | |
475 | -- | |
476 | -- ? attr_to_colors(92) --> {12, 5} | |
477 | -- | |
478 | -- | |
479 | -- See Also: | |
480 | -- [[:get_screen_char]], [[:colors_to_attr]] | |
481 | ||
482 | 0 | |
483 | 0 | return and_bits({attr_code, attr_code/16}, 0x0F) |
484 | end function | |
485 | ||
486 | --** | |
487 | -- Converts a foreground and background color set to its attribute code format. | |
488 | -- | |
489 | -- Parameters: | |
490 | -- # ##fgbg## : Either a sequence of {fgcolor, bgcolor} or just an integer fgcolor. | |
491 | -- # ##bg## : An integer bgcolor. Only used when ##fgbg## is an integer. | |
492 | -- | |
493 | -- Returns: | |
494 | -- An integer attribute code. | |
495 | -- | |
496 | -- Example 1: | |
497 | -- | |
498 | -- ? colors_to_attr({12, 5}) --> 92 | |
499 | -- ? colors_to_attr(12, 5) --> 92 | |
500 | -- | |
501 | -- | |
502 | -- See Also: | |
503 | -- [[:get_screen_char]], [[:put_screen_char]], [[:attr_to_colors]] | |
504 | ||
505 | 0 | |
506 | 0 | if sequence(fgbg) then |
507 | 0 | return fgbg[1] + fgbg[2] * 16 |
508 | else | |
509 | 0 | return fgbg + bg * 16 |
510 | end if | |
511 | end function | |
512 | ||
513 | --** | |
514 | -- Display a text image in any text mode. | |
515 | -- | |
516 | -- Parameters: | |
517 | -- # ##xy## : a pair of 1-based coordinates representing the point at which to start writing | |
518 | -- # ##text## : a list of sequences of alternated character and attribute. | |
519 | -- | |
520 | -- Comments: | |
521 | -- This routine displays to the active text page, and only works in text modes. | |
522 | -- | |
523 | -- You might use [[:save_text_image]]()/[[:display_text_image]]() in a text-mode graphical | |
524 | -- user interface, to allow "pop-up" dialog boxes, and drop-down menus to appear and disappear | |
525 | -- without losing what was previously on the screen. | |
526 | -- | |
527 | -- Example 1: | |
528 | -- | |
529 | -- clear_screen() | |
530 | -- display_text_image({1,1}, {{'A', WHITE, 'B', GREEN}, | |
531 | -- {'C', RED+16*WHITE}, | |
532 | -- {'D', BLUE}}) | |
533 | -- -- displays: | |
534 | -- -- AB | |
535 | -- -- C | |
536 | -- -- D | |
537 | -- -- at the top left corner of the screen. | |
538 | -- -- 'A' will be white with black (0) background color, | |
539 | -- -- 'B' will be green on black, | |
540 | -- -- 'C' will be red on white, and | |
541 | -- -- 'D' will be blue on black. | |
542 | -- | |
543 | -- | |
544 | -- See Also: | |
545 | -- [[:save_text_image]], [[:put_screen_char]] | |
546 | -- | |
547 | ||
548 | 0 | |
549 | integer extra_col2, extra_lines | |
550 | sequence vc, one_row | |
551 | ||
552 | 0 | vc = video_config() |
553 | 0 | if xy[1] < 1 or xy[2] < 1 then |
554 | 0 | return -- bad starting point |
555 | end if | |
556 | 0 | extra_lines = vc[VC_LINES] - xy[1] + 1 |
557 | 0 | if length(text) > extra_lines then |
558 | 0 | if extra_lines <= 0 then |
559 | 0 | return -- nothing to display |
560 | end if | |
561 | 0 | text = text[1..extra_lines] -- truncate |
562 | end if | |
563 | 0 | extra_col2 = 2 * (vc[VC_COLUMNS] - xy[2] + 1) |
564 | 0 | for row = 1 to length(text) do |
565 | 0 | one_row = text[row] |
566 | 0 | if length(one_row) > extra_col2 then |
567 | 0 | if extra_col2 <= 0 then |
568 | 0 | return -- nothing to display |
569 | end if | |
570 | 0 | one_row = one_row[1..extra_col2] -- truncate |
571 | end if | |
572 | ||
573 | 0 | machine_proc(M_PUT_SCREEN_CHAR, {xy[1]+row-1, xy[2], one_row}) |
574 | 0 | end for |
575 | 0 | end procedure |
576 | ||
577 | --** | |
578 | -- Copy a rectangular block of text out of screen memory | |
579 | -- | |
580 | -- Parameters: | |
581 | -- # ##top_left## : the coordinates, given as a pair, of the upper left corner of the area to save. | |
582 | -- # ##bottom_right## : the coordinates, given as a pair, of the lower right corner of the area to save. | |
583 | -- | |
584 | -- Returns: | |
585 | -- A **sequence**, of {character, attribute, character, ...} lists. | |
586 | -- | |
587 | -- Comments: | |
588 | -- | |
589 | -- The returned value is appropriately handled by [[:display_text_image]]. | |
590 | -- | |
591 | -- This routine reads from the active text page, and only works in text modes. | |
592 | -- | |
593 | -- You might use this function in a text-mode graphical user interface to save a portion of the | |
594 | -- screen before displaying a drop-down menu, dialog box, alert box etc. | |
595 | -- | |
596 | -- Example 1: | |
597 | -- | |
598 | -- -- Top 2 lines are: Hello and World | |
599 | -- s = save_text_image({1,1}, {2,5}) | |
600 | -- | |
601 | -- -- s is something like: {"H-e-l-l-o-", "W-o-r-l-d-"} | |
602 | -- | |
603 | -- | |
604 | -- See Also: | |
605 | -- [[:display_text_image]], [[:get_screen_char]] | |
606 | ||
607 | 0 | |
608 | sequence image, row_chars, vc | |
609 | ||
610 | 0 | image = {} |
611 | 0 | for row = top_left[1] to bottom_right[1] do |
612 | 0 | row_chars = {} |
613 | 0 | for col = top_left[2] to bottom_right[2] do |
614 | 0 | row_chars &= machine_func(M_GET_SCREEN_CHAR, {row, col}) |
615 | 0 | end for |
616 | ||
617 | 0 | image = append(image, row_chars) |
618 | 0 | end for |
619 | 0 | return image |
620 | end function | |
621 | ||
622 | --** | |
623 | -- Set the number of lines on a text-mode screen. | |
624 | -- | |
625 | -- Parameters: | |
626 | -- # ##rows## : an integer, the desired number of rows. | |
627 | -- | |
628 | -- Platforms: | |
629 | -- Not //Unix// | |
630 | -- | |
631 | -- Returns: | |
632 | -- An **integer**, the actual number of text lines. | |
633 | -- | |
634 | -- Comments: | |
635 | -- Values of 25, 28, 43 and 50 lines are supported by most video cards. | |
636 | -- | |
637 | -- See Also: | |
638 | -- | |
639 | -- [[:graphics_mode]], [[:video_config]] | |
640 | ||
641 | 0 | |
642 | 0 | return machine_func(M_TEXTROWS, rows) |
643 | end function | |
644 | ||
645 | --** | |
646 | -- Select a style of cursor. | |
647 | -- | |
648 | -- Parameters: | |
649 | -- # ##style## : an integer defining the cursor shape. | |
650 | -- | |
651 | -- Platform: | |
652 | -- Not //Unix// | |
653 | -- Comments: | |
654 | -- | |
655 | -- In pixel-graphics modes no cursor is displayed. | |
656 | -- | |
657 | -- Example 1: | |
658 | -- | |
659 | -- cursor(BLOCK_CURSOR) | |
660 | -- | |
661 | -- | |
662 | -- Cursor Type Constants: | |
663 | -- * [[:NO_CURSOR]] | |
664 | -- * [[:UNDERLINE_CURSOR]] | |
665 | -- * [[:THICK_UNDERLINE_CURSOR]] | |
666 | -- * [[:HALF_BLOCK_CURSOR]] | |
667 | -- * [[:BLOCK_CURSOR]] | |
668 | -- | |
669 | -- See Also: | |
670 | -- [[:graphics_mode]], [[:text_rows]] | |
671 | -- | |
672 | ||
673 | 0 | |
674 | 0 | machine_proc(M_CURSOR, style) |
675 | 0 | end procedure |
676 | ||
677 | --** | |
678 | -- Free (delete) any console window associated with your program. | |
679 | -- | |
680 | -- Comments: | |
681 | -- Euphoria will create a console text window for your program the first time that your | |
682 | -- program prints something to the screen, reads something from the keyboard, or in some | |
683 | -- way needs a console. On WIN32 this window will automatically disappear when your program | |
684 | -- terminates, but you can call free_console() to make it disappear sooner. On Linux or FreeBSD, | |
685 | -- the text mode console is always there, but an xterm window will disappear after Euphoria | |
686 | -- issues a "Press Enter" prompt at the end of execution. | |
687 | -- | |
688 | -- On Unix-style systems, ##free_console##() will set the terminal parameters back to normal, | |
689 | -- undoing the effect that curses has on the screen. | |
690 | -- | |
691 | -- In an xterm window, a call to ##free_console##(), without any further | |
692 | -- printing to the screen or reading from the keyboard, will eliminate the | |
693 | -- "Press Enter" prompt that Euphoria normally issues at the end of execution. | |
694 | -- | |
695 | -- After freeing the console window, you can create a new console window by printing | |
696 | -- something to the screen, or simply calling ##clear_screen##(), ##position##() or any other | |
697 | -- routine that needs a console. | |
698 | -- | |
699 | -- When you use the trace facility, or when your program has an error, Euphoria will | |
700 | -- automatically create a console window to display trace information, error messages etc. | |
701 | -- | |
702 | -- There's a WIN32 API routine, FreeConsole() that does something similar to | |
703 | -- free_console(). You should use ##free_console##() instead, because it lets the interpreter know | |
704 | -- that there is no longer a console to write to or read from. | |
705 | -- | |
706 | -- See Also: | |
707 | -- [[:clear_screen]] | |
708 | ||
709 | 0 | |
710 | 0 | machine_proc(M_FREE_CONSOLE, 0) |
711 | 0 | end procedure |
712 | ||
713 | ||
714 | --** | |
715 | -- Displays the supplied data on the console screen at the current cursor position. | |
716 | -- | |
717 | -- Parameters: | |
718 | -- # ##data_in## : Any object. | |
719 | -- # ##args## : Optional arguments used to format the output. Default is 1. | |
720 | -- # ##finalnl## : Optional. Determines if a new line is output after the data. | |
721 | -- Default is to output a new line. | |
722 | -- | |
723 | -- Comments: | |
724 | -- * If ##data_in## is an atom or integer, it is simply displayed. | |
725 | -- * If ##data_in## is a simple text string, then ##args## can be used to | |
726 | -- produce a formatted output with ##data_in## providing the [[:format]] string and | |
727 | -- ##args## being a sequence containing the data to be formatted. | |
728 | -- ** If the last character of ##data_in## is an underscore character then it | |
729 | -- is stripped off and ##finalnl## is set to zero. Thus ensuring that a new line | |
730 | -- is **not** output. | |
731 | -- ** The formatting codes expected in ##data_in## are the ones used by [[:format]]. | |
732 | -- It is not mandatory to use formatting codes, and if ##data_in## does not contain | |
733 | -- any then it is simply displayed and anything in ##args## is ignored. | |
734 | -- * If ##data_in## is a sequence containing floating-point numbers, sub-sequences | |
735 | -- or integers that are not characters, then ##data_in## is forwarded on to the | |
736 | -- [[:pretty_print]]() to display. | |
737 | -- ** If ##args## is a non-empty sequence, it is assumed to contain the pretty_print formatting options. | |
738 | -- ** if ##args## is an atom or an empty sequence, the assumed pretty_print formatting | |
739 | -- options are assumed to be {2}. | |
740 | -- | |
741 | -- After the data is displayed, the routine will normally output a New Line. If you | |
742 | -- want to avoid this, ensure that the last parameter is a zero. Or to put this | |
743 | -- another way, if the last parameter is zero then a New Line will **not** be output. | |
744 | -- | |
745 | -- Examples: | |
746 | -- | |
747 | -- display("Some plain text") -- Displays this string on the console plus a new line. | |
748 | -- display("Your answer:",0) -- Displays this string on the console without a new line. | |
749 | -- display("cat") | |
750 | -- display("Your answer:",,0) -- Displays this string on the console without a new line. | |
751 | -- display("") | |
752 | -- display("Your answer:_") -- Displays this string, except the '_', on the console without a new line. | |
753 | -- display("dog") | |
754 | -- display({"abc", 3.44554}) -- Displays the contents of 'res' on the console. | |
755 | -- display("The answer to [1] was [2]", {"'why'", 42}) -- formats these with a new line. | |
756 | -- display("",2) | |
757 | -- display({51,362,71}, {1}) | |
758 | -- | |
759 | -- Output would be ... | |
760 | -- {{{ | |
761 | -- Some plain text | |
762 | -- Your answer:cat | |
763 | -- Your answer: | |
764 | -- Your answer:dog | |
765 | -- { | |
766 | -- "abc", | |
767 | -- 3.44554 | |
768 | -- } | |
769 | -- The answer to 'why' was 42 | |
770 | -- "" | |
771 | -- {51'3',362,71'G'} | |
772 | -- }}} | |
773 | -- | |
774 | ||
775 | 0 | |
776 | ||
777 | 0 | if atom(data_in) then |
778 | 0 | if integer(data_in) then |
779 | 0 | printf(1, "%d", data_in) |
780 | else | |
781 | 0 | puts(1, trim(sprintf("%15.15f", data_in), '0')) |
782 | end if | |
783 | ||
784 | 0 | elsif length(data_in) > 0 then |
785 | 0 | if t_display(data_in) then |
786 | 0 | if data_in[$] = '_' then |
787 | 0 | data_in = data_in[1..$-1] |
788 | 0 | finalnl = 0 |
789 | end if | |
790 | ||
791 | 0 | puts(1, format(data_in, args)) |
792 | ||
793 | else | |
794 | 0 | if atom(args) or length(args) = 0 then |
795 | 0 | pretty_print(1, data_in, {2}) |
796 | else | |
797 | 0 | pretty_print(1, data_in, args) |
798 | end if | |
799 | end if | |
800 | else | |
801 | 0 | if equal(args, 2) then |
802 | 0 | puts(1, `""`) |
803 | end if | |
804 | end if | |
805 | ||
806 | 0 | if finalnl = 0 then |
807 | -- no new line | |
808 | 0 | elsif finalnl = -918_273_645 and equal(args,0) then |
809 | -- no new line | |
810 | else | |
811 | 0 | puts(1, '\n') |
812 | end if | |
813 | ||
814 | 0 | return |
815 | 0 | end procedure |