def text(self, day): """Get a textual representation of metadata for an entry.""" data = self.get_data_for_day(day) output = [format_date(datetime.date(self.year, self.month, day))] tags = edits_info = None try: lines, words, tags, size, edits = data except TypeError: m = 'No entry for selected date' else: m = '%d lines, %d words, %s' % (lines, words, format_size(size)) tags = ', '.join(tags) if edits: edits_info = 'Created: %s' % format_time(edits[0]) try: edits_info += ', edited %d times, last: %s' % (edits[2], format_time(edits[1])) except IndexError: pass output.append(m) if tags: output.append('Tags: %s' % tags) if edits_info: output.append(edits_info) return '\n'.join(output)
def show_edits(date, edits, area_id): """Show all edits of an entry as a scrollable list.""" from writelightly.screen import ScreenManager from writelightly.utils import format_time, format_size from writelightly.scrollable_list import ScrollableList import curses formatted = ['%s, created' % format_time(edits[0][0], full=True)] formatted += ['%s, %s' % (format_time(ts, full=True), format_size(size)) for ts, size in edits[1:]] sl = ScrollableList(formatted, area_id=area_id) sl.draw() while 1: kn = curses.keyname(sl.window.getch()) if kn in Config.general_keys['quit']: raise WLQuit if kn in Config.general_keys['quit_mode']: break if kn == 'KEY_RESIZE': ScreenManager.resize() if sl.hidden: continue elif kn in Config.edits_keys['open']: index = sl.get_current_index() fn = save_tmp_version(date, edits, index) edit_file(fn) sl.draw() else: sl.handle_keypress(kn)