-2

How can I print to the terminal messages that will be pinned to the top or bottom on the terminal console?

Thanks !

t_man222
  • 1
  • 1
  • 1
    Please show some effort in resolving this task yourself before asking us. We're not a coding service. – Torxed May 19 '20 at 07:48
  • Trust me I searched before I asked Since I couldn't find it, I decided to ask here – t_man222 May 20 '20 at 08:36
  • That's good, but it doesn't show at all in the question, so how would we know? We might recommend solutions you've already tried, so if possible include things you've tried and show us the effort so we better understand the problem. – Torxed May 20 '20 at 09:53

2 Answers2

0

You can use curses module to make a pinned message I found this solution in an already asked question here I believe you can add your string in the window.addstr function

import time
import curses

def pbar(window):
    height, width = window.getmaxyx()
    for i in range(10):
        window.addstr(height -1, 0, "[" + ("=" * i) + ">" + (" " * (10 - i )) + "]")
        window.refresh()
        time.sleep(0.5)

curses.wrapper(pbar)
MrKioZ
  • 515
  • 4
  • 14
0

You can get the terminal size you are running your code with help of the os module:

import os

def ptb(top_text, bottom_text):
    ts = os.get_terminal_size()
    n = ts.lines()
    os.system('clear') # Linux terminal only
    print(top_text + '\n'*(n-2) + bottom_text)
AnsFourtyTwo
  • 2,480
  • 2
  • 13
  • 33