Skip to content

Commit

Permalink
cli: remove readline import
Browse files Browse the repository at this point in the history
Bug-Url: #1161
  • Loading branch information
svinota committed Jan 31, 2024
1 parent 68a5c1b commit 568e38b
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pyroute2/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@
from pyroute2.cli.session import Session
from pyroute2.ndb.main import NDB

try:
import readline

HAS_READLINE = True
except ImportError:
HAS_READLINE = False


class Console(code.InteractiveConsole):
def __init__(self, stdout=None, log=None, sources=None):
global HAS_READLINE
self.db = NDB(log=log, sources=sources)
self.db.config.update(
{'show_format': 'json', 'recordset_pipe': 'true'}
Expand All @@ -28,10 +20,6 @@ def __init__(self, stdout=None, log=None, sources=None):
self.prompt = ''
self.set_prompt()
code.InteractiveConsole.__init__(self)
if HAS_READLINE:
readline.parse_and_bind('tab: complete')
readline.set_completer(self.completer)
readline.set_completion_display_matches_hook(self.display)

def close(self):
self.db.close()
Expand Down Expand Up @@ -92,6 +80,11 @@ def interact(self, readfunc=None):
self.showtraceback()
continue

def set_completer(self, readline):
readline.parse_and_bind('tab: complete')
readline.set_completer(self.completer)
readline.set_completion_display_matches_hook(self.display)

def completer(self, text, state):
if state == 0:
d = [x for x in dir(self.session.ptr) if x.startswith(text)]
Expand Down

0 comments on commit 568e38b

Please sign in to comment.