Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
0ceeff65
Commit
0ceeff65
authored
Mar 19, 2019
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve console handling. Remove broken matplotlib-sideload
parent
7441d525
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
52 deletions
+46
-52
src/console.html
src/console.html
+46
-16
src/matplotlib-sideload.html
src/matplotlib-sideload.html
+0
-36
No files found.
src/console.html
View file @
0ceeff65
...
...
@@ -5,14 +5,38 @@
<script
src=
"https://code.jquery.com/jquery-latest.js"
></script>
<script
src=
"https://cdn.jsdelivr.net/npm/jquery.terminal/js/jquery.terminal.min.js"
></script>
<link
href=
"https://cdn.jsdelivr.net/npm/jquery.terminal/css/jquery.terminal.min.css"
rel=
"stylesheet"
/>
<link
href=
"renderedhtml.css"
rel=
"stylesheet"
/>
<script
src=
"./pyodide_dev.js"
></script>
</head>
<body>
<script>
languagePluginLoader
.
then
(()
=>
{
pyodide
.
runPython
(
'
import io, code, sys
'
);
pyodide
.
runPython
(
'
_c = code.InteractiveConsole(locals=globals())
'
)
function
pushCode
(
line
)
{
handleResult
(
c
.
push
(
line
))
}
var
term
=
$
(
'
body
'
).
terminal
(
pushCode
,
{
greetings
:
"
Welcome to the Pyodide terminal emulator 🐍
"
,
prompt
:
"
[[;red;]>>> ]
"
}
);
window
.
term
=
term
;
pyodide
.
runPython
(
'
import io, code, sys
\n
'
+
'
sys.stdout = io.StringIO()
\n
'
+
'
sys.stderr = io.StringIO()
\n
'
+
'
from js import term, pyodide
\n
'
+
'
class Console(code.InteractiveConsole):
\n
'
+
'
def runcode(self, code):
\n
'
+
'
term.runPython("
\\
n".join(self.buffer))
\n
'
+
'
_c = Console(locals=globals())
'
)
var
c
=
pyodide
.
pyimport
(
'
_c
'
)
function
handleResult
(
result
)
{
if
(
result
)
{
term
.
set_prompt
(
'
[[;gray;]... ]
'
)
...
...
@@ -24,25 +48,31 @@
term
.
echo
(
`[[;red;]
${
stderr
}
]`
)
}
else
{
var
stdout
=
pyodide
.
runPython
(
"
sys.stdout.getvalue()
"
)
term
.
echo
(
stdout
.
trim
())
if
(
stdout
)
{
term
.
echo
(
stdout
.
trim
())
}
}
}
function
pushCode
(
line
)
{
pyodide
.
runPython
(
'
sys.stdout = io.StringIO()
'
)
pyodide
.
runPython
(
'
sys.stderr = io.StringIO()
'
)
if
(
line
.
startsWith
(
'
import
'
))
{
pyodide
.
runPythonAsync
(
line
).
then
(
handleResult
)
term
.
runPython
=
function
(
code
)
{
pyodide
.
runPythonAsync
(
code
).
then
(
term
.
handlePythonResult
,
term
.
handlePythonError
)
}
term
.
handlePythonResult
=
function
(
result
)
{
if
(
result
===
undefined
)
{
return
}
else
if
(
result
[
'
_repr_html_
'
]
!==
undefined
)
{
term
.
echo
(
result
[
'
_repr_html_
'
],
{
raw
:
true
})
}
else
{
handleResult
(
c
.
push
(
line
))
term
.
echo
(
result
.
toString
(
))
}
}
var
term
=
$
(
'
body
'
).
terminal
(
pushCode
,
{
greetings
:
"
Welcome to the Pyodide terminal emulator 🐍
"
,
prompt
:
"
[[;red;]>>> ]
"
}
);
term
.
handlePythonError
=
function
(
result
)
{
term
.
error
(
result
.
toString
())
}
});
</script>
</body>
...
...
src/matplotlib-sideload.html
deleted
100644 → 0
View file @
7441d525
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Loading matplotlib example...
</title>
</head>
<body>
<script>
var
blackout
=
document
.
createElement
(
'
div
'
);
blackout
.
setAttribute
(
'
style
'
,
'
width: 100%; height: 100%; position: absolute; left: 0; top: 0; background-color: #00000066; z-index: 10
'
);
document
.
body
.
appendChild
(
blackout
);
var
url_string
=
window
.
location
;
var
url
=
new
URL
(
url_string
);
var
content
=
url
.
searchParams
.
get
(
"
example
"
);
fetch
(
content
).
then
((
response
)
=>
response
.
text
())
.
then
((
text
)
=>
{
let
jsmd
=
document
.
getElementById
(
'
jsmd
'
);
jsmd
.
innerHTML
=
jsmd
.
innerHTML
+
text
;
let
pyodide
=
document
.
createElement
(
'
script
'
);
pyodide
.
src
=
'
pyodide_dev.js
'
;
pyodide
.
onload
=
()
=>
{
languagePluginLoader
.
then
(()
=>
{
window
.
pyodide
.
loadPackage
(
'
matplotlib
'
).
then
(()
=>
{
window
.
pyodide
.
runPython
(
'
__name__ = "__main__"
'
);
blackout
.
parentNode
.
removeChild
(
blackout
);
});
});
document
.
body
.
appendChild
(
pyodide
);
}
document
.
body
.
appendChild
(
script
);
});
</script>
<div
id=
'page'
></div>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment