From c61afaf39e6a1cc8529ffa6eff475b6a0fddc1ea Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Sun, 12 Apr 2015 12:30:54 +0300 Subject: [PATCH] foldermenu banners printed with double # signs --- foldermenu.py | 41 ++++++++++++++++++++++++++++++----------- qcd_function | 3 +-- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/foldermenu.py b/foldermenu.py index e170e7b..4e701d7 100755 --- a/foldermenu.py +++ b/foldermenu.py @@ -13,7 +13,7 @@ readline.parse_and_bind('set editing-mode vi') MENUFILE='.foldermenu' DEFAULTFILE = os.path.expanduser(os.path.join('~','.config','foldermenu','default')) -VERSION="0.3" +VERSION="0.4" def setup_options(): ''' Setup the command line options ''' @@ -25,6 +25,8 @@ def setup_options(): "If the command ends in '&' it is run in the background.") parser.add_argument("-1","--one-shot",action='store_true', dest='once',default=False, help="Launch only once, then exit") + parser.add_argument("-b","--no-banner", action='store_false', dest='banner', default=True, + help="Do not show banners. Banners are ## starting lines in the file") parser.add_argument("-d","--no-defaults",action='store_false', dest='defaults',default=True, help="Do not show default entries from "+DEFAULTFILE) parser.add_argument("-x","--no-exec",action='store_false', dest='executables',default=True, @@ -87,6 +89,9 @@ class bc: def pos(self,y,x): return "\033["+str(y)+";"+str(x)+"H" + def posprint(self, y,x,s): + sys.stdout.write( self.pos(y,x) + str(s) ) + class getch: def __init__(self): import sys, tty, termios @@ -117,6 +122,7 @@ class entry_collection: options=[] entries=[] dirs=[] + banner=[] menu_keys=[ichr(i+1) for i in range(60)] args='' dir_mode=False @@ -132,6 +138,7 @@ class entry_collection: def initialize(self): self.entries=[] self.dirs=[] + self.banner=[] if self.options.defaults: self.read_menu(DEFAULTFILE) self.read_menu() @@ -151,6 +158,9 @@ class entry_collection: for row in f: if row.strip()=='': continue + if row[0:2]=='##': + self.banner.append(row[2:].replace("\n","").replace("\r","")) + continue if row[0]=='#': continue row=row.strip().split(':',1) @@ -218,28 +228,35 @@ class entry_collection: pars=float(pars) else: pars=float(self.options.columns) + if self.options.banner: + b=self.banner + else: + b=[] + blen=len(b) cwd=os.path.basename(os.getcwd())[0:15] - print(self.co.END+self.co.CLR+self.co.pos(1,3)+self.co.WHI+cwd+self.co.YEL+' Menu x:exit '+helptext+self.co.END) + self.co.posprint(1,3,self.co.END+self.co.CLR+self.co.WHI+cwd+self.co.YEL+' Menu x:exit '+helptext+self.co.END) + for i,e in enumerate(b): + self.co.posprint(i+2,0,e) rows=int(math.ceil(len(my_entries)/pars)) while rows > maxrows: pars+=1 rows=int(math.ceil(len(my_entries)/pars)) maxcolumns=int(math.ceil(maxcolumns/pars)) - r=1 + r=1+blen par=1 for e,i in zip(my_entries,self.menu_keys): - if r>rows: - par=1+par - r=1 + if r-blen>rows: + par+=1 + r=1+blen printline=e.description if len(printline)>maxcolumns: printline=printline[:maxcolumns]+"..." if par==1: - print(self.co.WHI+i+self.co.END+' '+self.entry_color(e.launcher)+printline+self.co.END) + self.co.posprint(r+1,2,self.co.WHI+i+self.co.END+' '+self.entry_color(e.launcher)+printline+self.co.END) else: - print(self.co.pos(r+1,maxcolumns*(par-1))+'| '+self.co.WHI+i+self.co.END+' '+self.entry_color(e.launcher)+printline+self.co.END) - r=1+r - print(self.co.pos(rows+2,0)) + self.co.posprint(r+1,maxcolumns*(par-1),'| '+self.co.WHI+i+self.co.END+' '+self.entry_color(e.launcher)+printline+self.co.END) + r+=1 + self.co.posprint(rows+2+blen,0,"") def list(self): """ draws the list at cursor """ @@ -294,7 +311,9 @@ class entry_collection: if self.options.horizontal: # let's shuffle the deck, and print values in horizontal order: formatted=zip(*formatted) - + if self.options.banner: + if self.banner: + print("\n".join(self.banner)) for row in formatted: print '|'.join(row) diff --git a/qcd_function b/qcd_function index 8458481..cc44f8f 100644 --- a/qcd_function +++ b/qcd_function @@ -325,8 +325,7 @@ function ised () { function foldermenu_prompt { [ -f .foldermenu ] && { - echo -n "f:" - foldermenu -lf 10 || echo -n "*" + foldermenu -lf 10 $@ || echo -n "*" } || { true }