Skip to content

Commit 7bb96b3

Browse files
authored
Merge pull request #103 from Dyalog/multiline
Added multi-line mode.
2 parents a3d29f1 + 6b41e4f commit 7bb96b3

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

dyalog_kernel/kernel.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def __init__(self, **kwargs):
229229
0] + "\\dyalog.exe"
230230
CloseKey(dyalogKey)
231231
CloseKey(lastKey)
232-
self.dyalog_subprocess = subprocess.Popen([dyalogPath, "RIDE_SPAWNED=1", "DYALOGQUIETUCMDBUILD=1", 'RIDE_INIT=SERVE::' + str(
232+
self.dyalog_subprocess = subprocess.Popen([dyalogPath, "RIDE_SPAWNED=1", "DYALOGQUIETUCMDBUILD=1", "Dyalog_LineEditor_Mode=1", 'RIDE_INIT=SERVE::' + str(
233233
self._port).strip(), 'LOG_FILE=nul', os.path.dirname(os.path.abspath(__file__)) + '/init.dws'])
234234
else:
235235
# linux, darwin... etc
@@ -239,6 +239,7 @@ def __init__(self, **kwargs):
239239
dyalog_env['DYALOGQUIETUCMDBUILD'] = '1'
240240
dyalog_env['ENABLE_CEF'] = '0'
241241
dyalog_env['LOG_FILE'] = '/dev/null'
242+
dyalog_env['DYALOG_LINEEDITOR_MODE'] = '1'
242243
if sys.platform.lower() == "darwin":
243244
for d in sorted(os.listdir('/Applications')):
244245
if re.match('^Dyalog-\d+\.\d+\.app$', d):
@@ -336,7 +337,6 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
336337
if self.connected:
337338
lines = code.split('\n')
338339
match = re.search('^%suspend\s+(\w+)$',lines[0].lower(), re.IGNORECASE)
339-
nsmatch = re.match('^\\s*:namespace|:class|:interface',lines[0].lower())
340340
if match:
341341
suspend = match.group(1)
342342
if suspend == 'on':
@@ -354,26 +354,11 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
354354
self.out_error(
355355
'JUPYTER NOTEBOOK: UNDEFINED ARGUMENT TO %suspend, USE EITHER on OR off')
356356
lines = lines[1:]
357-
elif re.match('^\\s*∇', lines[0]):
358-
if not re.match('\\s*∇$', lines[-1]):
359-
self.out_error('DEFN ERROR: Missing closing ∇')
360-
else:
361-
lines[0] = re.sub('^\\s*∇', '', lines[0])
362-
lines = lines[:-1]
363-
self.define_function(lines)
364-
lines = []
365357
elif lines[0].lower() == ']dinput':
366-
self.define_function(lines[1:])
367-
lines = []
368-
elif nsmatch:
369-
if not re.match(":end"+re.sub("^\\s*:",'',nsmatch.group(0)),lines[-1].lower()):
370-
self.out_error("DEFN ERROR: No "+":End"+re.sub("^\\s*:",'',nsmatch.group(0)))
371-
lines = []
372-
else:
373-
self.define_function(lines)
374-
lines = []
358+
lines = lines[1:]
375359
try:
376360
# the windows interpreter can only handle ~125 chacaters at a time, so we do one line at a time
361+
pt = None
377362
for line in lines:
378363
line = line + '\n'
379364
self.execute_line(line)
@@ -393,7 +378,7 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
393378
received = dq.pop()
394379

395380
if received[0] == 'AppendSessionOutput':
396-
if not PROMPT_AVAILABLE:
381+
if (not PROMPT_AVAILABLE) and (received[1].get('type') != 14):
397382
data_collection = data_collection + \
398383
received[1].get('result')
399384
elif received[0] == 'SetPromptType':
@@ -413,6 +398,8 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
413398
self.execute_line("→\n")
414399
raise ValueError(
415400
'JUPYTER NOTEBOOK: Input through ⎕ is not supported')
401+
elif pt == 3:
402+
break
416403
elif pt == 4:
417404
time.sleep(1)
418405
raise ValueError(
@@ -434,6 +421,14 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
434421
self.ride_send(
435422
["ReplyOptionsDialog", {"index": -1, "token": received[1].get('token')}])
436423
# self.pa(received[1].get('input'))
424+
if pt == 3:
425+
self.ride_send(["WeakInterrupt", {}]) #should be StrongInterrupt, which is not working
426+
if not SUSPEND:
427+
self.execute_line("→\n")
428+
self.out_error('INPUT INTERRUPT: Incomplete code block')
429+
self.ride_receive_wait()
430+
dq.clear()
431+
437432
except KeyboardInterrupt:
438433
self.ride_send(["StrongInterrupt", {}])
439434
if not SUSPEND:

0 commit comments

Comments
 (0)