TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: RICKMAN
from: T M SMITH
date: 2017-10-24 23:16:00
subject: Re: Screen control

In message 
          rickman  wrote:

> Big Bad Bob wrote on 10/23/2017 2:57 AM:
>> On 10/21/17 13:04, T M Smith wrote:
>>> I am sure this is elementary to most but bear with me please.
>>> I am using Raspbian on a pi. How does one get a reading to print on
>>> screen in the same place on a continueing basis rather than printing
>>> on a new line and scrolling.
>>>
>>
>> if you're running this in a console, check out how 'curses' works.  You can
>> also try the VT ANSI escape sequences yourself.
>>
>> you can also send a 'home' cursor to the screen to overwrite the same line
>> over and over...
>>
>> https://en.wikipedia.org/wiki/ANSI_escape_code
>>
>> I think the right sequence for 'home cursor' is:
>>
>> [1G
>>
>> in C code it would be:
>>
>> "\x1b[1G"
>>
>> so don't do a line feed '\n' at the end, but do THAT instead, and I think
>> the line will overwrite itself.  That's what you wanted, right?
>>
>> (I've done this before but I don't have the code in front of me at the
>> moment)
>>
>> OK curiosity bugs me now and so I wrote this:
>>
>>
>>
>> #include 
>> #include 
>>
>> int main()
>> {
>> int i1;
>>
>>   for(i1=0; i1 < 500; i1++)
>>   {
>>     printf("Here I am: %d    \x1b[1G", i1);
>>     fflush(stdout);
>>     usleep(100000);
>>   }
>> }
>>
>>
>>
>> try it, you'll like it!

> When updating a value you are displaying, don't forget to consider
> formatting of the result.  If your numbers change from 3 digits to 2 digits
> for example, the last digit of the previous value won't be overwritten
> unless you use a fixed width format with spaces in front for shorter numbers.
Thanks for making that point Rick.
And thanks to everyone who contributed.

Malcolm Smith


--
T M Smith
Using an ARMX6 and RISC OS 5.21 in the North Riding of Yorkshire

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.