Skip to content

Commit e3b6933

Browse files
page on top, output on bottom
1 parent 8a94bea commit e3b6933

1 file changed

Lines changed: 13 additions & 21 deletions

File tree

runestone/activecode/js/activecode_brython.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,40 @@ export default class BrythonActiveCode extends ActiveCode {
3030
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
3131
<style>
3232
pre {
33-
position: absolute; font-size: 13px; width: 94%; padding: 9.5px; line-height: 1.42857143; border: 1px ; border-radius: 4px;
34-
overflow: auto; height: 200px; clear: both; position: sticky; top: 0; resize: both; background: white;
33+
position: absolute; font-size: 13px; width: 94%; padding: 9.5px; line-height: 1.42857143; border: 1px solid #ccc; border-radius: 4px;
34+
overflow: auto; height: 200px; clear: both; position: sticky; bottom: 0; resize: both; background: white;
3535
}
3636
code{
3737
border: 1px solid #ccc; border-radius: 4px;
3838
}
3939
</style>
4040
</head>
41-
<body onload='brython()' >
42-
<pre id="consolePre">
43-
<code id="consoleCode"></code>
44-
</pre>
41+
<body onload='brython()'>
4542
<script type='text/python'>
4643
import sys
4744
from browser import document, html
45+
import traceback
46+
47+
preElem = html.PRE()
48+
logger = html.CODE()
49+
preElem <= logger
4850
49-
logger = document['consoleCode']
50-
preElem = document['consolePre']
5151
class NewOut:
5252
def write(self, data):
5353
logger.innerHTML += str(data)
5454
5555
sys.stderr = sys.stdout = NewOut()
56-
</script>
57-
<script type="text/python3">
58-
from browser import document, html
59-
import sys
60-
import traceback
6156
6257
def my_exec(code):
6358
try:
6459
exec(code, locals())
65-
preElem = document['consolePre']
6660
preElem.style.visibility = "visible"
67-
document['consoleCode'].classList.add("plaintext")
68-
out_header = document.createElement("h3")
61+
out_header = document.createElement("h4")
6962
out_header.innerHTML = "Output"
7063
out_header.style.font = "24px 'Arial'"
64+
logger.classList.add("plaintext")
7165
preElem.prepend(out_header)
66+
document <= preElem
7267
except SyntaxError as err:
7368
error_class = err.__class__.__name__
7469
detail = err.args[0]
@@ -88,19 +83,16 @@ def my_exec(code):
8883
# This is only done if an Exception was catched
8984
result = f"'{error_class}': {detail} {line_number}"
9085
print(result)
91-
logger = document['consoleCode']
92-
preElem = document['consolePre']
9386
# Styling the pre element for error
9487
error_header = document.createElement("h3")
9588
error_header.innerHTML = "Error"
9689
error_header.style.font = "24px 'Arial'"
9790
preElem.prepend(error_header)
9891
preElem.style.visibility = "visible"
99-
preElem.style.top = "5px"
100-
preElem.style.backgroundColor = "#f2dede"
101-
preElem.style.border = "1px solid #ebccd1"
10292
logger.classList.add("python")
10393
94+
document <= preElem
95+
10496
my_exec("""${prog}
10597
""")
10698

0 commit comments

Comments
 (0)