[Tutor] clearing lines for a 'front end' to a tool

James jtp at nc.rr.com
Mon Sep 15 22:22:10 CEST 2008


All,

I'm writing a rather complex script which will preform quite a number
of complex file system tasks in the background. The program is
threaded and almost fully automated.

I'm writing a 'front end' which will show a list of the "things" that
are currently happening in the background in a simple
(non-interactive) interface. Here's an idea of what the terminal will
look like when the program is running.

>>> verifying file system contents
>>> starting parallel background process(es)
>>> (job 1 of 5) backing up file system
>>> (job 2 of 5) generating new content
>>> Jobs: 0 of 5 complete, 2 running                        Load avg: 0.40, 0.27, 0.24

The trick here is "blocking" actions and how the output will be
modified when another task starts up. Let's say that job 1 finishes;
the output will look like this:

>>> verifying file system contents
>>> starting parallel background process(es)
>>> (job 1 of 5) backing up file system
>>> (job 2 of 5) generating new content
>>> Done generating new content
>>> (job 3 or 5) putting content in correct subdirectories
>>> (job 4 of 5) tweaking new content for system
>>> Jobs: 1 of 5 complete, 3 running                        Load avg: 0.8, 0.41, 0.2

As can be seen from the output above, when the first "blocking" job is
done (2 of 5), certain other threads can be kicked off.

The question here is mostly about how to generate this output. The
bottom line (the 'status') *always* remains at the bottom of the
screen. The other processes are updated in 'real time', so when job 2
was done, a "Done generating new content" line appeared, and the lines
indicating jobs 3 and 4 appeared (while, again, the status line
remained at the bottom).

I'm unsure how to go about doing this... I imagine that the ANSI
"clear line" value may be helpful, but I haven't had much luck getting
that to work as I'd like. Curses seems like overkill in a situation
like this.

Any thoughts on how to best accomplish my goal?

Thanks!
-j


More information about the Tutor mailing list