Description:
add description
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r710:08159fa838b8 - - 1 file changed: 4 inserted, 1 deleted
@@ -1,272 +1,275 | |||||
|
1 | %h2 Live submit |
|
1 | %h2 Live submit |
|
2 | %br |
|
2 | %br |
|
3 |
|
3 | ||
|
4 | %textarea#text_sourcecode{style: "display:none"}~ @source |
|
4 | %textarea#text_sourcecode{style: "display:none"}~ @source |
|
5 | .container |
|
5 | .container |
|
6 | .row |
|
6 | .row |
|
7 | .col-md-12 |
|
7 | .col-md-12 |
|
8 | .alert.alert-info |
|
8 | .alert.alert-info |
|
9 | Write your code in the following box, choose language, and click submit button when finished |
|
9 | Write your code in the following box, choose language, and click submit button when finished |
|
10 | .row |
|
10 | .row |
|
11 | .col-md-8 |
|
11 | .col-md-8 |
|
12 | %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'} |
|
12 | %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'} |
|
13 | .col-md-4 |
|
13 | .col-md-4 |
|
14 | - # submission form |
|
14 | - # submission form |
|
15 | = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do |
|
15 | = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do |
|
16 |
|
16 | ||
|
17 | = hidden_field_tag 'editor_text', @source |
|
17 | = hidden_field_tag 'editor_text', @source |
|
18 | = hidden_field_tag 'submission[problem_id]', @problem.id |
|
18 | = hidden_field_tag 'submission[problem_id]', @problem.id |
|
19 | .form-group |
|
19 | .form-group |
|
20 | = label_tag "Task:" |
|
20 | = label_tag "Task:" |
|
21 | = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true |
|
21 | = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true |
|
|
22 | + .form-group | ||
|
|
23 | + = label_tag "Description:" | ||
|
|
24 | + = link_to_description_if_any "[download] <span class='glyphicon glyphicon-file'></span>".html_safe, @problem | ||
|
22 |
|
25 | ||
|
23 | .form-group |
|
26 | .form-group |
|
24 | - = label_tag 'Language' |
|
27 | + = label_tag 'Language:' |
|
25 | = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name', @lang_id || Language.find_by_pretty_name("Python").id || Language.first.id), class: 'form-control select', style: "width: 100px" |
|
28 | = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name', @lang_id || Language.find_by_pretty_name("Python").id || Language.first.id), class: 'form-control select', style: "width: 100px" |
|
26 | .form-group |
|
29 | .form-group |
|
27 | = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit', |
|
30 | = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit', |
|
28 | data: {confirm: "Submitting this source code for task #{@problem.long_name}?"} |
|
31 | data: {confirm: "Submitting this source code for task #{@problem.long_name}?"} |
|
29 | - # latest submission status |
|
32 | - # latest submission status |
|
30 | .panel{class: (@submission && @submission.graded_at) ? "panel-info" : "panel-warning"} |
|
33 | .panel{class: (@submission && @submission.graded_at) ? "panel-info" : "panel-warning"} |
|
31 | .panel-heading |
|
34 | .panel-heading |
|
32 | Latest Submission Status |
|
35 | Latest Submission Status |
|
33 | = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission |
|
36 | = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission |
|
34 | .panel-body |
|
37 | .panel-body |
|
35 | %div#latest_status |
|
38 | %div#latest_status |
|
36 | - if @submission |
|
39 | - if @submission |
|
37 | = render :partial => 'submission_short', |
|
40 | = render :partial => 'submission_short', |
|
38 | :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id } |
|
41 | :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id } |
|
39 | .row |
|
42 | .row |
|
40 | .col-md-12 |
|
43 | .col-md-12 |
|
41 | %h2 Console |
|
44 | %h2 Console |
|
42 | %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20} |
|
45 | %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20} |
|
43 |
|
46 | ||
|
44 | :javascript |
|
47 | :javascript |
|
45 | $(document).ready(function() { |
|
48 | $(document).ready(function() { |
|
46 | e = ace.edit("editor") |
|
49 | e = ace.edit("editor") |
|
47 | e.setValue($("#text_sourcecode").val()); |
|
50 | e.setValue($("#text_sourcecode").val()); |
|
48 | e.gotoLine(1); |
|
51 | e.gotoLine(1); |
|
49 | $("#language_id").trigger('change'); |
|
52 | $("#language_id").trigger('change'); |
|
50 | brython(); |
|
53 | brython(); |
|
51 | }); |
|
54 | }); |
|
52 |
|
55 | ||
|
53 |
|
56 | ||
|
54 | %script#__main__{type:'text/python3'} |
|
57 | %script#__main__{type:'text/python3'} |
|
55 | :plain |
|
58 | :plain |
|
56 | import sys |
|
59 | import sys |
|
57 | import traceback |
|
60 | import traceback |
|
58 |
|
61 | ||
|
59 | from browser import document as doc |
|
62 | from browser import document as doc |
|
60 | from browser import window, alert, console |
|
63 | from browser import window, alert, console |
|
61 |
|
64 | ||
|
62 | _credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands |
|
65 | _credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands |
|
63 | for supporting Python development. See www.python.org for more information.""" |
|
66 | for supporting Python development. See www.python.org for more information.""" |
|
64 |
|
67 | ||
|
65 | _copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com |
|
68 | _copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com |
|
66 | All Rights Reserved. |
|
69 | All Rights Reserved. |
|
67 |
|
70 | ||
|
68 | Copyright (c) 2001-2013 Python Software Foundation. |
|
71 | Copyright (c) 2001-2013 Python Software Foundation. |
|
69 | All Rights Reserved. |
|
72 | All Rights Reserved. |
|
70 |
|
73 | ||
|
71 | Copyright (c) 2000 BeOpen.com. |
|
74 | Copyright (c) 2000 BeOpen.com. |
|
72 | All Rights Reserved. |
|
75 | All Rights Reserved. |
|
73 |
|
76 | ||
|
74 | Copyright (c) 1995-2001 Corporation for National Research Initiatives. |
|
77 | Copyright (c) 1995-2001 Corporation for National Research Initiatives. |
|
75 | All Rights Reserved. |
|
78 | All Rights Reserved. |
|
76 |
|
79 | ||
|
77 | Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. |
|
80 | Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. |
|
78 | All Rights Reserved.""" |
|
81 | All Rights Reserved.""" |
|
79 |
|
82 | ||
|
80 | _license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com |
|
83 | _license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com |
|
81 | All rights reserved. |
|
84 | All rights reserved. |
|
82 |
|
85 | ||
|
83 | Redistribution and use in source and binary forms, with or without |
|
86 | Redistribution and use in source and binary forms, with or without |
|
84 | modification, are permitted provided that the following conditions are met: |
|
87 | modification, are permitted provided that the following conditions are met: |
|
85 |
|
88 | ||
|
86 | Redistributions of source code must retain the above copyright notice, this |
|
89 | Redistributions of source code must retain the above copyright notice, this |
|
87 | list of conditions and the following disclaimer. Redistributions in binary |
|
90 | list of conditions and the following disclaimer. Redistributions in binary |
|
88 | form must reproduce the above copyright notice, this list of conditions and |
|
91 | form must reproduce the above copyright notice, this list of conditions and |
|
89 | the following disclaimer in the documentation and/or other materials provided |
|
92 | the following disclaimer in the documentation and/or other materials provided |
|
90 | with the distribution. |
|
93 | with the distribution. |
|
91 | Neither the name of the <ORGANIZATION> nor the names of its contributors may |
|
94 | Neither the name of the <ORGANIZATION> nor the names of its contributors may |
|
92 | be used to endorse or promote products derived from this software without |
|
95 | be used to endorse or promote products derived from this software without |
|
93 | specific prior written permission. |
|
96 | specific prior written permission. |
|
94 |
|
97 | ||
|
95 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
98 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
96 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
99 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
97 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
100 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
98 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
101 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
99 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
102 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
100 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
103 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
101 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
104 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
102 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
105 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
103 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
106 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
104 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
107 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
105 | POSSIBILITY OF SUCH DAMAGE. |
|
108 | POSSIBILITY OF SUCH DAMAGE. |
|
106 | """ |
|
109 | """ |
|
107 |
|
110 | ||
|
108 | def credits(): |
|
111 | def credits(): |
|
109 | print(_credits) |
|
112 | print(_credits) |
|
110 | credits.__repr__ = lambda:_credits |
|
113 | credits.__repr__ = lambda:_credits |
|
111 |
|
114 | ||
|
112 | def copyright(): |
|
115 | def copyright(): |
|
113 | print(_copyright) |
|
116 | print(_copyright) |
|
114 | copyright.__repr__ = lambda:_copyright |
|
117 | copyright.__repr__ = lambda:_copyright |
|
115 |
|
118 | ||
|
116 | def license(): |
|
119 | def license(): |
|
117 | print(_license) |
|
120 | print(_license) |
|
118 | license.__repr__ = lambda:_license |
|
121 | license.__repr__ = lambda:_license |
|
119 |
|
122 | ||
|
120 | def write(data): |
|
123 | def write(data): |
|
121 | doc['console'].value += str(data) |
|
124 | doc['console'].value += str(data) |
|
122 |
|
125 | ||
|
123 |
|
126 | ||
|
124 | sys.stdout.write = sys.stderr.write = write |
|
127 | sys.stdout.write = sys.stderr.write = write |
|
125 | history = [] |
|
128 | history = [] |
|
126 | current = 0 |
|
129 | current = 0 |
|
127 | _status = "main" # or "block" if typing inside a block |
|
130 | _status = "main" # or "block" if typing inside a block |
|
128 |
|
131 | ||
|
129 | # execution namespace |
|
132 | # execution namespace |
|
130 | editor_ns = {'credits':credits, |
|
133 | editor_ns = {'credits':credits, |
|
131 | 'copyright':copyright, |
|
134 | 'copyright':copyright, |
|
132 | 'license':license, |
|
135 | 'license':license, |
|
133 | '__name__':'__main__'} |
|
136 | '__name__':'__main__'} |
|
134 |
|
137 | ||
|
135 | def cursorToEnd(*args): |
|
138 | def cursorToEnd(*args): |
|
136 | pos = len(doc['console'].value) |
|
139 | pos = len(doc['console'].value) |
|
137 | doc['console'].setSelectionRange(pos, pos) |
|
140 | doc['console'].setSelectionRange(pos, pos) |
|
138 | doc['console'].scrollTop = doc['console'].scrollHeight |
|
141 | doc['console'].scrollTop = doc['console'].scrollHeight |
|
139 |
|
142 | ||
|
140 | def get_col(area): |
|
143 | def get_col(area): |
|
141 | # returns the column num of cursor |
|
144 | # returns the column num of cursor |
|
142 | sel = doc['console'].selectionStart |
|
145 | sel = doc['console'].selectionStart |
|
143 | lines = doc['console'].value.split('\n') |
|
146 | lines = doc['console'].value.split('\n') |
|
144 | for line in lines[:-1]: |
|
147 | for line in lines[:-1]: |
|
145 | sel -= len(line) + 1 |
|
148 | sel -= len(line) + 1 |
|
146 | return sel |
|
149 | return sel |
|
147 |
|
150 | ||
|
148 |
|
151 | ||
|
149 | def myKeyPress(event): |
|
152 | def myKeyPress(event): |
|
150 | global _status, current |
|
153 | global _status, current |
|
151 | if event.keyCode == 9: # tab key |
|
154 | if event.keyCode == 9: # tab key |
|
152 | event.preventDefault() |
|
155 | event.preventDefault() |
|
153 | doc['console'].value += " " |
|
156 | doc['console'].value += " " |
|
154 | elif event.keyCode == 13: # return |
|
157 | elif event.keyCode == 13: # return |
|
155 | src = doc['console'].value |
|
158 | src = doc['console'].value |
|
156 | if _status == "main": |
|
159 | if _status == "main": |
|
157 | currentLine = src[src.rfind('>>>') + 4:] |
|
160 | currentLine = src[src.rfind('>>>') + 4:] |
|
158 | elif _status == "3string": |
|
161 | elif _status == "3string": |
|
159 | currentLine = src[src.rfind('>>>') + 4:] |
|
162 | currentLine = src[src.rfind('>>>') + 4:] |
|
160 | currentLine = currentLine.replace('\n... ', '\n') |
|
163 | currentLine = currentLine.replace('\n... ', '\n') |
|
161 | else: |
|
164 | else: |
|
162 | currentLine = src[src.rfind('...') + 4:] |
|
165 | currentLine = src[src.rfind('...') + 4:] |
|
163 | if _status == 'main' and not currentLine.strip(): |
|
166 | if _status == 'main' and not currentLine.strip(): |
|
164 | doc['console'].value += '\n>>> ' |
|
167 | doc['console'].value += '\n>>> ' |
|
165 | event.preventDefault() |
|
168 | event.preventDefault() |
|
166 | return |
|
169 | return |
|
167 | doc['console'].value += '\n' |
|
170 | doc['console'].value += '\n' |
|
168 | history.append(currentLine) |
|
171 | history.append(currentLine) |
|
169 | current = len(history) |
|
172 | current = len(history) |
|
170 | if _status == "main" or _status == "3string": |
|
173 | if _status == "main" or _status == "3string": |
|
171 | try: |
|
174 | try: |
|
172 | _ = editor_ns['_'] = eval(currentLine, editor_ns) |
|
175 | _ = editor_ns['_'] = eval(currentLine, editor_ns) |
|
173 | if _ is not None: |
|
176 | if _ is not None: |
|
174 | write(repr(_)+'\n') |
|
177 | write(repr(_)+'\n') |
|
175 | doc['console'].value += '>>> ' |
|
178 | doc['console'].value += '>>> ' |
|
176 | _status = "main" |
|
179 | _status = "main" |
|
177 | except IndentationError: |
|
180 | except IndentationError: |
|
178 | doc['console'].value += '... ' |
|
181 | doc['console'].value += '... ' |
|
179 | _status = "block" |
|
182 | _status = "block" |
|
180 | except SyntaxError as msg: |
|
183 | except SyntaxError as msg: |
|
181 | if str(msg) == 'invalid syntax : triple string end not found' or \ |
|
184 | if str(msg) == 'invalid syntax : triple string end not found' or \ |
|
182 | str(msg).startswith('Unbalanced bracket'): |
|
185 | str(msg).startswith('Unbalanced bracket'): |
|
183 | doc['console'].value += '... ' |
|
186 | doc['console'].value += '... ' |
|
184 | _status = "3string" |
|
187 | _status = "3string" |
|
185 | elif str(msg) == 'eval() argument must be an expression': |
|
188 | elif str(msg) == 'eval() argument must be an expression': |
|
186 | try: |
|
189 | try: |
|
187 | exec(currentLine, editor_ns) |
|
190 | exec(currentLine, editor_ns) |
|
188 | except: |
|
191 | except: |
|
189 | traceback.print_exc() |
|
192 | traceback.print_exc() |
|
190 | doc['console'].value += '>>> ' |
|
193 | doc['console'].value += '>>> ' |
|
191 | _status = "main" |
|
194 | _status = "main" |
|
192 | elif str(msg) == 'decorator expects function': |
|
195 | elif str(msg) == 'decorator expects function': |
|
193 | doc['console'].value += '... ' |
|
196 | doc['console'].value += '... ' |
|
194 | _status = "block" |
|
197 | _status = "block" |
|
195 | else: |
|
198 | else: |
|
196 | traceback.print_exc() |
|
199 | traceback.print_exc() |
|
197 | doc['console'].value += '>>> ' |
|
200 | doc['console'].value += '>>> ' |
|
198 | _status = "main" |
|
201 | _status = "main" |
|
199 | except: |
|
202 | except: |
|
200 | traceback.print_exc() |
|
203 | traceback.print_exc() |
|
201 | doc['console'].value += '>>> ' |
|
204 | doc['console'].value += '>>> ' |
|
202 | _status = "main" |
|
205 | _status = "main" |
|
203 | elif currentLine == "": # end of block |
|
206 | elif currentLine == "": # end of block |
|
204 | block = src[src.rfind('>>>') + 4:].splitlines() |
|
207 | block = src[src.rfind('>>>') + 4:].splitlines() |
|
205 | block = [block[0]] + [b[4:] for b in block[1:]] |
|
208 | block = [block[0]] + [b[4:] for b in block[1:]] |
|
206 | block_src = '\n'.join(block) |
|
209 | block_src = '\n'.join(block) |
|
207 | # status must be set before executing code in globals() |
|
210 | # status must be set before executing code in globals() |
|
208 | _status = "main" |
|
211 | _status = "main" |
|
209 | try: |
|
212 | try: |
|
210 | _ = exec(block_src, editor_ns) |
|
213 | _ = exec(block_src, editor_ns) |
|
211 | if _ is not None: |
|
214 | if _ is not None: |
|
212 | print(repr(_)) |
|
215 | print(repr(_)) |
|
213 | except: |
|
216 | except: |
|
214 | traceback.print_exc() |
|
217 | traceback.print_exc() |
|
215 | doc['console'].value += '>>> ' |
|
218 | doc['console'].value += '>>> ' |
|
216 | else: |
|
219 | else: |
|
217 | doc['console'].value += '... ' |
|
220 | doc['console'].value += '... ' |
|
218 |
|
221 | ||
|
219 | cursorToEnd() |
|
222 | cursorToEnd() |
|
220 | event.preventDefault() |
|
223 | event.preventDefault() |
|
221 |
|
224 | ||
|
222 | def myKeyDown(event): |
|
225 | def myKeyDown(event): |
|
223 | global _status, current |
|
226 | global _status, current |
|
224 | if event.keyCode == 37: # left arrow |
|
227 | if event.keyCode == 37: # left arrow |
|
225 | sel = get_col(doc['console']) |
|
228 | sel = get_col(doc['console']) |
|
226 | if sel < 5: |
|
229 | if sel < 5: |
|
227 | event.preventDefault() |
|
230 | event.preventDefault() |
|
228 | event.stopPropagation() |
|
231 | event.stopPropagation() |
|
229 | elif event.keyCode == 36: # line start |
|
232 | elif event.keyCode == 36: # line start |
|
230 | pos = doc['console'].selectionStart |
|
233 | pos = doc['console'].selectionStart |
|
231 | col = get_col(doc['console']) |
|
234 | col = get_col(doc['console']) |
|
232 | doc['console'].setSelectionRange(pos - col + 4, pos - col + 4) |
|
235 | doc['console'].setSelectionRange(pos - col + 4, pos - col + 4) |
|
233 | event.preventDefault() |
|
236 | event.preventDefault() |
|
234 | elif event.keyCode == 38: # up |
|
237 | elif event.keyCode == 38: # up |
|
235 | if current > 0: |
|
238 | if current > 0: |
|
236 | pos = doc['console'].selectionStart |
|
239 | pos = doc['console'].selectionStart |
|
237 | col = get_col(doc['console']) |
|
240 | col = get_col(doc['console']) |
|
238 | # remove current line |
|
241 | # remove current line |
|
239 | doc['console'].value = doc['console'].value[:pos - col + 4] |
|
242 | doc['console'].value = doc['console'].value[:pos - col + 4] |
|
240 | current -= 1 |
|
243 | current -= 1 |
|
241 | doc['console'].value += history[current] |
|
244 | doc['console'].value += history[current] |
|
242 | event.preventDefault() |
|
245 | event.preventDefault() |
|
243 | elif event.keyCode == 40: # down |
|
246 | elif event.keyCode == 40: # down |
|
244 | if current < len(history) - 1: |
|
247 | if current < len(history) - 1: |
|
245 | pos = doc['console'].selectionStart |
|
248 | pos = doc['console'].selectionStart |
|
246 | col = get_col(doc['console']) |
|
249 | col = get_col(doc['console']) |
|
247 | # remove current line |
|
250 | # remove current line |
|
248 | doc['console'].value = doc['console'].value[:pos - col + 4] |
|
251 | doc['console'].value = doc['console'].value[:pos - col + 4] |
|
249 | current += 1 |
|
252 | current += 1 |
|
250 | doc['console'].value += history[current] |
|
253 | doc['console'].value += history[current] |
|
251 | event.preventDefault() |
|
254 | event.preventDefault() |
|
252 | elif event.keyCode == 8: # backspace |
|
255 | elif event.keyCode == 8: # backspace |
|
253 | src = doc['console'].value |
|
256 | src = doc['console'].value |
|
254 | lstart = src.rfind('\n') |
|
257 | lstart = src.rfind('\n') |
|
255 | if (lstart == -1 and len(src) < 5) or (len(src) - lstart < 6): |
|
258 | if (lstart == -1 and len(src) < 5) or (len(src) - lstart < 6): |
|
256 | event.preventDefault() |
|
259 | event.preventDefault() |
|
257 | event.stopPropagation() |
|
260 | event.stopPropagation() |
|
258 |
|
261 | ||
|
259 |
|
262 | ||
|
260 | doc['console'].bind('keypress', myKeyPress) |
|
263 | doc['console'].bind('keypress', myKeyPress) |
|
261 | doc['console'].bind('keydown', myKeyDown) |
|
264 | doc['console'].bind('keydown', myKeyDown) |
|
262 | doc['console'].bind('click', cursorToEnd) |
|
265 | doc['console'].bind('click', cursorToEnd) |
|
263 | v = sys.implementation.version |
|
266 | v = sys.implementation.version |
|
264 | doc['console'].value = "Brython %s.%s.%s on %s %s\n>>> " % ( |
|
267 | doc['console'].value = "Brython %s.%s.%s on %s %s\n>>> " % ( |
|
265 | v[0], v[1], v[2], window.navigator.appName, window.navigator.appVersion) |
|
268 | v[0], v[1], v[2], window.navigator.appName, window.navigator.appVersion) |
|
266 | #doc['console'].value += 'Type "copyright", "credits" or "license" for more information.' |
|
269 | #doc['console'].value += 'Type "copyright", "credits" or "license" for more information.' |
|
267 | doc['console'].focus() |
|
270 | doc['console'].focus() |
|
268 | cursorToEnd() |
|
271 | cursorToEnd() |
|
269 |
|
272 | ||
|
270 |
|
273 | ||
|
271 |
|
274 | ||
|
272 |
|
275 |
You need to be logged in to leave comments.
Login now