1
0
mirror of https://github.com/Foltik/dotfiles synced 2025-01-22 06:50:57 -05:00

Clean parse script and start text menu

This commit is contained in:
Jack Foltz 2018-10-16 22:02:11 -04:00
parent 096dc8f0f3
commit 0b4052798e
Signed by: foltik
GPG Key ID: 303F88F996E95541
6 changed files with 136 additions and 14 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
*.swp
__pycache__/

View File

@ -0,0 +1 @@
from subprocess import call

View File

@ -57,12 +57,24 @@ Shut up, emacs.
(setq ring-bell-function 'ignore)
#+END_SRC
** Show relative line numbers
** Relative line numbers
Use the default emacs relative line numbers, but switch to absolute lines when in insert mode.
#+BEGIN_SRC emacs-lisp
(unless (version< emacs-version "26.1")
(setq display-line-numbers-type 'relative)
(setq linum-format " %3d ")
(global-display-line-numbers-mode t))
(setq-default display-line-numbers 'relative
display-line-numbers-widen t
display-line-numbers-current-absolute t)
(defun foltz-relative-numbers ()
(setq-local display-line-numbers 'relative))
(defun foltz-absolute-numbers ()
(setq-local display-line-numbers t))
(add-hook 'evil-insert-state-entry-hook #'foltz-absolute-numbers)
(add-hook 'evil-insert-state-exit-hook #'foltz-relative-numbers)
(global-display-line-numbers-mode t)
#+END_SRC
** y or n prompts
@ -158,6 +170,7 @@ See [[https://github.com/noctuid/general.el#which-key-integration][here]] for wh
:prefix "SPC"
"m" '(:ignore t :which-key "major-mode...")
"o" '(:ignore t :which-key "org-mode...")
"p" '(:ignore t :which-key "projectile-mode...")
"g" '(:ignore t :which-key "git...")
"h" '(:ignore t :which-key "help...")
"b" '(:ignore t :which-key "buffer...")
@ -181,6 +194,9 @@ See [[https://github.com/noctuid/general.el#which-key-integration][here]] for wh
:prefix "SPC o")
#+END_SRC
**** p - projectile-mode
Since we will be binding the entire projectile-mode
keymap to this, we don't actually need a definer.
**** g - git
#+BEGIN_SRC emacs-lisp
(general-create-definer foltz-git-def
@ -591,6 +607,17 @@ Keybinds [here](https://github.com/emacs-evil/evil-magit)
:after evil))
#+END_SRC
** Projects
Projectile provides project-level features like
make shortcuts and file switching
#+BEGIN_SRC emacs-lisp
(use-package projectile
:bind-keymap
:general
(foltz-leader-def
:states 'normal
"p" '(:keymap projectile-command-map)))
#+END_SRC
** Languages
*** Fish
Beter editing of scripts for the fish shell

80
menu.py Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/python
import curses
from curses import panel
class Menu(object):
def __init__(self, stdscreen, items):
self.window = stdscreen.subwin(0, 0)
self.window.keypad(1)
self.panel = panel.new_panel(self.window)
self.panel.hide()
panel.update_panels()
self.position = 0
self.items = items
self.items.append(('exit', 'exit'))
def navigate(self, n):
self.position += n
self.position %= len(self.items)
def display(self):
self.panel.top()
self.panel.show()
self.window.clear()
while True:
self.window.refresh()
curses.doupdate()
for index, item in enumerate(self.items):
if index == self.position:
mode = curses.A_REVERSE
else:
mode = curses.A_NORMAL
msg = '%d. %s' % (index, item[0])
self.window.addstr(1+index, 1, msg, mode)
key = self.window.getch()
if key in [curses.KEY_ENTER, ord('\n')]:
if self.position == len(self.items)-1:
break
else:
self.items[self.position][1]()
elif key == curses.KEY_UP:
self.navigate(-1)
elif key == curses.KEY_DOWN:
self.navigate(1)
self.window.clear()
self.panel.hide()
panel.update_panels()
curses.doupdate()
class App(object):
def __init__(self, stdscreen):
self.screen = stdscreen
curses.curs_set(0)
submenu_items = [
('beep', curses.beep),
('flash', curses.flash)
]
submenu = Menu(self.screen, submenu_items)
main_menu_items = [
('beep', curses.beep),
('flash', curses.flash),
('submenu', submenu.display)
]
main_menu = Menu(self.screen, main_menu_items)
main_menu.display()
if __name__ == '__main__':
curses.wrapper(App)

View File

@ -1,30 +1,34 @@
#!/usr/bin/python
import re
class Package:
def __init__(self, line):
self.type = line[0]
self.name = line[1]
self.script = line[2] if len(line) == 3 else None
type = None
name = None
script = None
@staticmethod
def is_package_line(line):
return re.match(r"^[^*]+", line[0])
class Category:
def __init__(self, line):
self.name = ' '.join(line[1:])
self.packages = []
name = ''
packages = []
@staticmethod
def is_category_line(line):
return re.match(r"^\*+", line[0])
def split(lines):
return list(map(lambda line: line.rstrip().split(' '), lines))
def parse_package_listing(file):
f = open(file, 'r')
lines = list(map(lambda l: l.rstrip().split(' '), f.readlines()))
categories = []
category = None
for line in lines:
if line[0].startswith('*'):
for line in split(f.readlines()):
if Category.is_category_line(line):
category = Category(line)
categories.append(category)
elif len(line[0]) != 0:
elif Package.is_package_line(line):
category.packages.append(Package(line))
return categories

10
test.py Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/python
import parse
categories = parse.parse_package_listing('packages.org')
for category in categories:
print(category.name)
for package in category.packages:
print('- ' + package.name)