Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #58 - Configure is now interruptable #73

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/mud/__about__.py

This file was deleted.

8 changes: 2 additions & 6 deletions src/mud/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def _create_parser() -> ArgumentParser:
parser.add_argument(*DIVERGED_ATTR, action='store_true', help='Filters repositories with diverged branches.')
parser.add_argument(*ASYNC_ATTR, action='store_true', help='Switches asynchronous run feature.')
parser.add_argument(SET_GLOBAL[0], help=f'Sets {BOLD}.mudconfig{RESET} in the current repository as your fallback {BOLD}.mudconfig{RESET}.', action='store_true')
parser.add_argument(VERSION[0], help='Displays the current version of mud.', action='store_true')
parser.add_argument('catch_all', nargs='*', help='Type any commands to execute among repositories.')
return parser

def run(self) -> None:
# Displays default help message
if len(sys.argv) == 1 or sys.argv[1] in HELP:
utils.version()
utils.info()
print()
self.parser.print_help()
return
# Sets global repository in .mudsettings
Expand All @@ -72,10 +72,6 @@ def run(self) -> None:
utils.settings.save()
print(f'Current {BOLD}.mudconfig{RESET} set as a global configuration.')
return
# Prints version
elif sys.argv[1] in VERSION:
utils.version()
return
# Runs configuration wizard
elif sys.argv[1] in CONFIGURE:
utils.configure()
Expand Down
3 changes: 1 addition & 2 deletions src/mud/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
BRANCHES = ['branch', 'branches', 'br']
REMOTE_BRANCHES = ['remote-branch', 'remote-branches', 'rbr']
HELP = ['help', '--help', '-h']
VERSION = ['--version', '-v', 'version']
CONFIGURE = ['configure', 'config']
SET_GLOBAL = ['--set-global']

COMMANDS = [ADD, REMOVE, LOG, INFO, INIT, TAGS, LABELS, STATUS, BRANCHES, REMOTE_BRANCHES, HELP, VERSION, CONFIGURE, SET_GLOBAL]
COMMANDS = [ADD, REMOVE, LOG, INFO, INIT, TAGS, LABELS, STATUS, BRANCHES, REMOTE_BRANCHES, HELP, CONFIGURE, SET_GLOBAL]

# Filters
ASYNC_ATTR = '-a', '--async'
Expand Down
48 changes: 17 additions & 31 deletions src/mud/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from mud.settings import *
from mud.styles import *
from mud.__about__ import __version__

SETTINGS_FILE_NAME = '.mudsettings'
CONFIG_FILE_NAME = '.mudconfig'
Expand All @@ -20,25 +19,18 @@ def glyphs(key: str) -> str:
return GLYPHS[key][0 if settings.config['mud'].getboolean('nerd_fonts', fallback=False) else 1]


def version() -> None:
def info() -> None:
os.chdir(os.path.dirname(os.path.abspath(__file__)))
logo = get_logo()
info = f'Jasur Sadikov <[email protected]>\nhttps://github.com/jasursadikov/mud\n{BOLD}{random.choice(TEXT[3:])}{__version__}{RESET}'
print(logo)
print(info)


def get_logo() -> str:
colors = TEXT[3:]
colors.remove(BRIGHT_WHITE)
m = random.choice(colors)
u = random.choice(colors)
d = random.choice(colors)
logo = f' {d}__{RESET}\n'
logo += f' {m}__ _ {u}__ __{d}___/ /{RESET}\n'
logo += f' {m}/ \' \\{u}/ // / {d}_ /{RESET}\n'
logo += f'{m}/_/_/_/{u}\\_,_/{d}\\_,_/ {RESET}'
return logo
print(f' {d}__{RESET}')
print(f' {m}__ _ {u}__ __{d}___/ /{RESET}')
print(f' {m}/ \' \\{u}/ // / {d}_ /{RESET}')
print(f'{m}/_/_/_/{u}\\_,_/{d}\\_,_/ {RESET}')
print(f'Jasur Sadikov <[email protected]>\nhttps://github.com/jasursadikov/mud')


def configure() -> None:
Expand All @@ -56,23 +48,17 @@ def configure() -> None:


def ask(text: str) -> bool:
print(f'{text} [Y/n] ', end='', flush=True)
if sys.platform.startswith('win'):
from msvcrt import getch
response = getch().decode().lower()
else:
import tty
import termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
response = sys.stdin.read(1).lower()
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)

print()
return response in ['y', '\r', '\n']
try:
answer = input(f"{text}? [Y/n]: ").strip().lower()
if answer in ('y', 'yes', ''):
return True
elif answer in ('n', 'no'):
return False
else:
print("Invalid input.")
return True
except KeyboardInterrupt:
exit()


def print_table(table: PrettyTable) -> None:
Expand Down
Loading