Add preview command
authorAlex Schroeder <alex@gnu.org>
Wed, 14 Aug 2019 10:58:53 +0000 (12:58 +0200)
committerAlex Schroeder <alex@gnu.org>
Wed, 14 Aug 2019 10:58:53 +0000 (12:58 +0200)
jan-pona-mute.py

index cac03ea9f3f5739d5d71891c3ceeb56ab219924c..e8d285c699640fb5ccbd0992dc5df0f8ec466cfb 100755 (executable)
@@ -25,11 +25,12 @@ import os
 # Command abbreviations
 _ABBREVS = {
     "q":    "quit",
-    "p":    "print",
+    "p":    "preview",
     "c":    "comments",
     "r":    "reload",
     "n":    "notifications",
     "e":    "edit",
+    "d":    "delete",
 }
 
 _RC_PATHS = (
@@ -532,6 +533,29 @@ Use the 'edit' command to edit notes."""
         with open(self.get_note_path(filename), mode = 'r', encoding = 'utf-8') as fp:
             return fp.read()
 
+    def do_preview(self, line):
+        """Preview a note using your pager.
+Use the 'pager' command to set your pager to something like 'mdcat'."""
+        if line == "":
+            print("The 'preview' command the number of a note as an argument.")
+            print("Use the 'notes' command to list all your notes.")
+            return
+        try:
+            n = int(line.strip())
+            notes = self.get_notes()
+            if notes:
+                try:
+                    self.show(self.read_note(notes[n-1]))
+                except IndexError:
+                    print("Use the 'list notes' command to list valid numbers.")
+                    return
+            else:
+                print("There are no notes to preview.")
+                return
+        except ValueError:
+            print("The 'preview' command takes a number as its argument.")
+            return
+
 # Main function
 def main():