Thread overview
How to update terminal output?
Mar 28, 2021
dog2002
Mar 28, 2021
Mark Lagodych
Mar 28, 2021
Adam D. Ruppe
Mar 28, 2021
dog2002
Mar 28, 2021
Zardoz
Mar 28, 2021
Jack
March 28, 2021
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.
March 28, 2021
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.
March 28, 2021
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
March 28, 2021
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.
March 28, 2021
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.
March 28, 2021
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