#!/usr/bin/env python3 """Test drsmenu.py.""" import math import time import typing import drsmenu def row_col_to_char(pad_max_row: int, pad_max_column: int, row: int, column: int) -> str: """ Convert a row, column into a magnitude, and from there convert it to character in a..z. Why? Because we want to put some simple ASCII art in the pad for testing. This gives us something to scroll and search. """ pad_max_row_over_2 = pad_max_row / 2.0 pad_max_column_over_2 = pad_max_column / 2.0 sqrt_of_2 = math.sqrt(2.0) # assert side_over_2 == 50.0 shifted_row = row - pad_max_row_over_2 # assert -50.0 <= shifted_row <= 50 shifted_column = column - pad_max_column_over_2 # assert -50.0 <= shifted_column <= 50 scaled_row = shifted_row / pad_max_row_over_2 # assert -1.0 <= scaled_row <= 1.0 scaled_column = shifted_column / pad_max_column_over_2 # assert -1.0 <= scaled_column <= 1.0 magnitude = math.sqrt(scaled_row ** 2.0 + scaled_column ** 2.0) # assert 0.0 <= magnitude <= sqrt_of_2 scaled_magnitude = magnitude / sqrt_of_2 # assert 0.0 <= scaled_magnitude <= 1.0 color_char = chr(int(scaled_magnitude * 25.0) + ord('a')) # assert 'a' <= color_char <= 'z' return color_char def circle(max_row: int, max_column: int) -> typing.List[str]: """Generate a weird sort of sphere using ASCII characters.""" text_list = [] # These loops fill the pad with letters for row in range(0, max_row): line_list = [] for column in range(0, max_column): if row == max_row - 1 and column == max_column - 1: # Curses doesn't want to put a character in the lower right corner continue color_char = row_col_to_char(max_row, max_column, row, column) line_list.append(color_char) text_list.append(''.join(line_list)) return text_list def main() -> None: """Start the ball rolling.""" options_text = [f'{i}' for i in range(100)] optionno = drsmenu.get_menu_selection('title 1', options_text) print(optionno) time.sleep(3) for x, y in ( (100, 100), (100, 200), (20, 20), ): options_text = circle(x, y) optionno = drsmenu.get_menu_selection('circle', options_text) print(optionno) time.sleep(3) options_text = [''.join('1234567890' for i in range(20)) for j in range(50)] optionno = drsmenu.get_menu_selection('title 2', options_text) print(optionno) if __name__ == '__main__': main()