foldermenu banners printed with double # signs
This commit is contained in:
@@ -13,7 +13,7 @@ readline.parse_and_bind('set editing-mode vi')
|
|||||||
|
|
||||||
MENUFILE='.foldermenu'
|
MENUFILE='.foldermenu'
|
||||||
DEFAULTFILE = os.path.expanduser(os.path.join('~','.config','foldermenu','default'))
|
DEFAULTFILE = os.path.expanduser(os.path.join('~','.config','foldermenu','default'))
|
||||||
VERSION="0.3"
|
VERSION="0.4"
|
||||||
|
|
||||||
def setup_options():
|
def setup_options():
|
||||||
''' Setup the command line options '''
|
''' Setup the command line options '''
|
||||||
@@ -25,6 +25,8 @@ def setup_options():
|
|||||||
"If the command ends in '&' it is run in the background.")
|
"If the command ends in '&' it is run in the background.")
|
||||||
parser.add_argument("-1","--one-shot",action='store_true', dest='once',default=False,
|
parser.add_argument("-1","--one-shot",action='store_true', dest='once',default=False,
|
||||||
help="Launch only once, then exit")
|
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,
|
parser.add_argument("-d","--no-defaults",action='store_false', dest='defaults',default=True,
|
||||||
help="Do not show default entries from "+DEFAULTFILE)
|
help="Do not show default entries from "+DEFAULTFILE)
|
||||||
parser.add_argument("-x","--no-exec",action='store_false', dest='executables',default=True,
|
parser.add_argument("-x","--no-exec",action='store_false', dest='executables',default=True,
|
||||||
@@ -87,6 +89,9 @@ class bc:
|
|||||||
def pos(self,y,x):
|
def pos(self,y,x):
|
||||||
return "\033["+str(y)+";"+str(x)+"H"
|
return "\033["+str(y)+";"+str(x)+"H"
|
||||||
|
|
||||||
|
def posprint(self, y,x,s):
|
||||||
|
sys.stdout.write( self.pos(y,x) + str(s) )
|
||||||
|
|
||||||
class getch:
|
class getch:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
import sys, tty, termios
|
import sys, tty, termios
|
||||||
@@ -117,6 +122,7 @@ class entry_collection:
|
|||||||
options=[]
|
options=[]
|
||||||
entries=[]
|
entries=[]
|
||||||
dirs=[]
|
dirs=[]
|
||||||
|
banner=[]
|
||||||
menu_keys=[ichr(i+1) for i in range(60)]
|
menu_keys=[ichr(i+1) for i in range(60)]
|
||||||
args=''
|
args=''
|
||||||
dir_mode=False
|
dir_mode=False
|
||||||
@@ -132,6 +138,7 @@ class entry_collection:
|
|||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.entries=[]
|
self.entries=[]
|
||||||
self.dirs=[]
|
self.dirs=[]
|
||||||
|
self.banner=[]
|
||||||
if self.options.defaults:
|
if self.options.defaults:
|
||||||
self.read_menu(DEFAULTFILE)
|
self.read_menu(DEFAULTFILE)
|
||||||
self.read_menu()
|
self.read_menu()
|
||||||
@@ -151,6 +158,9 @@ class entry_collection:
|
|||||||
for row in f:
|
for row in f:
|
||||||
if row.strip()=='':
|
if row.strip()=='':
|
||||||
continue
|
continue
|
||||||
|
if row[0:2]=='##':
|
||||||
|
self.banner.append(row[2:].replace("\n","").replace("\r",""))
|
||||||
|
continue
|
||||||
if row[0]=='#':
|
if row[0]=='#':
|
||||||
continue
|
continue
|
||||||
row=row.strip().split(':',1)
|
row=row.strip().split(':',1)
|
||||||
@@ -218,28 +228,35 @@ class entry_collection:
|
|||||||
pars=float(pars)
|
pars=float(pars)
|
||||||
else:
|
else:
|
||||||
pars=float(self.options.columns)
|
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]
|
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))
|
rows=int(math.ceil(len(my_entries)/pars))
|
||||||
while rows > maxrows:
|
while rows > maxrows:
|
||||||
pars+=1
|
pars+=1
|
||||||
rows=int(math.ceil(len(my_entries)/pars))
|
rows=int(math.ceil(len(my_entries)/pars))
|
||||||
maxcolumns=int(math.ceil(maxcolumns/pars))
|
maxcolumns=int(math.ceil(maxcolumns/pars))
|
||||||
r=1
|
r=1+blen
|
||||||
par=1
|
par=1
|
||||||
for e,i in zip(my_entries,self.menu_keys):
|
for e,i in zip(my_entries,self.menu_keys):
|
||||||
if r>rows:
|
if r-blen>rows:
|
||||||
par=1+par
|
par+=1
|
||||||
r=1
|
r=1+blen
|
||||||
printline=e.description
|
printline=e.description
|
||||||
if len(printline)>maxcolumns:
|
if len(printline)>maxcolumns:
|
||||||
printline=printline[:maxcolumns]+"..."
|
printline=printline[:maxcolumns]+"..."
|
||||||
if par==1:
|
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:
|
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)
|
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+r
|
r+=1
|
||||||
print(self.co.pos(rows+2,0))
|
self.co.posprint(rows+2+blen,0,"")
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
""" draws the list at cursor """
|
""" draws the list at cursor """
|
||||||
@@ -294,7 +311,9 @@ class entry_collection:
|
|||||||
if self.options.horizontal:
|
if self.options.horizontal:
|
||||||
# let's shuffle the deck, and print values in horizontal order:
|
# let's shuffle the deck, and print values in horizontal order:
|
||||||
formatted=zip(*formatted)
|
formatted=zip(*formatted)
|
||||||
|
if self.options.banner:
|
||||||
|
if self.banner:
|
||||||
|
print("\n".join(self.banner))
|
||||||
for row in formatted:
|
for row in formatted:
|
||||||
print '|'.join(row)
|
print '|'.join(row)
|
||||||
|
|
||||||
|
|||||||
@@ -325,8 +325,7 @@ function ised () {
|
|||||||
|
|
||||||
function foldermenu_prompt {
|
function foldermenu_prompt {
|
||||||
[ -f .foldermenu ] && {
|
[ -f .foldermenu ] && {
|
||||||
echo -n "f:"
|
foldermenu -lf 10 $@ || echo -n "*"
|
||||||
foldermenu -lf 10 || echo -n "*"
|
|
||||||
} || {
|
} || {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user