File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 3
3
< head >
4
4
< meta charset ="utf-8 ">
5
5
< title > RustPython Starter Application</ title >
6
+ < style type ="text/css " media ="screen ">
7
+ # code {
8
+ height : 70vh ;
9
+ width : 95vw ;
10
+ }
11
+
12
+ # run-btn {
13
+ width : 10em ;
14
+ height : 5em ;
15
+ }
16
+ </ style >
6
17
</ head >
7
18
< body >
19
+ < h1 > RustPython Demo</ h1 >
20
+ < p > Please input your python code below and click < kbd > Run</ kbd > :</ p >
21
+ < textarea id ="code "> x = 1
22
+ y = 2
23
+ print('Hello! x + y equals to ' + str(x+y))
24
+ </ textarea >
25
+ < button id ="run-btn "> Run</ button >
26
+ < h2 > Open the browser console (< kbd > Ctrl</ kbd > +< kbd > Shift</ kbd > +< kbd > I</ kbd > or < kbd > F12</ kbd > ) to see the output</ h2 >
8
27
< script src ="./bootstrap.js "> </ script >
9
28
</ body >
10
29
</ html >
Original file line number Diff line number Diff line change 1
1
import * as rp from "rustpython_wasm" ;
2
2
3
- rp . run_code ( "print('Hello Python!')\n" ) ;
3
+ function runCodeFromTextarea ( _ ) {
4
+ const code = document . getElementById ( 'code' ) . value ;
5
+ if ( ! code . endsWith ( '\n' ) ) { // HACK: if the code doesn't end with newline it crashes.
6
+ rp . run_code ( code + '\n' ) ;
7
+ return ;
8
+ }
9
+ rp . run_code ( code ) ;
10
+ }
11
+ document . getElementById ( 'run-btn' ) . addEventListener ( 'click' , runCodeFromTextarea ) ;
12
+
13
+ runCodeFromTextarea ( ) ; // Run once for demo
You can’t perform that action at this time.
0 commit comments