##// END OF EJS Templates
Merge pull request #4649 from arunpersaud/master...
Thomas Kluyver -
r13842:10151c20 merge
parent child Browse files
Show More
@@ -55,14 +55,18 b' def get_default_editor():'
55 55 else:
56 56 return 'notepad' # same in Windows!
57 57
58 def get_pasted_lines(sentinel, l_input=py3compat.input):
58 def get_pasted_lines(sentinel, l_input=py3compat.input, quiet=False):
59 59 """ Yield pasted lines until the user enters the given sentinel value.
60 60 """
61 print("Pasting code; enter '%s' alone on the line to stop or use Ctrl-D." \
62 % sentinel)
61 if not quiet:
62 print("Pasting code; enter '%s' alone on the line to stop or use Ctrl-D." \
63 % sentinel)
64 prompt = ":"
65 else:
66 prompt = ""
63 67 while True:
64 68 try:
65 l = l_input(':')
69 l = l_input(prompt)
66 70 if l == sentinel:
67 71 return
68 72 else:
@@ -133,7 +137,7 b' class TerminalMagics(Magics):'
133 137
134 138 You must terminate the block with '--' (two minus-signs) or Ctrl-D
135 139 alone on the line. You can also provide your own sentinel with '%paste
136 -s %%' ('%%' is the new sentinel for this operation)
140 -s %%' ('%%' is the new sentinel for this operation).
137 141
138 142 The block is dedented prior to execution to enable execution of method
139 143 definitions. '>' and '+' characters at the beginning of a line are
@@ -147,6 +151,7 b' class TerminalMagics(Magics):'
147 151 dedenting or executing it (preceding >>> and + is still stripped)
148 152
149 153 '%cpaste -r' re-executes the block previously entered by cpaste.
154 '%cpaste -q' suppresses any additional output messages.
150 155
151 156 Do not be alarmed by garbled output on Windows (it's a readline bug).
152 157 Just press enter and type -- (and press enter again) and the block
@@ -169,13 +174,15 b' class TerminalMagics(Magics):'
169 174 :--
170 175 Hello world!
171 176 """
172 opts, name = self.parse_options(parameter_s, 'rs:', mode='string')
177 opts, name = self.parse_options(parameter_s, 'rqs:', mode='string')
173 178 if 'r' in opts:
174 179 self.rerun_pasted()
175 180 return
176 181
182 quiet = ('q' in opts)
183
177 184 sentinel = opts.get('s', '--')
178 block = '\n'.join(get_pasted_lines(sentinel))
185 block = '\n'.join(get_pasted_lines(sentinel, quiet=quiet))
179 186 self.store_or_execute(block, name)
180 187
181 188 @line_magic
General Comments 0
You need to be logged in to leave comments. Login now