]> git.immae.eu Git - perso/Immae/Config/Nix/NUR.git/blob - pkgs/terminal-velocity/sort_found_notes.patch
Initial commit published for NUR
[perso/Immae/Config/Nix/NUR.git] / pkgs / terminal-velocity / sort_found_notes.patch
1 commit 0f9df37046e58c8963aff93c649e5d3dbf2202bd
2 Author: Ismaƫl Bouya <ismael.bouya@normalesup.org>
3 Date: Sat Mar 9 20:11:46 2019 +0100
4
5 Add sorting option
6
7 diff --git a/terminal_velocity/terminal_velocity.py b/terminal_velocity/terminal_velocity.py
8 index a53eda3..5f0e213 100755
9 --- a/terminal_velocity/terminal_velocity.py
10 +++ b/terminal_velocity/terminal_velocity.py
11 @@ -90,6 +90,10 @@ the default default will be used"""
12 default=defaults.get("log_file", "~/.tvlog"),
13 help="the file to log to (default: %(default)s)")
14
15 + parser.add_argument("-s", "--sort", dest="sort", action="store",
16 + default=defaults.get("sort", "date"),
17 + help="the note sorting rules. Possible values: date, title (default: %(default)s)")
18 +
19 parser.add_argument("-p", "--print-config", dest="print_config",
20 action="store_true", default=False,
21 help="print your configuration settings then exit")
22 @@ -138,7 +142,7 @@ the default default will be used"""
23 try:
24 urwid_ui.launch(notes_dir=args.notes_dir, editor=args.editor,
25 extension=args.extension, extensions=args.extensions,
26 - exclude=args.exclude)
27 + exclude=args.exclude, sort=args.sort)
28 except KeyboardInterrupt:
29 # Run the shutdown hook
30 shutdown()
31 diff --git a/terminal_velocity/urwid_ui.py b/terminal_velocity/urwid_ui.py
32 index 34cf4f6..caebcb9 100644
33 --- a/terminal_velocity/urwid_ui.py
34 +++ b/terminal_velocity/urwid_ui.py
35 @@ -237,11 +237,12 @@ class NoteFilterListBox(urwid.ListBox):
36 class MainFrame(urwid.Frame):
37 """The topmost urwid widget."""
38
39 - def __init__(self, notes_dir, editor, extension, extensions, exclude=None):
40 + def __init__(self, notes_dir, editor, extension, extensions, exclude=None, sort="date"):
41
42 self.editor = editor
43 self.notebook = notebook.PlainTextNoteBook(notes_dir, extension,
44 extensions, exclude=exclude)
45 + self.sort = sort
46
47 # Don't filter the note list when the text in the search box changes.
48 self.suppress_filter = False
49 @@ -408,7 +409,10 @@ class MainFrame(urwid.Frame):
50
51 # Sort the notes.
52 # TODO: Support different sort orderings.
53 - matching_notes.sort(key=lambda x: x.mtime, reverse=True)
54 + if self.sort == "title":
55 + matching_notes.sort(key=lambda x: x.title)
56 + else:
57 + matching_notes.sort(key=lambda x: x.mtime, reverse=True)
58
59 # Tell the list box to show only the matching notes.
60 self.list_box.filter(matching_notes)
61 @@ -433,10 +437,10 @@ class MainFrame(urwid.Frame):
62 self.selected_note = note
63
64
65 -def launch(notes_dir, editor, extension, extensions, exclude=None):
66 +def launch(notes_dir, editor, extension, extensions, exclude=None, sort="date"):
67 """Launch the user interface."""
68
69 - frame = MainFrame(notes_dir, editor, extension, extensions, exclude=exclude)
70 + frame = MainFrame(notes_dir, editor, extension, extensions, exclude=exclude, sort=sort)
71 loop = urwid.MainLoop(frame, palette)
72 frame.loop = loop
73 loop.run()