Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses
- from curses import wrapper
- from curses.textpad import Textbox, rectangle
- class Window():
- def __init__(self, height, width, start_y, start_x):
- self.height = height
- self.width = width
- self.start_y = start_y
- self.start_x = start_x
- def update(self, h, w, sy, sx):
- self.height = h
- self.width = w
- self.start_y = sy
- self.start_x = sx
- class Ui():
- def __init__(self, stdscr):
- self.stdscr = stdscr
- self.y, self.x = self.stdscr.getmaxyx()
- self.sb_dim = Window(self.y - 3, self.x // 5, 1, 1)
- self.side_bar = curses.newwin(self.sb_dim.height, self.sb_dim.width, self.sb_dim.start_y, self.sb_dim.start_x)
- self.user_text = None
- def run(self):
- self.print_screen()
- while True:
- c = self.stdscr.getch()
- if c == ord('q'):
- break
- elif c == curses.KEY_RESIZE:
- try:
- self.resize()
- self.print_screen()
- except Exception as e:
- print(e)
- def resize(self):
- self.y, self.x = self.stdscr.getmaxyx()
- self.sb_dim.update(self.y - 3, self.x // 5, 1, 1)
- def print_screen(self):
- self.stdscr.clear()
- self.stdscr.addstr(0, 1, f"{self.x}, {self.y}")
- rectangle(self.stdscr, self.sb_dim.start_y, self.sb_dim.start_x, self.sb_dim.height, self.sb_dim.width)
- self.stdscr.refresh()
- def main(stdscr):
- ui = Ui(stdscr)
- ui.run()
- if __name__ == "__main__":
- wrapper(main)
Advertisement
Add Comment
Please, Sign In to add comment