<html><head></head><body><div class="ydp4a83d09ayahoo-style-wrap" style="font-size: 16px;"><div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;">Hi all,</div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;">I'm playing around with ANSI code (ESC sequence) on the console. Sending an escape command is trivial such as changing text's color and background. However, getting a response isn't as easy as I thought. Here's a simple test program:</div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div><div><div><font face="courier new, courier, monaco, monospace, sans-serif">program <g class="gr_ gr_252 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" id="252" data-gr-id="252">ANSItest</g>;</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"><br></font></div><div><font face="courier new, courier, monaco, monospace, sans-serif">var</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"> s: string;</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif">begin</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"> <i>// send ESC command</i></font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"> write('Cursor position: ');</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"> write(#27'[6n');</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"> read(s);</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"> <i>// read ESC result</i></font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"> write('Received string: ');</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif"> writeln(s);</font></div><div><font face="courier new, courier, monaco, monospace, sans-serif">end.</font></div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div></div><div class="ydp4a83d09asignature"><div>The program sends <font face="courier new, courier, monaco, monospace, sans-serif"><ESC>[6n</font> command to query current cursor position and would return <font face="courier new, courier, monaco, monospace, sans-serif"><ESC>[<line>;<column>R</font> string. As the result is sent back to standard input, I think using the standard <font face="courier new, courier, monaco, monospace, sans-serif">read()</font> procedure would be enough. Unfortunately, that's not the case. Here are the problems:</div><div><br></div><div>1. <font face="courier new, courier, monaco, monospace, sans-serif">read()</font> procedure keeps waiting until the user presses return/enter key while I hope it could automatically stop reading as the input buffer gets empty. Is there a way to make <font face="courier new, courier, monaco, monospace, sans-serif">read()</font> doesn't wait for return/enter key?</div><div><br></div><div>2. <font face="courier new, courier, monaco, monospace, sans-serif">read()</font> procedure strangely doesn't read the response given by the console (into <font face="courier new, courier, monaco, monospace, sans-serif">s</font> variable) although it's clearly printed on the screen. It's proven by the last <font face="courier new, courier, monaco, monospace, sans-serif"><g class="gr_ gr_1211 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling" id="1211" data-gr-id="1211">writeln</g>(s)</font> line that produces nothing or an empty text. What's wrong with it?</div><div><br></div><div>3. The return value of an ESC command query is printed on the console. I don't want this. I want to send the ESC command silently, <g class="gr_ gr_1930 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Punctuation only-ins replaceWithoutSep" id="1930" data-gr-id="1930">fortunately</g> the standard <font face="courier new, courier, monaco, monospace, sans-serif"><g class="gr_ gr_2036 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Grammar multiReplace" id="2036" data-gr-id="2036">write</g>()</font> procedure is able to do just that. I also want to get the response value silently. Is there a way to temporarily redirect standard input into a variable?</div><div><br></div><div>Requirements:</div><div><br></div><div>– I want to avoid <font face="courier new, courier, monaco, monospace, sans-serif">CRT</font> unit as much as possible. I prefer raw pascal solution.</div><div>– The solution works across platforms, at least on Mac, Linux, and Windows.</div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;">Is it possible using standard Pascal routines?</div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;">Thank you.</div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;">Regards,</div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div>–Mr Bee<div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div></div></div></div></body></html>