disable readline functionality on windows

This commit is contained in:
Lincoln Stein
2022-08-18 16:00:44 -04:00
parent bb46c70ec5
commit ac440a1197

View File

@ -1,11 +1,16 @@
#!/usr/bin/env python #!/usr/bin/env python
import readline
import argparse import argparse
import shlex import shlex
import atexit import atexit
import os import os
# readline will be disabled on windows systems
try:
import readline
readline_available = True
except:
readline_available = False
debugging = False debugging = False
def main(): def main():
@ -26,6 +31,7 @@ def main():
weights = "models/ldm/stable-diffusion-v1/model.ckpt" weights = "models/ldm/stable-diffusion-v1/model.ckpt"
# command line history will be stored in a file called "~/.dream_history" # command line history will be stored in a file called "~/.dream_history"
if readline_available:
setup_readline() setup_readline()
print("* Initializing, be patient...\n") print("* Initializing, be patient...\n")
@ -174,7 +180,8 @@ def create_cmd_parser():
parser.add_argument('-f','--strength',default=0.75,type=float,help="strength for noising/unnoising. 0.0 preserves image exactly, 1.0 replaces it completely") parser.add_argument('-f','--strength',default=0.75,type=float,help="strength for noising/unnoising. 0.0 preserves image exactly, 1.0 replaces it completely")
return parser return parser
def setup_readline(): if readline_available:
def setup_readline():
readline.set_completer(Completer(['--steps','-s','--seed','-S','--iterations','-n','--batch_size','-b', readline.set_completer(Completer(['--steps','-s','--seed','-S','--iterations','-n','--batch_size','-b',
'--width','-W','--height','-H','--cfg_scale','-C','--grid','-g', '--width','-W','--height','-H','--cfg_scale','-C','--grid','-g',
'--individual','-i','--init_img','-I','--strength','-f']).complete) '--individual','-i','--init_img','-I','--strength','-f']).complete)
@ -182,7 +189,7 @@ def setup_readline():
readline.parse_and_bind('tab: complete') readline.parse_and_bind('tab: complete')
load_history() load_history()
def load_history(): def load_history():
histfile = os.path.join(os.path.expanduser('~'),".dream_history") histfile = os.path.join(os.path.expanduser('~'),".dream_history")
try: try:
readline.read_history_file(histfile) readline.read_history_file(histfile)
@ -191,7 +198,7 @@ def load_history():
pass pass
atexit.register(readline.write_history_file,histfile) atexit.register(readline.write_history_file,histfile)
class Completer(): class Completer():
def __init__(self,options): def __init__(self,options):
self.options = sorted(options) self.options = sorted(options)
return return