arrows support for foldermenu, and folder changing as command
This commit is contained in:
@@ -22,7 +22,8 @@ def setup_options():
|
|||||||
parser=ArgumentParser(description="Prints folder specific shell commands stored in '"+MENUFILE+
|
parser=ArgumentParser(description="Prints folder specific shell commands stored in '"+MENUFILE+
|
||||||
"' file, and in addition the executables in the current folder. "+
|
"' file, and in addition the executables in the current folder. "+
|
||||||
"Menufile format for each line: 'description:command'. "+
|
"Menufile format for each line: 'description:command'. "+
|
||||||
"If the command ends in '&' it is run in the background.")
|
"If the command ends in '&' it is run in the background. "+
|
||||||
|
"If the command ends in '/' it is a folder, and selecting will enter.")
|
||||||
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,
|
parser.add_argument("-b","--no-banner", action='store_false', dest='banner', default=True,
|
||||||
@@ -69,15 +70,17 @@ def ichr(i):
|
|||||||
return chr(i)
|
return chr(i)
|
||||||
|
|
||||||
class bc:
|
class bc:
|
||||||
MAG = '\033[95m'
|
MAG = '\033[35m'
|
||||||
BLU = '\033[94m'
|
BLU = '\033[34m'
|
||||||
GRE = '\033[92m'
|
GRE = '\033[32m'
|
||||||
YEL = '\033[93m'
|
YEL = '\033[33m'
|
||||||
RED = '\033[91m'
|
RED = '\033[31m'
|
||||||
CYA = '\033[96m'
|
CYA = '\033[36m'
|
||||||
WHI = '\033[1m'
|
WHI = '\033[1m'
|
||||||
|
BG_BLK = '\033[40m'
|
||||||
END = '\033[0m'
|
END = '\033[0m'
|
||||||
CLR = '\033[2J'
|
CLR = '\033[2J'
|
||||||
|
INV = '\033[7m'
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
self.MAG = ''
|
self.MAG = ''
|
||||||
@@ -88,6 +91,8 @@ class bc:
|
|||||||
self.CYA = ''
|
self.CYA = ''
|
||||||
self.WHI = ''
|
self.WHI = ''
|
||||||
self.END = ''
|
self.END = ''
|
||||||
|
self.BG_BLK = ''
|
||||||
|
self.INV = ''
|
||||||
|
|
||||||
def pos(self,y,x):
|
def pos(self,y,x):
|
||||||
return "\033[%s;%sH"%( y, x )
|
return "\033[%s;%sH"%( y, x )
|
||||||
@@ -128,6 +133,8 @@ class entry_collection:
|
|||||||
self.co = bc()
|
self.co = bc()
|
||||||
self.dir_mode = False
|
self.dir_mode = False
|
||||||
self.max_length = 0
|
self.max_length = 0
|
||||||
|
self.selected = -1
|
||||||
|
self.rows = 0
|
||||||
self.initialize()
|
self.initialize()
|
||||||
if not self.options.colors:
|
if not self.options.colors:
|
||||||
self.co.disable()
|
self.co.disable()
|
||||||
@@ -224,13 +231,14 @@ class entry_collection:
|
|||||||
def menu(self):
|
def menu(self):
|
||||||
""" draws the menu at the top of the screen """
|
""" draws the menu at the top of the screen """
|
||||||
if self.dir_mode:
|
if self.dir_mode:
|
||||||
helptext = "[.]executables"
|
helptext = "[.]commands"
|
||||||
my_entries = self.dirs
|
my_entries = self.dirs
|
||||||
else:
|
else:
|
||||||
helptext = '[.]folders [-]args (%s%s%s)'%(
|
helptext = '[.]folders [-]args %s(%s%s%s)'%(
|
||||||
|
self.co.END + self.co.MAG,
|
||||||
self.co.END,
|
self.co.END,
|
||||||
self.args,
|
self.args,
|
||||||
self.co.YEL
|
self.co.MAG
|
||||||
)
|
)
|
||||||
my_entries = self.entries
|
my_entries = self.entries
|
||||||
|
|
||||||
@@ -264,7 +272,7 @@ class entry_collection:
|
|||||||
"%s%s%s [q/x]exit %s%s"%(
|
"%s%s%s [q/x]exit %s%s"%(
|
||||||
self.co.WHI,
|
self.co.WHI,
|
||||||
cwd,
|
cwd,
|
||||||
self.co.YEL,
|
self.co.MAG,
|
||||||
helptext,
|
helptext,
|
||||||
self.co.END
|
self.co.END
|
||||||
)
|
)
|
||||||
@@ -282,7 +290,7 @@ class entry_collection:
|
|||||||
maxcolumns = int(math.ceil(maxcolumns / pars))
|
maxcolumns = int(math.ceil(maxcolumns / pars))
|
||||||
r = 1 + blen
|
r = 1 + blen
|
||||||
par = 1
|
par = 1
|
||||||
for entry, key in zip(my_entries, self.menu_keys):
|
for index, (entry, key) in enumerate(zip(my_entries, self.menu_keys)):
|
||||||
if r - blen > rows:
|
if r - blen > rows:
|
||||||
par += 1
|
par += 1
|
||||||
r = 1 + blen
|
r = 1 + blen
|
||||||
@@ -295,15 +303,20 @@ class entry_collection:
|
|||||||
else:
|
else:
|
||||||
column = maxcolumns * ( par - 1 )
|
column = maxcolumns * ( par - 1 )
|
||||||
border = '| '
|
border = '| '
|
||||||
|
if self.selected == index:
|
||||||
|
highlight = self.co.INV + ">"
|
||||||
|
else:
|
||||||
|
highlight = ' '
|
||||||
self.co.posprint(
|
self.co.posprint(
|
||||||
r+1,
|
r+1,
|
||||||
column,
|
column,
|
||||||
"%s%s%s%s %s%s%s"%(
|
"%s%s%s%s%s%s%s%s"%(
|
||||||
border,
|
border,
|
||||||
self.co.WHI,
|
self.co.WHI,
|
||||||
key,
|
key,
|
||||||
self.co.END,
|
self.co.END,
|
||||||
self.entry_color(entry.launcher),
|
self.entry_color(entry.launcher),
|
||||||
|
highlight,
|
||||||
printline,
|
printline,
|
||||||
self.co.END
|
self.co.END
|
||||||
)
|
)
|
||||||
@@ -314,6 +327,7 @@ class entry_collection:
|
|||||||
0,
|
0,
|
||||||
"#"
|
"#"
|
||||||
)
|
)
|
||||||
|
self.rows = rows
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
""" draws the list at cursor """
|
""" draws the list at cursor """
|
||||||
@@ -388,14 +402,17 @@ class entry_collection:
|
|||||||
|
|
||||||
bg = False
|
bg = False
|
||||||
idx = self.menu_keys.index(key)
|
idx = self.menu_keys.index(key)
|
||||||
# note, no error checking here
|
|
||||||
if self.dir_mode:
|
if self.dir_mode:
|
||||||
command_str = self.dirs[idx].command
|
command_str = self.dirs[idx].command
|
||||||
os.chdir(command_str)
|
else:
|
||||||
return
|
|
||||||
# continue here if not changing folders
|
|
||||||
command_str = self.entries[idx].command
|
command_str = self.entries[idx].command
|
||||||
|
|
||||||
|
if self.dir_mode or command_str[-1] == '/':
|
||||||
|
if os.path.isdir(command_str):
|
||||||
|
os.chdir(command_str)
|
||||||
|
self.selected = -1
|
||||||
|
return
|
||||||
|
|
||||||
if command_str[-1] == '&':
|
if command_str[-1] == '&':
|
||||||
#Run the program in background
|
#Run the program in background
|
||||||
command_str = command_str[:-1]
|
command_str = command_str[:-1]
|
||||||
@@ -432,6 +449,7 @@ class entry_collection:
|
|||||||
|
|
||||||
def flip_mode(self):
|
def flip_mode(self):
|
||||||
self.dir_mode = not self.dir_mode
|
self.dir_mode = not self.dir_mode
|
||||||
|
self.selected = 0
|
||||||
|
|
||||||
def is_key(self, key):
|
def is_key(self, key):
|
||||||
if self.dir_mode:
|
if self.dir_mode:
|
||||||
@@ -446,6 +464,19 @@ class entry_collection:
|
|||||||
return (False, 'No such entry')
|
return (False, 'No such entry')
|
||||||
return (True, '')
|
return (True, '')
|
||||||
|
|
||||||
|
def select_move(self, delta):
|
||||||
|
new_value = self.selected + delta
|
||||||
|
if new_value < 0:
|
||||||
|
return
|
||||||
|
if self.dir_mode:
|
||||||
|
max_value = len(self.dirs) - 1
|
||||||
|
else:
|
||||||
|
max_value = len(self.entries) - 1
|
||||||
|
if new_value > max_value:
|
||||||
|
return
|
||||||
|
self.selected = new_value
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def start_engines():
|
def start_engines():
|
||||||
options = setup_options()
|
options = setup_options()
|
||||||
@@ -468,7 +499,29 @@ def start_engines():
|
|||||||
entries.menu()
|
entries.menu()
|
||||||
inkey = ord(ch.get())
|
inkey = ord(ch.get())
|
||||||
#print('-'+str((inkey))+'-')
|
#print('-'+str((inkey))+'-')
|
||||||
if inkey in (113, 120, 27, 3, 24, 4): # esc, q, x
|
if inkey == 27:
|
||||||
|
inkey2 = ord(ch.get())
|
||||||
|
if inkey2 == 91:
|
||||||
|
inkey3 = ord(ch.get())
|
||||||
|
if inkey3 == 66:
|
||||||
|
entries.select_move(1)
|
||||||
|
if inkey3 == 65:
|
||||||
|
entries.select_move(-1)
|
||||||
|
if inkey3 == 67:
|
||||||
|
entries.select_move(entries.rows)
|
||||||
|
if inkey3 == 68:
|
||||||
|
entries.select_move(-entries.rows)
|
||||||
|
# 66 = down
|
||||||
|
# 65 = up
|
||||||
|
# 67 = right
|
||||||
|
# 68 = left
|
||||||
|
# 53 = pg up
|
||||||
|
# 54 = pg down
|
||||||
|
#
|
||||||
|
#~ print(inkey3)
|
||||||
|
#~ sys.exit(0)
|
||||||
|
|
||||||
|
if inkey in (113, 120, 3, 24, 4): # q, x
|
||||||
print('Exited in: ' + os.getcwd())
|
print('Exited in: ' + os.getcwd())
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
if inkey == 45: # -
|
if inkey == 45: # -
|
||||||
@@ -479,6 +532,8 @@ def start_engines():
|
|||||||
readline.set_startup_hook(None)
|
readline.set_startup_hook(None)
|
||||||
if inkey == 46: # .
|
if inkey == 46: # .
|
||||||
entries.flip_mode()
|
entries.flip_mode()
|
||||||
|
if inkey == 13:
|
||||||
|
inkey = ord(entries.menu_keys[entries.selected])
|
||||||
found, message = entries.is_key(chr(inkey))
|
found, message = entries.is_key(chr(inkey))
|
||||||
if found:
|
if found:
|
||||||
entries.launch(chr(inkey))
|
entries.launch(chr(inkey))
|
||||||
|
|||||||
Reference in New Issue
Block a user