Skip to content

Commit 3c9e87e

Browse files
committed
Remove multiline handing attemp, Fix #5
1 parent cf8c513 commit 3c9e87e

File tree

1 file changed

+0
-32
lines changed

1 file changed

+0
-32
lines changed

powershell_kernel/powershell_repl.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@
66
import re
77
from . import subprocess_repl
88

9-
# PowerShell in interactive mode shows no prompt, so we must hold it by hand.
10-
# Every command prepended with other command, which will output only one character ('.')
11-
# When user command leads to no output (for example, 'cd ..'), we get only this character,
12-
# and then we send command to show prompt explicitly.
13-
# No output at all means, that PowerShell needs more input (multiline mode).
14-
# In this case we proceeds sending user input without modifications.
15-
169
class PowershellRepl(subprocess_repl.SubprocessRepl):
1710
TYPE = "powershell"
18-
PREPENDER = b"."
1911

2012
def __init__(self, encoding, **kwds):
2113
if not encoding:
@@ -26,42 +18,18 @@ def __init__(self, encoding, **kwds):
2618
raise LookupError("Can't detect encoding from chcp")
2719
encoding = "cp" + chcp_encoding.groups()[0]
2820
print(encoding)
29-
3021
super(PowershellRepl, self).__init__(encoding, **kwds)
3122

32-
# Using this to detect whether PowerShell returns some output or it needs more input
33-
# PowerShell in interactive mode doesn't show prompt, so we must hold it by hand
34-
# It's a hack and, for example, we can send 'Write-Host "" -NoNewLine' with no output, but in outhr cases it may work well
35-
self.got_output = True
36-
self.multiline = False
37-
3823
def read_bytes(self):
3924
# this is windows specific problem, that you cannot tell if there
4025
# are more bytes ready, so we read only 1 at a times
4126

4227
result = super(PowershellRepl, self).read_bytes()
43-
44-
# Consumes output (it must be equal to PREPENDER)
45-
if result and not self.got_output:
46-
self.got_output = True
47-
self.multiline = False
48-
# Don't return PREPENDER, read another input
49-
return self.read_bytes()
50-
5128
return result
5229

5330
def write_bytes(self, bytes):
5431
# Drop flag on new input
55-
self.got_output = False
56-
if not self.multiline:
57-
# Turn multiline mode on, it will be turned off, when PowerShell returns some output
58-
self.multiline = True
59-
self.prepend()
6032
self.do_write(bytes)
6133

6234
def do_write(self, bytes):
6335
super(PowershellRepl, self).write_bytes(bytes)
64-
65-
def prepend(self):
66-
""" Command to prepend every output with special mark to detect multiline mode """
67-
self.do_write(b'Write-Host "' + PowershellRepl.PREPENDER + b'" -NoNewLine; ')

0 commit comments

Comments
 (0)