1 //-------------------------------------------------------------------------
\r
3 // This file contains some DataFlex 3.2 Console Mode functions
\r
4 // to manipulate console window.
\r
6 // This file is to be included in df32func.mk
\r
8 // Copyright (c) 2006-2015, glyn@8kb.co.uk
\r
10 // df32func/console.inc
\r
11 //-------------------------------------------------------------------------
\r
13 #IFDEF __console_h__
\r
18 //-------------------------------------------------------------------------
\r
20 //-------------------------------------------------------------------------
\r
22 // Global StringTokenizer used to store "font blocks" for large text
\r
23 object font_split is a StringTokenizer
\r
26 //-------------------------------------------------------------------------
\r
28 //-------------------------------------------------------------------------
\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
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
37 append l_01tmpStr argv
\r
38 runprogram wait l_01tmpStr
\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
48 // Add color markup here.
\r
49 move 1 to l_iWidthAt
\r
51 move 0 to l_iTotalLines
\r
52 move 0 to l_iTotalWidth
\r
54 direct_input channel DEFAULT_FILE_CHANNEL argv
\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
69 close_input channel DEFAULT_FILE_CHANNEL
\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
76 for l_i from 1 to 22
\r
77 readln channel DEFAULT_FILE_CHANNEL l_sBuf
\r
80 if (uppercase(l_sBuf) contains "{YELLOW}") begin
\r
81 move (replaces("{YELLOW}",l_sBuf,"")) to l_sBuf
\r
84 if (uppercase(l_sBuf) contains "{WHITE}") begin
\r
85 move (replaces("{WHITE}",l_sBuf,"")) to l_sBuf
\r
88 if (uppercase(l_sBuf) contains "{RED}") begin
\r
89 move (replaces("{RED}",l_sBuf,"")) to l_sBuf
\r
92 if (uppercase(l_sBuf) contains "{GREEN}") begin
\r
93 move (replaces("{GREEN}",l_sBuf,"")) to l_sBuf
\r
96 if (uppercase(l_sBuf) contains "{BLUE}") begin
\r
97 move (replaces("{BLUE}",l_sBuf,"")) to l_sBuf
\r
100 if (uppercase(l_sBuf) contains "{PURPLE}") begin
\r
101 move (replaces("{PURPLE}",l_sBuf,"")) to l_sBuf
\r
104 if (uppercase(l_sBuf) contains "{GREY}") begin
\r
105 move (replaces("{GREY}",l_sBuf,"")) to l_sBuf
\r
108 if (uppercase(l_sBuf) contains "{BLACK}") begin
\r
109 move (replaces("{BLACK}",l_sBuf,"")) to l_sBuf
\r
113 show (pad(mid(l_sBuf,80,l_iWidthAt),80))
\r
116 close_input channel DEFAULT_FILE_CHANNEL
\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
126 show (center(l_sTmp,80))
\r
132 if (l_iLineAt <> 0) decrement l_iLineAt
\r
134 if (key.down) begin
\r
135 if ((l_iLineAt+22) < l_iTotalLines) increment l_iLineAt
\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
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
147 if ((ascii(l_k)) = 44) begin
\r
148 move 0 to l_iLineAt
\r
150 if ((ascii(l_k)) = 45) begin
\r
151 calc (l_iTotalLines-22) to l_iLineAt
\r
153 if ((ascii(l_k)) = 4) begin
\r
154 if (l_iWidthAt <> 1) decrement l_iWidthAt
\r
156 if ((ascii(l_k)) = 5) begin
\r
157 if ((l_iWidthAt+80) <= l_iTotalWidth) increment l_iWidthAt
\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
166 move 0 to l_onCount
\r
167 move (uppercase(argv)) to argv
\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
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
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
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
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
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
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
203 function_return l_onCount
\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
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
216 function_return l_i
\r