User Interface Suggestions? (newbie)

BartC bc at freeuk.com
Thu Oct 6 07:03:37 EDT 2016


On 05/10/2016 23:12, Akira Li wrote:
> Beverly Howard <bev at bevhoward.com> writes:
>
>> ...snip...
>> A primary question would be, "What are options for building a display
>> that would update displayed values without scrolling?"
>
> To rewrite only the last character, you could use '\b':
>
>   import os
>   import itertools
>   import time
>   for c in map(str.encode, itertools.cycle('\-/|')):
>       os.write(1, b'\b'+c)
>       time.sleep(.3)
>
> To rewrite only the last line, you could use '\r':
>
>   for i in range(1, 101):
>       time.sleep(.1)
>       print('\r{:4.0%}'.format(i/100), flush=True, end='')
>
> To control the full screen in the terminal e.g., to change the position,
> you could use *blessings* module [1]:
>
>   from blessings import Terminal  # $ pip install blessings
>
>   line = 'Line in the middle of the terminal.'
>   term = Terminal()
>   with term.hidden_cursor(), term.fullscreen():
>       x = (term.width - len(line)) // 2
>       y = (term.height - 1) // 2
>       with term.location(x, y):
>           print(term.bold_white_on_black(line))
>
>       with term.location(0, term.height - 1):
>           input('press <Enter> to exit..')
>
> For interactive command-line applications from a simple prompt to full
> screen terminal applications, you could use *prompt_toolkit* module [2].
>
>> My first goal is to build a program that would interface with a
>> Raspberry Pi to control a heating process.
>>
>
> For flexibility, you could split your program into a server and a client
> that controls it (text, GUI, web).

All this advice seems to be getting out of hand, with suggestions of 
'curses' and 'blessings' and using GUI. I've tried 'ncurses' elsewhere 
and it was over the top for what I wanted to do.

The OP wants to runs on Pi which I think runs Linux.

So all they are asking is, is there a way of randomly positioning the 
cursor within the terminal window so that the next output is at that 
position. Something like an escape sequence. Terminal screens have been 
around a long time, you'd think someone would have had such a 
requirement before!

I'd quite like to know too. However I've just tried a test sequence 
("<esc>[P1d" to move the cursor to row 1) and it didn't work. If there's 
reason why something so basic won't work (hence the need for curses etc) 
then that would be useful to know too. (And how does curses manage it?!)

-- 
Bartc



More information about the Python-list mailing list