0

I've just recently started delving into the blessed library for Python. My intention here was to fill the entire screen with a character. blessed luckily features a method in the Terminal class named move_xy(), allowing me to print a character anywhere I want on the screen provided a row and column 'co-ordinate'. The following is what I've done:

import blessed
import time
import os


terminal = blessed.Terminal()

time.sleep(3)
print(os.get_terminal_size())

for i in range(0,238):
    for j in range(0,67):
        print(terminal.move_xy(i,j)+"8")
        
t = input('Stopgap')

238 and 67 are not arbitrary values; 237 and 66 are outputted by os.get_terminal_size(). Upon running the program in a full-screen terminal, I instead get characters printed diagonally across the screen. Setting it instead to print(terminal.move_xy(i,j)+"8", end = '') fixes the issue

This is what I find puzzling. Why should we specify end = ''? Isnt terminal.move_xy(i,j) moving us exactly where we want on screen? So why should the default value of the end argument, \n factor into this? If I am specifying exactly where to print, why should the end argument matter exactly? I am thoroughly confused

Hash
  • 147
  • 1
  • 10
  • If `terminal.move_xy()` positions the cursor anywhere on the bottom line of the screen, then `print`'s normal newline is going to scroll the screen up by one line. There is absolutely nothing `move_xy()` could do to prevent that effect, *you* have to prevent the newline from being output. – jasonharper Dec 18 '21 at 21:42
  • @jasonharper I don't understand, how does \n scroll it up by one line? Wont it scroll the screen down by one line? Also, if it does scroll down/up, why does it affect move_xy() anyway? Won't move_xy() just position itself wherever it wants? I am not quite able to understand why it is affected by the newline Edit:Is the cause of all this because the coordinates are decided on the basis of the CURRENT window view? – Hash Dec 18 '21 at 21:55
  • The `move_xy()` did, in fact, move to the location you wanted, and then the "8" was printed at that exact location. And then `print()` produced a newline, which scrolls the screen *just like it always does*, and now the "8" is no longer in the same location. I don't see where there's any room for confusion here. – jasonharper Dec 18 '21 at 22:02
  • Maybe a helpful way to understand it is to realize that `move_xy()` is basically just going to create a string of control characters that, when "printed", do magical cursor things to move it where you want it. Then, you are just supplying the text that will continue to be printed after that. `print()` is trying to be helpful by adding a newline after that (because the newline is often useful). The newline is basically another magical control character whose job is to move the cursor down one line (and the screen up if necessary). – Luke Nelson Dec 18 '21 at 23:15
  • But since you don't want that newline, you need to tell print to not use it. – Luke Nelson Dec 18 '21 at 23:15
  • @LukeNelson But if the control character moves the cursor exactly where I want it, why does the newline affect things anyway? Is it because of the edge case jason had mentioned, in that, when I am at the bottom line of a screen, the newline scrolls the screen down thus eliminating one row at the top, and adding a row at the bottom of the screen throwing all my "coordinates" into a royal mess? – Hash Dec 19 '21 at 08:32
  • 1
    @Hash that seems like exactly what is happening. Just thats its not really an edge case, but a pretty constant phenomenon. – Luke Nelson Dec 19 '21 at 14:12
  • 1
    @LukeNelson I see, I've got it now, thank you! – Hash Dec 19 '21 at 15:51

0 Answers0