aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwustho <benawiadha@gmail.com>2020-03-01 20:29:43 +0700
committerwustho <benawiadha@gmail.com>2020-03-01 20:29:43 +0700
commit898fa943070b82580f402b32d9d11902f440a0fc (patch)
tree315239b931b7c0eeca52a06244d0fe70d8702071
parent252b5e27d0a50c48a8da4382d5eb19b0faac1cde (diff)
downloadepy-898fa943070b82580f402b32d9d11902f440a0fc.tar.gz
Added func: input_prompt
-rwxr-xr-xepy.py105
1 files changed, 61 insertions, 44 deletions
diff --git a/epy.py b/epy.py
index c70d54a..d77ee3c 100755
--- a/epy.py
+++ b/epy.py
@@ -14,7 +14,7 @@ Options:
"""
-__version__ = "2020.2.17"
+__version__ = "2020.3.1"
__license__ = "MIT"
__author__ = "Benawi Adha"
__url__ = "https://github.com/wustho/epy"
@@ -593,6 +593,59 @@ def help():
return "Help", src, K["Help"]
+def input_prompt(prompt):
+ rows, cols = SCREEN.getmaxyx()
+ stat = curses.newwin(1, cols, rows-1, 0)
+ if COLORSUPPORT:
+ stat.bkgd(SCREEN.getbkgd())
+ stat.keypad(True)
+ curses.echo(1)
+ curses.curs_set(1)
+
+ init_text = ""
+
+ stat.addstr(0, 0, " " + prompt + ":", curses.A_REVERSE)
+ stat.addstr(0, 7, init_text)
+ stat.refresh()
+
+ try:
+ while True:
+ ipt = stat.getch()
+ if ipt == 27:
+ stat.clear()
+ stat.refresh()
+ curses.echo(0)
+ curses.curs_set(0)
+ return
+ elif ipt == 10:
+ stat.clear()
+ stat.refresh()
+ curses.echo(0)
+ curses.curs_set(0)
+ return init_text
+ elif ipt in {8, curses.KEY_BACKSPACE}:
+ init_text = init_text[:-1]
+ elif ipt == curses.KEY_RESIZE:
+ stat.clear()
+ stat.refresh()
+ curses.echo(0)
+ curses.curs_set(0)
+ return curses.KEY_RESIZE
+ else:
+ init_text += chr(ipt)
+
+ stat.clear()
+ stat.addstr(0, 0, " " + prompt + ":", curses.A_REVERSE)
+ stat.addstr(0, 7, init_text)
+ stat.refresh()
+ except KeyboardInterrupt:
+ stat.clear()
+ stat.refresh()
+ curses.echo(0)
+ curses.curs_set(0)
+ return
+
+
def dots_path(curr, tofi):
candir = curr.split("/")
tofi = tofi.split("/")
@@ -658,49 +711,13 @@ def searching(pad, src, width, y, ch, tot):
rows, cols = SCREEN.getmaxyx()
x = (cols - width) // 2
if SEARCHPATTERN is None:
- stat = curses.newwin(1, cols, rows-1, 0)
- if COLORSUPPORT:
- stat.bkgd(SCREEN.getbkgd())
- stat.keypad(True)
- curses.echo(1)
- curses.curs_set(1)
- SEARCHPATTERN = ""
- stat.addstr(0, 0, " Regex:", curses.A_REVERSE)
- stat.addstr(0, 7, SEARCHPATTERN)
- stat.refresh()
- while True:
- ipt = stat.getch()
- if ipt == 27:
- stat.clear()
- stat.refresh()
- curses.echo(0)
- curses.curs_set(0)
- SEARCHPATTERN = None
- return y
- elif ipt == 10:
- SEARCHPATTERN = "/"+SEARCHPATTERN
- stat.clear()
- stat.refresh()
- curses.echo(0)
- curses.curs_set(0)
- break
- # TODO: why different behaviour unix dos or win lin
- elif ipt in {8, curses.KEY_BACKSPACE}:
- SEARCHPATTERN = SEARCHPATTERN[:-1]
- elif ipt == curses.KEY_RESIZE:
- stat.clear()
- stat.refresh()
- curses.echo(0)
- curses.curs_set(0)
- SEARCHPATTERN = None
- return curses.KEY_RESIZE
- else:
- SEARCHPATTERN += chr(ipt)
-
- stat.clear()
- stat.addstr(0, 0, " Regex:", curses.A_REVERSE)
- stat.addstr(0, 7, SEARCHPATTERN)
- stat.refresh()
+ candtext = input_prompt("Regex")
+ if candtext is None:
+ return y
+ elif isinstance(candtext, str):
+ SEARCHPATTERN = "/" + candtext
+ elif candtext == curses.KEY_RESIZE:
+ return candtext
if SEARCHPATTERN in {"?", "/"}:
SEARCHPATTERN = None