using printf with \r help

username
Posts: 563
Joined: Thu May 03, 2018 1:18 pm

using printf with \r help

Postby username » Fri Dec 13, 2024 5:03 am

when I printf using the \r option only nothing goes to the terminal.
I want to be able to print on the same line without a CR.

for (int i = 10; i >= 0; i--) {
printf("Restarting in %d seconds...\r", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}

This prints nothing, even if I use fflush(stdout); after the printf.

Anyone have any ideas to do this ?

Dennie
Posts: 7
Joined: Fri Aug 30, 2024 2:22 am

Re: using printf with \r help

Postby Dennie » Fri Dec 13, 2024 8:19 am

Maybe you can try ESP_LOGI() instead of printf(). (but my printf() is fine).

MicroController
Posts: 2045
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: using printf with \r help

Postby MicroController » Fri Dec 13, 2024 2:53 pm

You can try ANSI codes, like

Code: Select all

printf("... \033[1G"); // Move cursor to column 1

username
Posts: 563
Joined: Thu May 03, 2018 1:18 pm

Re: using printf with \r help

Postby username » Fri Dec 13, 2024 8:57 pm

Maybe you can try ESP_LOGI() instead of printf(). (but my printf() is fine).
ESP_LOGI() wont work because all the ESP_LOGx's slap a CR at the end of what your printing.

printf("... \033[1G"); // Move cursor to column 1
Thanks, but the issue is without the \n the uart never shoots anything out. It gets buffered to some length, and when that buffer gets full everything gets dumped at once. I need a way to force the uart to dump what it has.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 125 guests