aboutsummaryrefslogtreecommitdiff
path: root/wikijscmd
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2021-10-08 19:21:28 -0500
committerMark Powers <mark@marks.kitchen>2021-10-08 19:21:28 -0500
commit01c2c28dcc9efb83f3d9c38332312e40850309f5 (patch)
treef0e35ac58d3d78c7e2a1603cd1c5f935e428569e /wikijscmd
parente23a1382744f36000006a8df68fb2b4aaa5027af (diff)
Refactor entry points
Diffstat (limited to 'wikijscmd')
-rw-r--r--wikijscmd/__init__.py11
-rw-r--r--wikijscmd/__main__.py6
-rw-r--r--[-rwxr-xr-x]wikijscmd/app.py (renamed from wikijscmd/cli.py)9
-rw-r--r--[-rwxr-xr-x]wikijscmd/tui.py (renamed from wikijscmd/ncurses.py)15
4 files changed, 19 insertions, 22 deletions
diff --git a/wikijscmd/__init__.py b/wikijscmd/__init__.py
index 8f45ae2..e69de29 100644
--- a/wikijscmd/__init__.py
+++ b/wikijscmd/__init__.py
@@ -1,11 +0,0 @@
-from wikijscmd import cli
-from wikijscmd import ncurses
-
-def main():
- cli.cli()
-
-def tui():
- try:
- ncurses.wrapper(m)
- except Exception as e:
- raise e
diff --git a/wikijscmd/__main__.py b/wikijscmd/__main__.py
index 02ddab3..267af9f 100644
--- a/wikijscmd/__main__.py
+++ b/wikijscmd/__main__.py
@@ -1,4 +1,6 @@
-import wikijscmd
+import sys
+
+from . import app
if __name__ == '__main__':
- wikijscmd.main()
+ app.main()
diff --git a/wikijscmd/cli.py b/wikijscmd/app.py
index 2847e40..c16a446 100755..100644
--- a/wikijscmd/cli.py
+++ b/wikijscmd/app.py
@@ -5,8 +5,9 @@ import argparse
from wikijscmd.config import config
from wikijscmd.commands import create, edit, single, tree, today, move, fill_in_pages
+from wikijscmd.tui import tui
-def cli():
+def main():
parser = argparse.ArgumentParser("wikijscmd")
parser.set_defaults(command=None)
subparsers = parser.add_subparsers()
@@ -40,6 +41,9 @@ def cli():
parser_journal = subparsers.add_parser("journal", help="create journal pages")
parser_journal.set_defaults(command=fill_in_pages)
+ parser_tui = subparsers.add_parser("tui", help="lauch a ncurses interface")
+ parser_tui.set_defaults(command=tui)
+
args = vars(parser.parse_args())
callback = args["command"]
if callback is None:
@@ -47,6 +51,3 @@ def cli():
else:
del args["command"]
callback(**args)
-
-if __name__ == "__main__":
- main()
diff --git a/wikijscmd/ncurses.py b/wikijscmd/tui.py
index ecc145f..16232bb 100755..100644
--- a/wikijscmd/ncurses.py
+++ b/wikijscmd/tui.py
@@ -3,7 +3,7 @@
import curses
from curses import wrapper
-from wikijscmd import util
+from wikijscmd import util, commands
def pager(stdscr, lst):
'''
@@ -87,17 +87,22 @@ def m(stdscr):
ret = pager(stdscr, [x["path"] + "\t" + x["title"] for x in items])
if ret["action"] == "select":
selected = items[ret["index"]]
- ret = pager(stdscr, main.get_single_page(selected["path"])["content"].split("\n"))
+ ret = pager(stdscr, util.get_single_page(selected["path"])["content"].split("\n"))
elif ret["action"] == "edit":
selected = items[ret["index"]]
- main.edit({"path":selected["path"], "save": True})
+ commands.edit(selected["path"], True)
elif ret["action"] == "create":
stdscr.clear()
title = enter_value(stdscr, "Enter title: ", 0)
path = enter_value(stdscr, "Enter path: ", 1)
- main.create({"path": path, "title": title})
+ commands.create(path, title)
elif ret["action"] == "today":
- main.today({})
+ commands.today()
else:
break
+def tui():
+ try:
+ wrapper(m)
+ except Exception as e:
+ raise e