User Interface Suggestions? (newbie)

Grant Edwards grant.b.edwards at gmail.com
Thu Oct 6 13:07:40 EDT 2016


On 2016-10-06, BartC <bc at freeuk.com> wrote:

> 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.

It can run Linux.  Whether the OP's is or not, I don't know.

> 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.

Yes.

> Something like an escape sequence. Terminal screens have been around
> a long time, you'd think someone would have had such a requirement
> before!

Yes, they did.  They wrote the curses library.

> 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.

That doesn't look like an ANSI terminal escape sequence to me -- but I
have no idea what terminal type you're using, so I can't tell you
whether it's right or not.

The ANSI seqeunce to move the cursor to row 1, column 1, is
'<esc>[1;1m'.  Both positions default to 1, so '<esc>[m' does the same
thing.

> 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?!)

Curses knows how to deal with various different terminal types and it
also knows about the intracacies of the Unix tty API.

If you want to, you can just assume your terminal uses ANSI escape
sequences:

  https://en.wikipedia.org/wiki/ANSI_escape_code

That will mostly work on most terminals you run into these days.

If you want to go one step further, you can use the terminfo library
to deal with different terminal types, but I have no idea how to use
it without ncurses.  If people care about their programs working with
different terminal types, they use ncurses.

-- 
Grant Edwards               grant.b.edwards        Yow! !  Up ahead!  It's a
                                  at               DONUT HUT!!
                              gmail.com            




More information about the Python-list mailing list