2

I am using blessings (or blessed) to try to print in the same spot in a for-loop. However, I find that this only works if I print 3 above the bottom of the terminal, but if I print 1 or two lines above the bottom it prints a new line for each iteration...

For y=term.height-3:

from blessed import Terminal

term = Terminal()
print()
print()
for i in range(0,999999999):

    with term.location(y=term.height-2):

        print('Here is the bottom.')

This code prints this:

Here is the bottom.

It does that for every iteration.

BUT, if I change the print location to

with term.location(y=term.height-1):

It does this

Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.

and so on and so on.. why is this?

1 Answers1

0

Height of terminal is exclusive: [0,N] => N+1
Let's take N = 3 for simplicity

0 >
1 >
2 >
3 >

term.height = 4
term.height - 1 = 3
results in

0 > hidden to keep height = 4 and because you wrote on line 4
1 > 
2 >
3 > (3,1)
4 > Bottom is here

Now let's do it again, we have this

1 > 
2 >
3 > (3,1)
4 > Bottom is here

In height results in

[1] 0 > 
[2] 1 >
[3] 2 > (3,1)
[4] 3 > Bottom is here

And you print at line 3

[1] 0 > hidden to keep height = 4 and because you wrote on line 4
[2] 1 >
[3] 2 > (3,1)
[4] 3 > (3,1)
[5] 4 > Bottom is here
IQbrod
  • 2,060
  • 1
  • 6
  • 28
  • 1
    I'm still confused as to why the program doesn't just print in one spot and instead pushes the previous print statements up – User56789087654356789 Aug 08 '19 at 15:01
  • You print two lines on the last lines 3 & 4, so your terminal scroll down from 1 to 4 with last two lines written normally, then you do it again and write lines 4 & 5 with a terminal between 2 and 5, but 1 has still your text written. And so on... – IQbrod Aug 08 '19 at 15:08