www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to change text while running in console?

reply "Israel" <tl12000 live.com> writes:
I remember doing this in C++ and it worked but is this possible 
in D?

Its basically updating information in the console window without 
constantly printing new lines.

http://stackoverflow.com/questions/14043148/how-to-change-text-while-running-the-console
Apr 26 2015
next sibling parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Monday, 27 April 2015 at 02:26:01 UTC, Israel wrote:
 I remember doing this in C++ and it worked but is this possible 
 in D?

 Its basically updating information in the console window 
 without constantly printing new lines.

 http://stackoverflow.com/questions/14043148/how-to-change-text-while-running-the-console
write(info, "\r"); stdout.flush(); E.g. with percent: writef("%d%%\r", current * 100 / total); stdout.flush();
Apr 26 2015
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Monday, 27 April 2015 at 02:30:36 UTC, Vladimir Panteleev
wrote:
 writef("%d%%\r", current * 100 / total); stdout.flush();
I'd prolly put a width specifier on it like %3d because otherwise if it was 100 percent then went to 99, the third digit wouldn't be erased.
Apr 26 2015
prev sibling parent "Israel" <tl12000 live.com> writes:
On Monday, 27 April 2015 at 02:30:36 UTC, Vladimir Panteleev 
wrote:
 On Monday, 27 April 2015 at 02:26:01 UTC, Israel wrote:
 I remember doing this in C++ and it worked but is this 
 possible in D?

 Its basically updating information in the console window 
 without constantly printing new lines.

 http://stackoverflow.com/questions/14043148/how-to-change-text-while-running-the-console
write(info, "\r"); stdout.flush(); E.g. with percent: writef("%d%%\r", current * 100 / total); stdout.flush();
Thank you guys it works. Even with the percent sign. write(sumincrease, "%", "\r"); stdout.flush();
Apr 26 2015
prev sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Monday, 27 April 2015 at 02:26:01 UTC, Israel wrote:
 I remember doing this in C++ and it worked but is this possible 
 in D?
Have you tried it yet? The solution is basically the same, you just write out the carriage return character to the device.
Apr 26 2015
parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Monday, 27 April 2015 at 02:32:17 UTC, Adam D. Ruppe wrote:
 On Monday, 27 April 2015 at 02:26:01 UTC, Israel wrote:
 I remember doing this in C++ and it worked but is this 
 possible in D?
Have you tried it yet? The solution is basically the same, you just write out the carriage return character to the device.
You also need to flush the FILE buffer, as C stdio will do that for you only if the string contains a \n character.
Apr 26 2015