def pad_to_screen(s): """ Pads a string to the terminal size. The string length is computed after removing shell escape sequences. """ current_size = len(remove_escapes(s)) desired_size = get_screen_columns() - 1 pad_char = " " # pad_char = "_" # useful for debugging if current_size < desired_size: s += pad_char * (desired_size - current_size) return s
def console_write(s): ''' Writes a line that will be erased. ''' cols = get_screen_columns() s = string.ljust(s, cols) stream.write(s) stream.write('\r')