def display(self): """ Nicely formatted display of the location history, with current location highlighted. If a clean display is present on the screen, this overwrites it to perform an 'update'. """ buffer_size = get_buffer_size() if self.shown and self.disp_size == buffer_size: # We just need to update the previous display, so we # go back to the original display start point move_cursor(0, buffer_size[1] - self.offset_from_bottom) else: # We need to redisplay, so remember the start point for # future updates self.disp_size = buffer_size self.offset_from_bottom = buffer_size[1] - get_cursor()[1] stdout.write('\n') lines_written = 2 stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT) for i in range(len(self.locations)): location = self.locations[i] if i < 9: prefix = ' +%d ' % (i + 1) else: prefix = ' %d ' % (i + 1) lines_written += (len(prefix + location) / buffer_size[0] + 1) if i != self.index: # Non-selected entry, simply print stdout.write(prefix + location + '\n') else: # Currently selected entry, print with highlight stdout.write(appearance.colors.dir_history_selection + prefix + location + color.Fore.DEFAULT + color.Back.DEFAULT) stdout.write(' ' * (buffer_size[0] - get_cursor()[0])) # Check whether we have overflown the buffer if lines_written > self.offset_from_bottom: self.offset_from_bottom = lines_written # Mark a clean display of the history self.shown = True
def check_overflow(self, line): """ Update the known location of a shown history to account for the possibility of overflowing the display buffer. """ (buf_width, buf_height) = get_buffer_size() (cur_x, cur_y) = get_cursor() lines_written = len(line) // buf_width + 1 if cur_y + lines_written > buf_height: self.offset_from_bottom += cur_y + lines_written - buf_height
def check_overflow(self, line): """ Update the known location of a shown history to account for the possibility of overflowing the display buffer. """ (buf_width, buf_height) = get_buffer_size() (cur_x, cur_y) = get_cursor() lines_written = len(line) / buf_width + 1 if cur_y + lines_written > buf_height: self.offset_from_bottom += cur_y + lines_written - buf_height
def display(self): """ Nicely formatted display of the location history, with current location highlighted. If a clean display is present on the screen, this overwrites it to perform an 'update'. """ buffer_size = get_buffer_size() if self.shown and self.disp_size == buffer_size: # We just need to update the previous display, so we # go back to the original display start point move_cursor(0, buffer_size[1] - self.offset_from_bottom) else: # We need to redisplay, so remember the start point for # future updates self.disp_size = buffer_size self.offset_from_bottom = buffer_size[1] - get_cursor()[1] stdout.write('\n') lines_written = 2 stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT) for i in range(len(self.locations)): location = self.locations[i] prefix = ' %d ' % (i + 1) lines_written += (len(prefix + location) / buffer_size[0] + 1) if i != self.index: # Non-selected entry, simply print stdout.write(prefix + location + '\n') else: # Currently selected entry, print with highlight stdout.write(appearance.colors.dir_history_selection + prefix + location + color.Fore.DEFAULT + color.Back.DEFAULT) stdout.write(' ' * (buffer_size[0] - get_cursor()[0])) # Check whether we have overflown the buffer if lines_written > self.offset_from_bottom: self.offset_from_bottom = lines_written # Mark a clean display of the history self.shown = True
get_viewport()[1]) / 4: # We print multiple columns to save space num_columns = (console.get_buffer_size()[0] - 1) / column_width else: # We print a single column for clarity num_columns = 1 num_lines = len(suggestions) / num_columns if len(suggestions) % num_columns != 0: num_lines += 1 num_screens = 1.0 * num_lines / (get_viewport()[3] - get_viewport()[1]) if num_screens >= 0.9: # We ask for confirmation before displaying many completions (c_x, c_y) = get_cursor() offset_from_bottom = console.get_buffer_size( )[1] - c_y message = ' Scroll ' + str(int( round(num_screens))) + ' screens? [Tab] ' stdout.write('\n' + message) rec = read_input() move_cursor( c_x, console.get_buffer_size()[1] - offset_from_bottom) stdout.write('\n' + ' ' * len(message)) move_cursor( c_x, console.get_buffer_size()[1] - offset_from_bottom)
if column_width > console.get_buffer_size()[0] - 1: column_width = console.get_buffer_size()[0] - 1 if len(suggestions) > (get_viewport()[3] - get_viewport()[1]) / 4: # We print multiple columns to save space num_columns = (console.get_buffer_size()[0] - 1) / column_width else: # We print a single column for clarity num_columns = 1 num_lines = len(suggestions) / num_columns if len(suggestions) % num_columns != 0: num_lines += 1 num_screens = 1.0 * num_lines / (get_viewport()[3] - get_viewport()[1]) if num_screens >= 0.9: # We ask for confirmation before displaying many completions (c_x, c_y) = get_cursor() offset_from_bottom = console.get_buffer_size()[1] - c_y message = ' Scroll ' + str(int(round(num_screens))) + ' screens? [Tab] ' stdout.write('\n' + message) rec = read_input() move_cursor(c_x, console.get_buffer_size()[1] - offset_from_bottom) stdout.write('\n' + ' ' * len(message)) move_cursor(c_x, console.get_buffer_size()[1] - offset_from_bottom) if rec.Char != '\t': continue stdout.write('\n') num_col_could_choose = num_lines # num_lines > 0 num_item_could_choose = len(string.lowercase) while num_col_could_choose < num_item_could_choose : num_col_could_choose = num_col_could_choose + num_lines