Control of printing

Jan 18, 2017 3 Replies

I am working my way through a series of tutorials for the P1 one of which reads data through the serial i2c bus and using the pcf8591 chip and module. The system works OK outputting the reading to the terminal and generating a long column of readings. What I am seeking to do is print the output to single screen position, overwriting the earlier reading each time. How does one achieve this in Python. Can anyone give me a steer?



Malcolm Smith


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

On Wed, 18 Jan 2017 22:48:49 GMT, T M Smith declaimed the following:

Depends a bit on the features of the terminal/console.

Many will return to the left of the current row if sent a simple carriage return ("\r") rather than a newline ("\n") (which typically acts as the combination of ).

Above that, if the terminal/console understands ANSI (or VT-52/-100) control codes one can send escape sequences to position to any location on the window.

formatting link

formatting link
formatting link

{Apologies for the M$ Windows links, but that's part of the "if the ... understands ANSI" aspect}

If neither of these suffice, you may be entering the realms of creating a full fledged GUI application (pick the framework of your choice).

Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

Thank you for the info Dennis That looks to be nearer the mark than everything else I have tried. Will now do some trials.

Malcolm

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

Depends what language you're writing the display program in and whether you're writing to a text console or not.

As others have said, if you're happy to merely overwrite a single line on a 24x80 terminal then emitting the '\r' (CR) character is likely to work in almost any language.

Going beyond that depends what programming language you're writing in because most have their own terminal management packages: for instance, if you're writing in C then you'll almost certainly want to have a look at the ncurses package, which is available as a Raspbian package, and there's a slim O'Reilly book "Printing with Curses" if you need a tutorial. IIRC the 'top' monitoring program uses curses for its display and so do a number of text editors.

If you want something a bit more generalised and capable of displaying on a desktop, have a look at GTK+.

martin@ | Martin Gregorie gregorie. | Essex, UK org |

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required