]> git.8kb.co.uk Git - dataflex/df32func/blob - src/df32/console.inc
Just pushing the latest copy of my development / staging DataFlex stuff into git...
[dataflex/df32func] / src / df32 / console.inc
1 //-------------------------------------------------------------------------\r
2 // console.inc\r
3 //      This file contains some DataFlex 3.2 Console Mode functions\r
4 //      to manipulate console window.\r
5 //\r
6 // This file is to be included in df32func.mk\r
7 //\r
8 // Copyright (c) 2006-2015, glyn@8kb.co.uk\r
9 // \r
10 // df32func/console.inc\r
11 //-------------------------------------------------------------------------\r
12 \r
13 #IFDEF __console_h__\r
14 #ELSE\r
15     #INCLUDE console.h\r
16 #ENDIF\r
17 \r
18 //-------------------------------------------------------------------------\r
19 // Global objects\r
20 //-------------------------------------------------------------------------            \r
21 \r
22 // Global StringTokenizer used to store "font blocks" for large text\r
23 object font_split is a StringTokenizer\r
24 end_object\r
25 \r
26 //-------------------------------------------------------------------------\r
27 // Functions\r
28 //-------------------------------------------------------------------------\r
29 \r
30 // Set the display mode to argv lines\r
31 function set_mode global integer argv returns integer\r
32     local string l_01tmpStr\r
33 \r
34     if (sysconf(sysconf_os_name)) eq "Win32 Console Mode" move "c:\windows\system32\mode con: cols=80 lines=" to l_01tmpStr\r
35     if (sysconf(sysconf_os_name)) ne "Win32 Console Mode" move "c:\windows\command\mode con: cols=80 lines=" to l_01tmpStr\r
36 \r
37     append l_01tmpStr argv\r
38     runprogram wait l_01tmpStr\r
39 \r
40     function_return 0\r
41 end_function\r
42 \r
43 // Display a text file to screen\r
44 function screen_display global string argv returns integer\r
45     local string l_sBuf l_k l_sTmp\r
46     local integer l_i l_iLineAt l_iTotalLines l_iTotalWidth l_iWidthAt\r
47 \r
48     // Add color markup here.    \r
49     move 1 to l_iWidthAt\r
50     move 0 to l_iLineAt\r
51     move 0 to l_iTotalLines\r
52     move 0 to l_iTotalWidth\r
53 \r
54     direct_input channel DEFAULT_FILE_CHANNEL argv   \r
55     while not (seqeof)\r
56         readln channel DEFAULT_FILE_CHANNEL l_sBuf\r
57         move (rtrim(l_sBuf)) to l_sbuf\r
58         move (replaces("{YELLOW}",l_sBuf,"")) to l_sBuf\r
59         move (replaces("{WHITE}",l_sBuf,"")) to l_sBuf\r
60         move (replaces("{RED}",l_sBuf,"")) to l_sBuf\r
61         move (replaces("{GREEN}",l_sBuf,"")) to l_sBuf\r
62         move (replaces("{BLUE}",l_sBuf,"")) to l_sBuf\r
63         move (replaces("{PURPLE}",l_sBuf,"")) to l_sBuf\r
64         move (replaces("{GREY}",l_sBuf,"")) to l_sBuf\r
65         move (replaces("{BLACK}",l_sBuf,"")) to l_sBuf\r
66         if (length(l_sBuf) > l_iTotalWidth) move ((length(l_sBuf))+1) to l_iTotalWidth\r
67         increment l_iTotalLines\r
68     loop\r
69     close_input channel DEFAULT_FILE_CHANNEL \r
70 \r
71     while not (key.escape)\r
72         direct_input channel DEFAULT_FILE_CHANNEL argv\r
73             for l_i from 1 to l_iLineAt\r
74                 readln channel DEFAULT_FILE_CHANNEL \r
75             loop\r
76             for l_i from 1 to 22\r
77                 readln channel DEFAULT_FILE_CHANNEL l_sBuf\r
78                 gotoxy (l_i-1) 0\r
79 \r
80                     if (uppercase(l_sBuf) contains "{YELLOW}") begin\r
81                         move (replaces("{YELLOW}",l_sBuf,"")) to l_sBuf\r
82                         screenmode 1\r
83                     end\r
84                     if (uppercase(l_sBuf) contains "{WHITE}") begin\r
85                         move (replaces("{WHITE}",l_sBuf,"")) to l_sBuf\r
86                         screenmode 2\r
87                     end\r
88                     if (uppercase(l_sBuf) contains "{RED}") begin\r
89                         move (replaces("{RED}",l_sBuf,"")) to l_sBuf\r
90                         screenmode 28\r
91                     end\r
92                     if (uppercase(l_sBuf) contains "{GREEN}") begin\r
93                         move (replaces("{GREEN}",l_sBuf,"")) to l_sBuf\r
94                         screenmode 26\r
95                     end\r
96                     if (uppercase(l_sBuf) contains "{BLUE}") begin\r
97                         move (replaces("{BLUE}",l_sBuf,"")) to l_sBuf\r
98                         screenmode 19\r
99                     end\r
100                     if (uppercase(l_sBuf) contains "{PURPLE}") begin\r
101                         move (replaces("{PURPLE}",l_sBuf,"")) to l_sBuf\r
102                         screenmode 29\r
103                     end\r
104                     if (uppercase(l_sBuf) contains "{GREY}") begin\r
105                         move (replaces("{GREY}",l_sBuf,"")) to l_sBuf\r
106                         screenmode 24\r
107                     end\r
108                     if (uppercase(l_sBuf) contains "{BLACK}") begin\r
109                         move (replaces("{BLACK}",l_sBuf,"")) to l_sBuf\r
110                         screenmode 16\r
111                     end\r
112 \r
113                 show (pad(mid(l_sBuf,80,l_iWidthAt),80))\r
114                 screenmode 1\r
115             loop\r
116         close_input channel DEFAULT_FILE_CHANNEL        \r
117     \r
118         move "lines " to l_sTmp\r
119         append l_sTmp (l_iLineAt+1) "-" (l_iLineAt+22) " of " (l_iTotalLines)\r
120         if (l_iTotalLines < (l_iLineAt+22)) begin\r
121             move "lines " to l_sTmp\r
122             append l_sTmp (l_iLineAt+1) "-" (l_iTotalLines) " of " (l_iTotalLines)\r
123         end\r
124         gotoxy 23 0\r
125         screenmode 112\r
126         show (center(l_sTmp,80)) \r
127         screenmode 1\r
128         \r
129         gotoxy 26 0\r
130         inkey l_k\r
131         if (key.up) begin\r
132             if (l_iLineAt <> 0) decrement l_iLineAt\r
133         end\r
134         if (key.down) begin\r
135             if ((l_iLineAt+22) < l_iTotalLines) increment l_iLineAt\r
136         end\r
137         if ((ascii(l_k)) = 34) begin\r
138             calc (l_iLineAt-22) to l_iLineAt\r
139             if (l_iLineAt < 0) move 0 to l_iLineAt\r
140         end\r
141         if ((ascii(l_k)) = 35) begin\r
142             calc (l_iLineAt+22) to l_iLineAt\r
143             if (l_iLineAt > (l_iTotalLines-22)) begin\r
144                 move (l_iTotalLines-22) to l_iLineAt\r
145             end\r
146         end\r
147         if ((ascii(l_k)) = 44) begin\r
148             move 0 to l_iLineAt\r
149         end\r
150         if ((ascii(l_k)) = 45) begin\r
151             calc (l_iTotalLines-22) to l_iLineAt\r
152         end\r
153         if ((ascii(l_k)) = 4) begin\r
154             if (l_iWidthAt <> 1) decrement l_iWidthAt\r
155         end\r
156         if ((ascii(l_k)) = 5) begin\r
157             if ((l_iWidthAt+80) <= l_iTotalWidth) increment l_iWidthAt\r
158         end\r
159     loop\r
160 end_function\r
161 \r
162 // Draw a large character in a dos window\r
163 function draw_bigchar global string argv integer posx integer posy returns integer\r
164     local integer l_onCount l_i l_iChars\r
165     local string l_c\r
166     move 0 to l_onCount\r
167     move (uppercase(argv)) to argv\r
168     \r
169     send delete_data to (font_split(current_object))\r
170     send set_string to (font_split(current_object)) argv ","\r
171     get token_count of (font_split(current_object)) to l_iChars\r
172     \r
173     for l_i from 0 to (l_iChars+1)\r
174         get token_value of (font_split(current_object)) item l_i to l_c\r
175         if ((integer(l_c)) = 1) increment l_onCount\r
176         if (l_i < 8) begin\r
177             gotoxy posx (posy+l_i)\r
178             if ((integer(l_c)) = 0) show (character(32))\r
179             if ((integer(l_c)) = 1) show (character(219))\r
180         end\r
181         if ((l_i >= 8) and (l_i < 16)) begin\r
182             gotoxy (posx+1) (posy+l_i-8)\r
183             if ((integer(l_c)) = 0) show (character(32))\r
184             if ((integer(l_c)) = 1) show (character(219))\r
185         end\r
186         if ((l_i >= 16) and (l_i < 24)) begin\r
187             gotoxy (posx+2) (posy+l_i-16)\r
188             if ((integer(l_c)) = 0) show (character(32))\r
189             if ((integer(l_c)) = 1) show (character(219))\r
190         end\r
191         if ((l_i >= 24) and (l_i < 32)) begin\r
192             gotoxy (posx+3) (posy+l_i-24)\r
193             if ((integer(l_c)) = 0) show (character(32))\r
194             if ((integer(l_c)) = 1) show (character(219))\r
195         end\r
196         if ((l_i >= 32) and (l_i <= 40)) begin\r
197             gotoxy (posx+4) (posy+l_i-32)\r
198             if ((integer(l_c)) = 0) show (character(32))\r
199             if ((integer(l_c)) = 1) show (character(219))\r
200         end\r
201     loop\r
202     \r
203     function_return l_onCount\r
204 end_function\r
205 \r
206 // Draw large text in a dos window\r
207 function big_text global string argv integer posx integer posy returns integer\r
208     local integer l_iResult l_i\r
209     local string l_tmpStr\r
210 \r
211     for l_i from 1 to  (length(argv))\r
212         move (mid(argv,1,l_i)) to l_tmpStr\r
213         get array_value of (font_array(current_object)) item (ascii(l_tmpStr)) to l_tmpStr\r
214         move (draw_bigchar(l_tmpStr,posx,(posy+((l_i-1)*9)))) to l_iResult\r
215     loop\r
216     function_return l_i\r
217 end_function\r