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