Commit 2019a8fb authored by louis-riviere-xyz's avatar louis-riviere-xyz
Browse files

complet

parent a1417274
import readline
readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')
from cmd import Cmd
from setux.main import banner
from setux.logger import logger
from setux.logger import logger, error
from .helps import helps
from . import commands
def setup_readline():
try:
import readline
except ImportError:
error('readline not found')
raise
readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')
readline.set_completer_delims(' \t\n')
from os import environ
from os.path import join, isfile, expanduser
inputrc = environ.get('INPUTRC')
if inputrc is None:
inputrc = join(expanduser("~"), '.inputrc')
if not isfile(inputrc):
inputrc = '/etc/inputrc'
try:
readline.read_init_file(inputrc)
except Exception as x:
error(x)
def safe(cmd, target):
def wrapper(arg):
try:
......@@ -26,10 +47,11 @@ def prompt(target):
class Repl(Cmd):
def __init__(self, target):
super().__init__()
setup_readline()
self.prompt = prompt(target)
for name, cmd in commands.items():
setattr(self, f'do_{name}', safe(cmd, target))
super().__init__()
def do_help(self, cmd):
def title(txt):
......@@ -65,6 +87,13 @@ class Repl(Cmd):
def do_EOF(self, arg):
return True
def completedefault(text, line, begidx, endidx):
print(11111, text, line, begidx, endidx)
return [1, 2, 3]
def complete_install(text, line, begidx, endidx):
print(11111, text, line, begidx, endidx)
return [1, 2, 3]
def repl(target):
Repl(target).cmdloop()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment