def show_not_found(pos_screen: Screen, defn_screen: Screen): pos_screen.set_style(Color.named('error')) pos_screen.add_str("Error") defn_screen.set_style(Color.named('error')) defn_screen.add_str_wrapped( "Could not find a defition for the given word!") defn_screen.nl() defn_screen.set_style(Bold(), Color.named('error')) defn_screen.add_str_wrapped("Note that Wordnik is case-sensitive") pos_screen.render() defn_screen.render()
def main(): options = parse_args() if options.keybindings: word = 'Keybindings' dict_entries = key_binding_entries else: word = ' '.join(options.word) dict_entries = get_dict_entries(word, options.traceback) scr = curses_begin() show_banner(scr) scr.win.addstr( "Hello", TextStyle(0, ( Bold(), Color.named('missing-info'), )).attr()) scr.getch() curses.endwin() return show_requested_word(scr, word) scr.render() if dict_entries == []: rs = len('Error') + 2 (pos_screen, defn_screen) = curses_create_subscrs(scr, right_start=rs) show_not_found(pos_screen, defn_screen) else: # this takes the (part-of-speech, defintion) tuples and replaces # empty strings in the part-of-speec with the string <unknown> dict_entries = fix_missing_pos(dict_entries) # this finds the tuple in dict_entries with the longest length # of the string at index 0, then it takes the 0th element of # that tuple, gets its length and adds 2 rs = len(max(dict_entries, key=lambda x: len(x[0]))[0]) + 2 (pos_screen, defn_screen) = curses_create_subscrs(scr, right_start=rs) lines = 0 for entry in dict_entries: entry_lines = show_word_defintion(entry, pos_screen, defn_screen) pos_screen.nl(entry_lines + 1) defn_screen.nl(2) lines += entry_lines curses_mainloop(scr, pos_screen, defn_screen) curses.endwin()
def show_requested_word(scr: Screen, word: str): scr.set_style(Bold()) scr.add_str(word)