Skip to content

Commit

Permalink
Fixed Ctrl-C problem
Browse files Browse the repository at this point in the history
  • Loading branch information
mambo committed Jun 21, 2016
1 parent 0377566 commit 1b5f374
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 0 additions & 2 deletions acid/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

import os
import signal
import argparse

from acid.parser import Parser, tokenize
Expand Down Expand Up @@ -65,7 +64,6 @@ def compile(path):

def interactive(path=None):
repl = REPL()
signal.signal(signal.SIGINT, lambda *_: repl.quit())

if path is not None:
repl.load(path)
Expand Down
13 changes: 10 additions & 3 deletions acid/repl/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@ def read_command(self):
Reads a user-typed REPL command from the input stream.
"""

print(self.prompt.format(**self.__dict__), end='')
inp = input()
try:
inp = input(self.prompt.format(**self.__dict__))
except EOFError:
print('')
inp = ''

cmd = parse_repl_line(inp)

return cmd

def quit(self):
Expand All @@ -133,12 +137,15 @@ def run(self, display_header=True):

self.running = True

print(self.header)
if display_header:
print(self.header)

while self.running:
try:
cmd = self.read_command()
res = cmd.execute(self)
except KeyboardInterrupt:
print('Interrupted.')
except Exception as exc:
if self.path is None:
msg = 'File <stdin>, input #{repl.cmd_count}'.format(repl=self)
Expand Down

0 comments on commit 1b5f374

Please sign in to comment.