macOS: Fix changing tab title and kitty shell not working
I forgot that Apple has its own special snowflake readline variant. Fixes #494
This commit is contained in:
parent
54438cae3f
commit
f68f8bf9c9
@ -53,7 +53,6 @@ class HistoryCompleter:
|
|||||||
if os.path.exists(self.history_path):
|
if os.path.exists(self.history_path):
|
||||||
readline.read_history_file(self.history_path)
|
readline.read_history_file(self.history_path)
|
||||||
readline.set_completer(self.complete)
|
readline.set_completer(self.complete)
|
||||||
readline.parse_and_bind('tab: complete')
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, *a):
|
def __exit__(self, *a):
|
||||||
@ -87,6 +86,7 @@ def main(args):
|
|||||||
global readline
|
global readline
|
||||||
import readline as rl
|
import readline as rl
|
||||||
readline = rl
|
readline = rl
|
||||||
|
from kitty.shell import init_readline
|
||||||
msg = 'Ask the user for input'
|
msg = 'Ask the user for input'
|
||||||
try:
|
try:
|
||||||
args, items = parse_args(args[1:], option_text, '', msg, 'kitty ask')
|
args, items = parse_args(args[1:], option_text, '', msg, 'kitty ask')
|
||||||
@ -96,7 +96,7 @@ def main(args):
|
|||||||
input('Press enter to quit...')
|
input('Press enter to quit...')
|
||||||
raise SystemExit(e.code)
|
raise SystemExit(e.code)
|
||||||
|
|
||||||
readline.read_init_file()
|
init_readline(readline)
|
||||||
ans = {'items': items}
|
ans = {'items': items}
|
||||||
|
|
||||||
with alternate_screen(), HistoryCompleter(args.name):
|
with alternate_screen(), HistoryCompleter(args.name):
|
||||||
|
|||||||
@ -14,12 +14,24 @@ from .cli import (
|
|||||||
emph, green, italic, parse_option_spec, print_help_for_seq, title
|
emph, green, italic, parse_option_spec, print_help_for_seq, title
|
||||||
)
|
)
|
||||||
from .cmds import cmap, display_subcommand_help, parse_subcommand_cli
|
from .cmds import cmap, display_subcommand_help, parse_subcommand_cli
|
||||||
from .constants import cache_dir, version
|
from .constants import cache_dir, is_macos, version
|
||||||
|
|
||||||
all_commands = tuple(sorted(cmap))
|
all_commands = tuple(sorted(cmap))
|
||||||
match_commands = tuple(sorted(all_commands + ('exit', 'help', 'quit')))
|
match_commands = tuple(sorted(all_commands + ('exit', 'help', 'quit')))
|
||||||
|
|
||||||
|
|
||||||
|
def init_readline(readline):
|
||||||
|
try:
|
||||||
|
readline.read_init_file()
|
||||||
|
except EnvironmentError:
|
||||||
|
if not is_macos:
|
||||||
|
raise
|
||||||
|
if 'libedit' in readline.__doc__:
|
||||||
|
readline.parse_and_bind("bind ^I rl_complete")
|
||||||
|
else:
|
||||||
|
readline.parse_and_bind('tab: complete')
|
||||||
|
|
||||||
|
|
||||||
def cmd_names_matching(prefix):
|
def cmd_names_matching(prefix):
|
||||||
for cmd in match_commands:
|
for cmd in match_commands:
|
||||||
if not prefix or cmd.startswith(prefix):
|
if not prefix or cmd.startswith(prefix):
|
||||||
@ -76,7 +88,6 @@ class Completer:
|
|||||||
if os.path.exists(self.history_path):
|
if os.path.exists(self.history_path):
|
||||||
readline.read_history_file(self.history_path)
|
readline.read_history_file(self.history_path)
|
||||||
readline.set_completer(self.complete)
|
readline.set_completer(self.complete)
|
||||||
readline.parse_and_bind('tab: complete')
|
|
||||||
delims = readline.get_completer_delims()
|
delims = readline.get_completer_delims()
|
||||||
readline.set_completer_delims(delims.replace('-', ''))
|
readline.set_completer_delims(delims.replace('-', ''))
|
||||||
return self
|
return self
|
||||||
@ -141,7 +152,7 @@ def run_cmd(global_opts, cmd, func, opts, items):
|
|||||||
|
|
||||||
|
|
||||||
def real_main(global_opts):
|
def real_main(global_opts):
|
||||||
readline.read_init_file()
|
init_readline(readline)
|
||||||
print_help_for_seq.allow_pager = False
|
print_help_for_seq.allow_pager = False
|
||||||
print('Welcome to the kitty shell!')
|
print('Welcome to the kitty shell!')
|
||||||
print('Use {} for assistance or {} to quit'.format(green('help'), green('exit')))
|
print('Use {} for assistance or {} to quit'.format(green('help'), green('exit')))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user