www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to update terminal output?

reply dog2002 <742617000027 aaathats3as.com> writes:
I mean, I want to write a string without a new line. For example, 
some command line applications have progress bars.

For a single line string I use \r. But it doesn't work for a 
multiple line string - the application is just adding new lines.
Mar 28 2021
next sibling parent reply Mark Lagodych <lgd.mrk gmail.com> writes:
On Sunday, 28 March 2021 at 16:45:29 UTC, dog2002 wrote:
 I mean, I want to write a string without a new line. For 
 example, some command line applications have progress bars.

 For a single line string I use \r. But it doesn't work for a 
 multiple line string - the application is just adding new lines.
See http://www.climagic.org/mirrors/VT100_Escape_Codes.html Basically, you just need to do this: writeln("\033[" ~ cmd); where cmd is your VT100 command and \033 is an Escape character. Although some (all?) of that commands do not work in the Windows terminal. For instance, you can change background color ONLY using Windows API.
Mar 28 2021
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 28 March 2021 at 17:13:02 UTC, Mark Lagodych wrote:
 Although some (all?) of that commands do not work in the 
 Windows terminal. For instance, you can change background color 
 ONLY using Windows API.
Windows can support them all if you enable the setting. but yeah anything outside the current line needs these sequences and/or the right api calls.
Mar 28 2021
prev sibling parent dog2002 <742617000027 aaathats3as.com> writes:
On Sunday, 28 March 2021 at 17:13:02 UTC, Mark Lagodych wrote:
 On Sunday, 28 March 2021 at 16:45:29 UTC, dog2002 wrote:
 I mean, I want to write a string without a new line. For 
 example, some command line applications have progress bars.

 For a single line string I use \r. But it doesn't work for a 
 multiple line string - the application is just adding new 
 lines.
See http://www.climagic.org/mirrors/VT100_Escape_Codes.html Basically, you just need to do this: writeln("\033[" ~ cmd); where cmd is your VT100 command and \033 is an Escape character. Although some (all?) of that commands do not work in the Windows terminal. For instance, you can change background color ONLY using Windows API.
Thank you. Seems like \033[<n>A\r does work.
Mar 28 2021
prev sibling next sibling parent Zardoz <luis.panadero gmail.com> writes:
On Sunday, 28 March 2021 at 16:45:29 UTC, dog2002 wrote:
 I mean, I want to write a string without a new line. For 
 example, some command line applications have progress bars.

 For a single line string I use \r. But it doesn't work for a 
 multiple line string - the application is just adding new lines.
You must use ANSI control codes to repositionate the cursor or use a library like ncurses that handle this kind of stuff. https://code.dlang.org/search?q=ncurses In particular , nice-curses have a class to generate a TUI progress bar
Mar 28 2021
prev sibling parent Jack <jckj33 gmail.com> writes:
On Sunday, 28 March 2021 at 16:45:29 UTC, dog2002 wrote:
 I mean, I want to write a string without a new line. For 
 example, some command line applications have progress bars.

 For a single line string I use \r. But it doesn't work for a 
 multiple line string - the application is just adding new lines.
you have to erase the line when you're about to display a new progress percent. On UNIX system, you have to use character terminal escapes[1] on window you have to dig the console API[2] or you can just use ncurse library[3][4] [1]: https://web.archive.org/web/20200415203148/http://ascii-table.com/ansi-escape-sequences-vt-100.php [2]: https://docs.microsoft.com/en-us/windows/console/console-reference [3]: https://invisible-island.net/ncurses/announce.html [4]: https://code.dlang.org/search?q=ncurses
Mar 28 2021