]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - patches/terminal_velocity_sort_found_notes.patch
Move Émilia's website
[perso/Immae/Config/Nix.git] / patches / terminal_velocity_sort_found_notes.patch
CommitLineData
d0f80881
IB
1diff --git a/terminal_velocity/terminal_velocity.py b/terminal_velocity/terminal_velocity.py
2index db2eb05..bb77dc6 100755
3--- a/terminal_velocity/terminal_velocity.py
4+++ b/terminal_velocity/terminal_velocity.py
5@@ -75,6 +75,10 @@ the default default will be used"""
6 default=defaults.get("log_file", "~/.tvlog"),
7 help="the file to log to (default: %(default)s)")
8
9+ parser.add_argument("-s", "--sort", dest="sort", action="store",
10+ default=defaults.get("sort", "date"),
11+ help="the note sorting rules. Possible values: date, title (default: %(default)s)")
12+
13 parser.add_argument("-p", "--print-config", dest="print_config",
14 action="store_true", default=False,
15 help="print your configuration settings then exit")
16@@ -120,7 +124,7 @@ the default default will be used"""
17 try:
18 urwid_ui.launch(notes_dir=args.notes_dir, editor=args.editor,
19 extension=args.extension, extensions=args.extensions,
20- exclude=args.exclude)
21+ exclude=args.exclude, sort=args.sort)
22 except KeyboardInterrupt:
23 # Silence KeyboardInterrupt tracebacks on ctrl-c.
24 sys.exit()
25diff --git a/terminal_velocity/urwid_ui.py b/terminal_velocity/urwid_ui.py
26index 34cf4f6..caebcb9 100644
27--- a/terminal_velocity/urwid_ui.py
28+++ b/terminal_velocity/urwid_ui.py
29@@ -237,11 +237,12 @@ class NoteFilterListBox(urwid.ListBox):
30 class MainFrame(urwid.Frame):
31 """The topmost urwid widget."""
32
33- def __init__(self, notes_dir, editor, extension, extensions, exclude=None):
34+ def __init__(self, notes_dir, editor, extension, extensions, exclude=None, sort="date"):
35
36 self.editor = editor
37 self.notebook = notebook.PlainTextNoteBook(notes_dir, extension,
38 extensions, exclude=exclude)
39+ self.sort = sort
40
41 # Don't filter the note list when the text in the search box changes.
42 self.suppress_filter = False
43@@ -408,7 +409,10 @@ class MainFrame(urwid.Frame):
44
45 # Sort the notes.
46 # TODO: Support different sort orderings.
47- matching_notes.sort(key=lambda x: x.mtime, reverse=True)
48+ if self.sort == "title":
49+ matching_notes.sort(key=lambda x: x.title)
50+ else:
51+ matching_notes.sort(key=lambda x: x.mtime, reverse=True)
52
53 # Tell the list box to show only the matching notes.
54 self.list_box.filter(matching_notes)
55@@ -433,10 +437,10 @@ class MainFrame(urwid.Frame):
56 self.selected_note = note
57
58
59-def launch(notes_dir, editor, extension, extensions, exclude=None):
60+def launch(notes_dir, editor, extension, extensions, exclude=None, sort="date"):
61 """Launch the user interface."""
62
63- frame = MainFrame(notes_dir, editor, extension, extensions, exclude=exclude)
64+ frame = MainFrame(notes_dir, editor, extension, extensions, exclude=exclude, sort=sort)
65 loop = urwid.MainLoop(frame, palette)
66 frame.loop = loop
67 loop.run()