Remove trailing spaces and replace tabs with spaces

This commit is contained in:
Simonas Kazlauskas 2012-08-19 22:55:50 +03:00
parent e3ec361552
commit b3e3f041fe

View file

@ -18,7 +18,7 @@ def run_fish_cmd(text):
from subprocess import PIPE from subprocess import PIPE
p = subprocess.Popen(["fish"], stdin=PIPE, stdout=PIPE, stderr=PIPE) p = subprocess.Popen(["fish"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
if IS_PY2: if IS_PY2:
out, err = p.communicate(text) out, err = p.communicate(text)
else: else:
out, err = p.communicate(bytes(text, 'utf-8')) out, err = p.communicate(bytes(text, 'utf-8'))
out = str(out, 'utf-8') out = str(out, 'utf-8')
@ -26,9 +26,9 @@ def run_fish_cmd(text):
return(out, err) return(out, err)
def escape_fish_cmd(text): def escape_fish_cmd(text):
# Replace one backslash with two, and single quotes with backslash-quote # Replace one backslash with two, and single quotes with backslash-quote
escaped = text.replace('\\', '\\\\').replace("'", "\\'") escaped = text.replace('\\', '\\\\').replace("'", "\\'")
return "'" + escaped + "'" return "'" + escaped + "'"
named_colors = { named_colors = {
'black' : '000000', 'black' : '000000',
@ -56,14 +56,14 @@ def parse_one_color(comp):
return '' return ''
def better_color(c1, c2): def better_color(c1, c2):
""" Indicate which color is "better", i.e. prefer term256 colors """ """ Indicate which color is "better", i.e. prefer term256 colors """
if not c2: return c1 if not c2: return c1
if not c1: return c2 if not c1: return c2
if c1 == 'normal': return c2 if c1 == 'normal': return c2
if c2 == 'normal': return c1 if c2 == 'normal': return c1
if c2 in named_colors: return c1 if c2 in named_colors: return c1
if c1 in named_colors: return c2 if c1 in named_colors: return c2
return c1 return c1
def parse_color(color_str): def parse_color(color_str):
@ -114,9 +114,9 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def write_to_wfile(self, txt): def write_to_wfile(self, txt):
if IS_PY2: if IS_PY2:
self.wfile.write(txt) self.wfile.write(txt)
else: # Python 3 else: # Python 3
self.wfile.write(bytes(txt, 'utf-8')) self.wfile.write(bytes(txt, 'utf-8'))
def do_get_colors(self): def do_get_colors(self):
@ -157,7 +157,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
'operator': 'Like * and ~', 'operator': 'Like * and ~',
'escape': 'Escapes like \\n', 'escape': 'Escapes like \\n',
'cwd': 'Current directory', 'cwd': 'Current directory',
'cwd_root': 'cwd for root user', 'cwd_root': 'cwd for root user',
'valid_path': 'Valid paths', 'valid_path': 'Valid paths',
'autosuggestion': 'Suggested completion' 'autosuggestion': 'Suggested completion'
} }
@ -248,9 +248,9 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
return out return out
def do_delete_history_item(self, history_item_text): def do_delete_history_item(self, history_item_text):
# It's really lame that we always return success here # It's really lame that we always return success here
out, err = run_fish_cmd('builtin history --save --delete -- ' + escape_fish_cmd(history_item_text)) out, err = run_fish_cmd('builtin history --save --delete -- ' + escape_fish_cmd(history_item_text))
return True return True
def do_GET(self): def do_GET(self):
p = self.path p = self.path
@ -332,9 +332,9 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
what = postvars.get(b'what') what = postvars.get(b'what')
what[0] = str(what[0]).lstrip("b'").rstrip("'") what[0] = str(what[0]).lstrip("b'").rstrip("'")
if self.do_delete_history_item(what[0]): if self.do_delete_history_item(what[0]):
output = ["OK"] output = ["OK"]
else: else:
output = ["Unable to delete history item"] output = ["Unable to delete history item"]
else: else:
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_POST(self) return SimpleHTTPServer.SimpleHTTPRequestHandler.do_POST(self)
@ -379,10 +379,10 @@ if PORT > 9000:
# Just look at the first letter # Just look at the first letter
initial_tab = '' initial_tab = ''
if len(sys.argv) > 1: if len(sys.argv) > 1:
for tab in ['functions', 'colors', 'variables', 'history']: for tab in ['functions', 'colors', 'variables', 'history']:
if tab.startswith(sys.argv[1]): if tab.startswith(sys.argv[1]):
initial_tab = '#' + tab initial_tab = '#' + tab
break break
url = 'http://localhost:{0}/{1}'.format(PORT, initial_tab) url = 'http://localhost:{0}/{1}'.format(PORT, initial_tab)
print("Web config started at '{0}'. Hit enter to stop.".format(url)) print("Web config started at '{0}'. Hit enter to stop.".format(url))