From 6a535ae856a4e5f2b4c79793024f5bed8ec77ddf Mon Sep 17 00:00:00 2001 From: Richard Mwewa <74001397+rly0nheart@users.noreply.github.com> Date: Wed, 12 Apr 2023 16:17:51 +0200 Subject: [PATCH] Created a setup_readline function for the code used to setup readline. The function has been moved to config.py, and will be called from main.py --- octosuite/config.py | 22 ++++++++++++++++++++++ octosuite/main.py | 1 + octosuite/octosuite.py | 22 +--------------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/octosuite/config.py b/octosuite/config.py index 03a0eec..b6a49e4 100644 --- a/octosuite/config.py +++ b/octosuite/config.py @@ -146,6 +146,28 @@ def create_parser(): return parser +# Setup readline +def setup_readline(): + if os.name == "nt": + try: + from pyreadline3 import Readline + except ImportError: + subprocess.run(['pip3', 'install', 'pyreadline3'], shell=False) + readline = Readline() + else: + import readline + + def completer(text, state): + options = [i for i in commands if i.startswith(text)] + if state < len(options): + return options[state] + else: + return None + + readline.parse_and_bind("tab: complete") + readline.set_completer(completer) + + parser = create_parser() args = parser.parse_args() diff --git a/octosuite/main.py b/octosuite/main.py index d76cf87..a3be5d9 100644 --- a/octosuite/main.py +++ b/octosuite/main.py @@ -3,6 +3,7 @@ from octosuite.octosuite import * # I drifted away from the 'pythonic way' here def octosuite(): + setup_readline() try: run = Octosuite() path_finder() diff --git a/octosuite/octosuite.py b/octosuite/octosuite.py index 2338e87..5641888 100644 --- a/octosuite/octosuite.py +++ b/octosuite/octosuite.py @@ -12,7 +12,7 @@ import subprocess from datetime import datetime from requests.auth import HTTPBasicAuth from octosuite.banner import version_tag, banner -from octosuite.config import Tree, Text, Table, Prompt, Confirm, Markdown, xprint, create_parser, args, red, white, green, yellow, header_title, reset +from octosuite.config import Tree, Text, Table, Prompt, Confirm, Markdown, xprint, create_parser, setup_readline, args, red, white, green, yellow, header_title, reset from octosuite.message_prefixes import ERROR, WARNING, PROMPT, POSITIVE, NEGATIVE, INFO # wondering why I name all the variables instead of just using the * wildcard?, because it's the pythonic way lol # seriously now, the reason why I am doing this, is so that you know exactly what I am importing from a named module :) from octosuite.helper import help_command, source_command, search_command, user_command, repo_command, \ @@ -27,26 +27,6 @@ from octosuite.csv_loggers import log_org_profile, log_user_profile, log_repo_pr log_commits_search -if os.name == "nt": - try: - from pyreadline3 import Readline - except ImportError: - subprocess.run(['pip3', 'install', 'pyreadline3'], shell=False) - readline = Readline() -else: - import readline - - def completer(text, state): - options = [i for i in commands if i.startswith(text)] - if state < len(options): - return options[state] - else: - return None - - readline.parse_and_bind("tab: complete") - readline.set_completer(completer) - - # path_finder() # This function is responsible for creating/checking the availability of the (.logs, output, downloads) folders, # enabling logging to automatically log network/user activity to a file, and logging the start of a session.