diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-04-26 01:32:07 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-04-26 01:32:07 +0200 |
commit | 8c4f6e37479002818bcfe7381cd4e4b47fd2d1fb (patch) | |
tree | 8d032273fb3b5e4216b021795256e79dffe0b667 /patches/terminal_velocity_sort_found_notes.patch | |
parent | c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8 (diff) | |
download | Nix-8c4f6e37479002818bcfe7381cd4e4b47fd2d1fb.tar.gz Nix-8c4f6e37479002818bcfe7381cd4e4b47fd2d1fb.tar.zst Nix-8c4f6e37479002818bcfe7381cd4e4b47fd2d1fb.zip |
Start splitting nix environment to smaller files
Diffstat (limited to 'patches/terminal_velocity_sort_found_notes.patch')
-rw-r--r-- | patches/terminal_velocity_sort_found_notes.patch | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/patches/terminal_velocity_sort_found_notes.patch b/patches/terminal_velocity_sort_found_notes.patch deleted file mode 100644 index 2bc563c..0000000 --- a/patches/terminal_velocity_sort_found_notes.patch +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
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() | ||