nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit 4c8da5a89270efb6b03e85c0a019a9c19074a29f
parent 680b1a44bb0060847d65b4eab1390b513c3330f4
Author: Eric Davis <edavis@insanum.com>
Date:   Sat, 28 Jun 2014 00:20:18 -0700

added support for an external pager for viewing notes with

Diffstat:
Mconfig.py | 6+++++-
Msncli.py | 41+++++++++++++++++++++++++++++++++++++++--
2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/config.py b/config.py @@ -18,6 +18,7 @@ def __init__(self): 'cfg_format_strftime' : '%Y/%m/%d', 'cfg_format_note_title' : '[%D] %F %-N %T', 'cfg_status_bar' : 'yes', + 'cfg_pager' : 'less -c', 'kb_help' : 'h', 'kb_quit' : 'q', @@ -31,6 +32,7 @@ def __init__(self): 'kb_top' : 'g', 'kb_status' : 's', 'kb_view_note' : 'enter', + 'kb_view_note_ext' : 'meta enter', 'kb_view_log' : 'l', 'kb_tabstop2' : '2', 'kb_tabstop4' : '4', @@ -98,7 +100,8 @@ def __init__(self): 'tabstop' : [ cp.get(cfg_sec, 'cfg_tabstop'), 'Tabstop spaces' ], 'format_strftime' : [ cp.get(cfg_sec, 'cfg_format_strftime', raw=True), 'Date strftime format' ], 'format_note_title' : [ cp.get(cfg_sec, 'cfg_format_note_title', raw=True), 'Note title format' ], - 'status_bar' : [ cp.get(cfg_sec, 'cfg_status_bar'), 'Status bar location' ] + 'status_bar' : [ cp.get(cfg_sec, 'cfg_status_bar'), 'Status bar location' ], + 'pager' : [ cp.get(cfg_sec, 'cfg_pager'), 'External pager' ] } self.keybinds = \ @@ -115,6 +118,7 @@ def __init__(self): 'top' : [ cp.get(cfg_sec, 'kb_top'), 'Goto top' ], 'status' : [ cp.get(cfg_sec, 'kb_status'), 'Toggle status bar' ], 'view_note' : [ cp.get(cfg_sec, 'kb_view_note'), 'View note' ], + 'view_note_ext' : [ cp.get(cfg_sec, 'kb_view_note_ext'), 'View note with pager' ], 'view_log' : [ cp.get(cfg_sec, 'kb_view_log'), 'View log' ], 'tabstop2' : [ cp.get(cfg_sec, 'kb_tabstop2'), 'View with tabstop=2' ], 'tabstop4' : [ cp.get(cfg_sec, 'kb_tabstop4'), 'View with tabstop=4' ], diff --git a/sncli.py b/sncli.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 import os, sys, re, signal, time, datetime, logging -import copy, json, urwid, datetime +import copy, json, urwid, datetime, tempfile import utils from config import Config from simplenote import Simplenote @@ -421,6 +421,42 @@ def note_title_listbox_keypress(self, size, key): sncli_loop.widget = NoteContent(self.listbox.focus_position, int(get_config().get_config('tabstop'))) + elif key == 'meta enter': + pager = None + if self.config.get_config('pager'): + pager = self.config.get_config('pager') + if not pager and os.environ['PAGER']: + pager = os.environ['PAGER'] + if not pager: + # XXX bottom status message no external pager configured + return + + # XXX bottom status message showing pager string + + note = list_get_note_json(self.listbox.focus_position) + ext = ".mkd" if 'markdown' in note['systemtags'] else ".txt" + f = tempfile.NamedTemporaryFile(suffix=ext, delete=False) + f.write(note['content']) + f.flush() + + saveb = self.contents['body'][0] + saveh = self.contents['header'][0] + #savef = self.contents['footer'][0] + + try: + os.system(pager + u' ' + f.name) + except OSError, e: + # XXX bottom status message pager error + raise + + self.contents['body'] = ( saveb, None ) + self.contents['header'] = ( saveh, None ) + #self.contents['footer'] = ( savef, None ) + + # XXX check if modified, if so update it + + os.unlink(f.name) + elif key == self.config.get_keybind('search'): self.contents['footer'] = \ ( urwid.AttrMap(SearchNotes(key, self), 'search_bar'), None ) @@ -603,7 +639,8 @@ def __init__(self): # NoteTitles keybinds keys = [ 'search', 'clear_search', - 'view_note' ] + 'view_note', + 'view_note_ext' ] lines.extend(self.create_kb_help_lines(u"Keybinds Note List", keys)) # NoteContent keybinds