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

Added multi-line mode. #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 15 additions & 20 deletions dyalog_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def __init__(self, **kwargs):
0] + "\\dyalog.exe"
CloseKey(dyalogKey)
CloseKey(lastKey)
self.dyalog_subprocess = subprocess.Popen([dyalogPath, "RIDE_SPAWNED=1", "DYALOGQUIETUCMDBUILD=1", 'RIDE_INIT=SERVE::' + str(
self.dyalog_subprocess = subprocess.Popen([dyalogPath, "RIDE_SPAWNED=1", "DYALOGQUIETUCMDBUILD=1", "Dyalog_LineEditor_Mode=1", 'RIDE_INIT=SERVE::' + str(
self._port).strip(), 'LOG_FILE=nul', os.path.dirname(os.path.abspath(__file__)) + '/init.dws'])
else:
# linux, darwin... etc
Expand All @@ -239,6 +239,7 @@ def __init__(self, **kwargs):
dyalog_env['DYALOGQUIETUCMDBUILD'] = '1'
dyalog_env['ENABLE_CEF'] = '0'
dyalog_env['LOG_FILE'] = '/dev/null'
dyalog_env['DYALOG_LINEEDITOR_MODE'] = '1'
if sys.platform.lower() == "darwin":
for d in sorted(os.listdir('/Applications')):
if re.match('^Dyalog-\d+\.\d+\.app$', d):
Expand Down Expand Up @@ -336,7 +337,6 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
if self.connected:
lines = code.split('\n')
match = re.search('^%suspend\s+(\w+)$',lines[0].lower(), re.IGNORECASE)
nsmatch = re.match('^\\s*:namespace|:class|:interface',lines[0].lower())
if match:
suspend = match.group(1)
if suspend == 'on':
Expand All @@ -354,26 +354,11 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
self.out_error(
'JUPYTER NOTEBOOK: UNDEFINED ARGUMENT TO %suspend, USE EITHER on OR off')
lines = lines[1:]
elif re.match('^\\s*∇', lines[0]):
if not re.match('\\s*∇$', lines[-1]):
self.out_error('DEFN ERROR: Missing closing ∇')
else:
lines[0] = re.sub('^\\s*∇', '', lines[0])
lines = lines[:-1]
self.define_function(lines)
lines = []
elif lines[0].lower() == ']dinput':
self.define_function(lines[1:])
lines = []
elif nsmatch:
if not re.match(":end"+re.sub("^\\s*:",'',nsmatch.group(0)),lines[-1].lower()):
self.out_error("DEFN ERROR: No "+":End"+re.sub("^\\s*:",'',nsmatch.group(0)))
lines = []
else:
self.define_function(lines)
lines = []
lines = lines[1:]
try:
# the windows interpreter can only handle ~125 chacaters at a time, so we do one line at a time
pt = None
for line in lines:
line = line + '\n'
self.execute_line(line)
Expand All @@ -393,7 +378,7 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
received = dq.pop()

if received[0] == 'AppendSessionOutput':
if not PROMPT_AVAILABLE:
if (not PROMPT_AVAILABLE) and (received[1].get('type') != 14):
data_collection = data_collection + \
received[1].get('result')
elif received[0] == 'SetPromptType':
Expand All @@ -413,6 +398,8 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
self.execute_line("→\n")
raise ValueError(
'JUPYTER NOTEBOOK: Input through ⎕ is not supported')
elif pt == 3:
break
elif pt == 4:
time.sleep(1)
raise ValueError(
Expand All @@ -434,6 +421,14 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
self.ride_send(
["ReplyOptionsDialog", {"index": -1, "token": received[1].get('token')}])
# self.pa(received[1].get('input'))
if pt == 3:
self.ride_send(["WeakInterrupt", {}]) #should be StrongInterrupt, which is not working
if not SUSPEND:
self.execute_line("→\n")
self.out_error('INPUT INTERRUPT: Incomplete code block')
self.ride_receive_wait()
dq.clear()

except KeyboardInterrupt:
self.ride_send(["StrongInterrupt", {}])
if not SUSPEND:
Expand Down