import curses import time # Using readlines() file1 = open("test", "r") lines = file1.readlines() debug_text = False def show_debug_text(stdscr, width, height, start_x_file): """debug text for the tomb of doom""" whstr = "Width: {}, Height: {}".format(width, height) stdscr.addstr(0, 0, whstr, curses.color_pair(1)) file_string = "X position of text: {}".format(start_x_file) stdscr.addstr(1, 0, file_string, curses.color_pair(1)) def draw_scroll(stdscr): # Clear and refresh the screen for a blank screen # Set delay to no, to not wait for keyboard press stdscr.nodelay(1) stdscr.clear() stdscr.refresh() start_x_file = 80 rotation = 1 # Start colors in curses curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK) curses.init_pair(6, curses.COLOR_YELLOW, curses.COLOR_BLACK) while True: # Loop where k is the last character pressed stdscr.clear() height, width = stdscr.getmaxyx() # Declaration of strings title = "Curses horizontal scroller test"[: width - 1] subtitle = "Crunk Varia"[: width - 1] hwidth = width // 2 # Centering calculations start_x_title = int((hwidth) - (len(title) // 2) - len(title) % 2) start_x_subtitle = int( (hwidth) - (len(subtitle) // 2) - len(subtitle) % 2 ) start_y = int((height) - 2) if debug_text: show_debug_text(stdscr, width, height, start_x_file) line_count = 0 for line in lines: ch_count = 0 for character in line: if ( ch_count + start_x_file < width and ch_count + start_x_file > 0 ): stdscr.addch( 3 + line_count, start_x_file + ch_count, character, curses.color_pair(rotation), ) ch_count += 1 line_count += 1 # Turning on attributes for title stdscr.attron(curses.color_pair(2)) stdscr.attron(curses.A_BOLD) # Rendering title stdscr.addstr(start_y, start_x_title, title) # Turning off attributes for title stdscr.attroff(curses.color_pair(2)) stdscr.attroff(curses.A_BOLD) stdscr.addstr(start_y + 1, start_x_subtitle, subtitle) # Refresh the screen stdscr.refresh() time.sleep(1.0 / 30) start_x_file -= 1 if start_x_file < -80: start_x_file = 80 rotation += 1 if rotation > 6: rotation = 1 key_pressed = stdscr.getch() != -1 if key_pressed: raise KeyboardInterrupt() def main(): curses.wrapper(draw_scroll) if __name__ == "__main__": try: main() except KeyboardInterrupt: curses.endwin() curses.curs_set(1) curses.reset_shell_mode() curses.echo()