@dodona/papyros 1.0.0 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/App.d.ts +1 -1
- package/dist/App.js +73 -0
- package/dist/App.js.map +1 -0
- package/dist/Backend.d.ts +0 -48
- package/dist/Backend.js +76 -0
- package/dist/Backend.js.map +1 -0
- package/dist/BackendEvent.d.ts +0 -0
- package/dist/BackendEvent.js +24 -0
- package/dist/BackendEvent.js.map +1 -0
- package/dist/BackendEventQueue.d.ts +0 -0
- package/dist/BackendEventQueue.js +135 -0
- package/dist/BackendEventQueue.js.map +1 -0
- package/dist/BackendManager.d.ts +1 -1
- package/dist/BackendManager.js +94 -0
- package/dist/BackendManager.js.map +1 -0
- package/dist/CodeRunner.d.ts +0 -0
- package/dist/CodeRunner.js +372 -0
- package/dist/CodeRunner.js.map +1 -0
- package/dist/Constants.d.ts +0 -0
- package/dist/Constants.js +36 -0
- package/dist/Constants.js.map +1 -0
- package/dist/InputManager.d.ts +0 -0
- package/dist/InputManager.js +102 -0
- package/dist/InputManager.js.map +1 -0
- package/dist/InputServiceWorker.d.ts +0 -0
- package/dist/InputServiceWorker.js +37 -0
- package/dist/InputServiceWorker.js.map +1 -0
- package/dist/Library.d.ts +2 -2
- package/dist/Library.js +9 -1
- package/dist/Library.js.map +1 -0
- package/dist/OutputManager.d.ts +0 -0
- package/dist/OutputManager.js +161 -0
- package/dist/OutputManager.js.map +1 -0
- package/dist/Papyros.css +563 -0
- package/dist/Papyros.d.ts +0 -1
- package/dist/Papyros.js +268 -0
- package/dist/Papyros.js.map +1 -0
- package/dist/ProgrammingLanguage.d.ts +0 -0
- package/dist/ProgrammingLanguage.js +9 -0
- package/dist/ProgrammingLanguage.js.map +1 -0
- package/dist/Translations.d.ts +74 -74
- package/dist/Translations.js +164 -0
- package/dist/Translations.js.map +1 -0
- package/dist/editor/BatchInputEditor.d.ts +0 -0
- package/dist/editor/BatchInputEditor.js +71 -0
- package/dist/editor/BatchInputEditor.js.map +1 -0
- package/dist/editor/CodeEditor.d.ts +0 -5
- package/dist/editor/CodeEditor.js +180 -0
- package/dist/editor/CodeEditor.js.map +1 -0
- package/dist/editor/CodeMirrorEditor.d.ts +0 -0
- package/dist/editor/CodeMirrorEditor.js +168 -0
- package/dist/editor/CodeMirrorEditor.js.map +1 -0
- package/dist/editor/DarkTheme.d.ts +0 -0
- package/dist/editor/DarkTheme.js +73 -0
- package/dist/editor/DarkTheme.js.map +1 -0
- package/dist/editor/Gutters.d.ts +0 -0
- package/dist/editor/Gutters.js +162 -0
- package/dist/editor/Gutters.js.map +1 -0
- package/dist/examples/Examples.d.ts +0 -0
- package/dist/examples/Examples.js +23 -0
- package/dist/examples/Examples.js.map +1 -0
- package/dist/examples/JavaScriptExamples.d.ts +0 -0
- package/dist/examples/JavaScriptExamples.js +16 -0
- package/dist/examples/JavaScriptExamples.js.map +1 -0
- package/dist/examples/PythonExamples.d.ts +0 -0
- package/dist/examples/PythonExamples.js +163 -0
- package/dist/examples/PythonExamples.js.map +1 -0
- package/dist/input/BatchInputHandler.d.ts +0 -0
- package/dist/input/BatchInputHandler.js +112 -0
- package/dist/input/BatchInputHandler.js.map +1 -0
- package/dist/input/InteractiveInputHandler.d.ts +0 -0
- package/dist/input/InteractiveInputHandler.js +90 -0
- package/dist/input/InteractiveInputHandler.js.map +1 -0
- package/dist/input/UserInputHandler.d.ts +0 -0
- package/dist/input/UserInputHandler.js +40 -0
- package/dist/input/UserInputHandler.js.map +1 -0
- package/dist/util/HTMLShapes.d.ts +0 -0
- package/dist/util/HTMLShapes.js +25 -0
- package/dist/util/HTMLShapes.js.map +1 -0
- package/dist/util/Logging.d.ts +0 -0
- package/dist/util/Logging.js +30 -0
- package/dist/util/Logging.js.map +1 -0
- package/dist/util/Rendering.d.ts +0 -0
- package/dist/util/Rendering.js +139 -0
- package/dist/util/Rendering.js.map +1 -0
- package/dist/util/Util.d.ts +1 -1
- package/dist/util/Util.js +148 -0
- package/dist/util/Util.js.map +1 -0
- package/dist/workers/input/InputWorker.d.ts +0 -0
- package/dist/workers/input/InputWorker.js +63 -1
- package/dist/workers/input/InputWorker.js.map +1 -0
- package/dist/workers/javascript/JavaScriptWorker.d.ts +39 -0
- package/dist/workers/javascript/JavaScriptWorker.js +148 -0
- package/dist/workers/javascript/JavaScriptWorker.js.map +1 -0
- package/dist/workers/javascript/worker.d.ts +1 -0
- package/dist/workers/javascript/worker.js +5 -0
- package/dist/workers/javascript/worker.js.map +1 -0
- package/dist/workers/python/PythonWorker.d.ts +31 -0
- package/dist/workers/python/PythonWorker.js +106 -0
- package/dist/workers/python/PythonWorker.js.map +1 -0
- package/dist/workers/python/python_package.tar.gz +0 -0
- package/dist/workers/python/worker.d.ts +1 -0
- package/dist/workers/python/worker.js +5 -0
- package/dist/workers/python/worker.js.map +1 -0
- package/package.json +45 -42
- package/dist/workers/javascript/JavaScriptWorker.worker.d.ts +0 -2
- package/dist/workers/python/PythonWorker.worker.d.ts +0 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Based on https://github.com/codemirror/theme-one-dark/blob/main/src/one-dark.ts with slight edits
|
|
2
|
+
import { EditorView } from "@codemirror/view";
|
|
3
|
+
// Using https://github.com/one-dark/vscode-one-dark-theme/ as reference for the colors
|
|
4
|
+
const ivory = "#abb2bf";
|
|
5
|
+
const stone = "#7d8799"; // Brightened compared to original to increase contrast
|
|
6
|
+
const darkBackground = "#21252b";
|
|
7
|
+
const highlightBackground = "#2c313a";
|
|
8
|
+
const background = "#282c34";
|
|
9
|
+
const tooltipBackground = "#353a42";
|
|
10
|
+
const selection = "#3E4451";
|
|
11
|
+
const cursor = "#528bff";
|
|
12
|
+
// / The editor theme styles
|
|
13
|
+
export const darkTheme = EditorView.theme({
|
|
14
|
+
"&": {
|
|
15
|
+
color: ivory,
|
|
16
|
+
backgroundColor: background
|
|
17
|
+
},
|
|
18
|
+
".cm-content": {
|
|
19
|
+
caretColor: cursor
|
|
20
|
+
},
|
|
21
|
+
".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor },
|
|
22
|
+
// eslint-disable-next-line max-len
|
|
23
|
+
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection },
|
|
24
|
+
".cm-panels": { backgroundColor: darkBackground, color: ivory },
|
|
25
|
+
".cm-panels.cm-panels-top": { borderBottom: "2px solid black" },
|
|
26
|
+
".cm-panels.cm-panels-bottom": { borderTop: "2px solid black" },
|
|
27
|
+
".cm-searchMatch": {
|
|
28
|
+
backgroundColor: "#72a1ff59",
|
|
29
|
+
outline: "1px solid #457dff"
|
|
30
|
+
},
|
|
31
|
+
".cm-searchMatch.cm-searchMatch-selected": {
|
|
32
|
+
backgroundColor: "#6199ff2f"
|
|
33
|
+
},
|
|
34
|
+
".cm-activeLine": { backgroundColor: highlightBackground },
|
|
35
|
+
".cm-selectionMatch": { backgroundColor: "#aafe661a" },
|
|
36
|
+
"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": {
|
|
37
|
+
backgroundColor: "#bad0f847",
|
|
38
|
+
outline: "1px solid #515a6b"
|
|
39
|
+
},
|
|
40
|
+
".cm-gutters": {
|
|
41
|
+
// make gutters darker
|
|
42
|
+
backgroundColor: darkBackground,
|
|
43
|
+
color: stone,
|
|
44
|
+
border: "none"
|
|
45
|
+
},
|
|
46
|
+
".cm-activeLineGutter": {
|
|
47
|
+
backgroundColor: highlightBackground
|
|
48
|
+
},
|
|
49
|
+
".cm-foldPlaceholder": {
|
|
50
|
+
backgroundColor: "transparent",
|
|
51
|
+
border: "none",
|
|
52
|
+
color: "#ddd"
|
|
53
|
+
},
|
|
54
|
+
".cm-tooltip": {
|
|
55
|
+
border: "none",
|
|
56
|
+
backgroundColor: tooltipBackground
|
|
57
|
+
},
|
|
58
|
+
".cm-tooltip .cm-tooltip-arrow:before": {
|
|
59
|
+
borderTopColor: "transparent",
|
|
60
|
+
borderBottomColor: "transparent"
|
|
61
|
+
},
|
|
62
|
+
".cm-tooltip .cm-tooltip-arrow:after": {
|
|
63
|
+
borderTopColor: tooltipBackground,
|
|
64
|
+
borderBottomColor: tooltipBackground
|
|
65
|
+
},
|
|
66
|
+
".cm-tooltip-autocomplete": {
|
|
67
|
+
"& > ul > li[aria-selected]": {
|
|
68
|
+
backgroundColor: highlightBackground,
|
|
69
|
+
color: ivory
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, { dark: true });
|
|
73
|
+
//# sourceMappingURL=DarkTheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DarkTheme.js","sourceRoot":"","sources":["../../src/editor/DarkTheme.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,uFAAuF;AAEvF,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,uDAAuD;AAChF,MAAM,cAAc,GAAG,SAAS,CAAC;AACjC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AACtC,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,SAAS,GAAG,SAAS,CAAC;AAC5B,MAAM,MAAM,GAAG,SAAS,CAAC;AAEzB,4BAA4B;AAC5B,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC;IACtC,GAAG,EAAE;QACD,KAAK,EAAE,KAAK;QACZ,eAAe,EAAE,UAAU;KAC9B;IAED,aAAa,EAAE;QACX,UAAU,EAAE,MAAM;KACrB;IAED,4BAA4B,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE;IACzD,mCAAmC;IACnC,wFAAwF,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE;IAExH,YAAY,EAAE,EAAE,eAAe,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE;IAC/D,0BAA0B,EAAE,EAAE,YAAY,EAAE,iBAAiB,EAAE;IAC/D,6BAA6B,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE;IAE/D,iBAAiB,EAAE;QACf,eAAe,EAAE,WAAW;QAC5B,OAAO,EAAE,mBAAmB;KAC/B;IACD,yCAAyC,EAAE;QACvC,eAAe,EAAE,WAAW;KAC/B;IAED,gBAAgB,EAAE,EAAE,eAAe,EAAE,mBAAmB,EAAE;IAC1D,oBAAoB,EAAE,EAAE,eAAe,EAAE,WAAW,EAAE;IAEtD,uEAAuE,EAAE;QACrE,eAAe,EAAE,WAAW;QAC5B,OAAO,EAAE,mBAAmB;KAC/B;IAED,aAAa,EAAE;QACX,sBAAsB;QACtB,eAAe,EAAE,cAAc;QAC/B,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,MAAM;KACjB;IAED,sBAAsB,EAAE;QACpB,eAAe,EAAE,mBAAmB;KACvC;IAED,qBAAqB,EAAE;QACnB,eAAe,EAAE,aAAa;QAC9B,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,MAAM;KAChB;IAED,aAAa,EAAE;QACX,MAAM,EAAE,MAAM;QACd,eAAe,EAAE,iBAAiB;KACrC;IACD,sCAAsC,EAAE;QACpC,cAAc,EAAE,aAAa;QAC7B,iBAAiB,EAAE,aAAa;KACnC;IACD,qCAAqC,EAAE;QACnC,cAAc,EAAE,iBAAiB;QACjC,iBAAiB,EAAE,iBAAiB;KACvC;IACD,0BAA0B,EAAE;QACxB,4BAA4B,EAAE;YAC1B,eAAe,EAAE,mBAAmB;YACpC,KAAK,EAAE,KAAK;SACf;KACJ;CACJ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC"}
|
package/dist/editor/Gutters.d.ts
CHANGED
|
File without changes
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { StateField } from "@codemirror/state";
|
|
2
|
+
import { StateEffect } from "@codemirror/state";
|
|
3
|
+
import { gutter, GutterMarker } from "@codemirror/view";
|
|
4
|
+
import { EditorView } from "@codemirror/view";
|
|
5
|
+
import { appendClasses } from "../util/Rendering";
|
|
6
|
+
/**
|
|
7
|
+
* Helper class to create markers in the gutter
|
|
8
|
+
*/
|
|
9
|
+
class SimpleMarker extends GutterMarker {
|
|
10
|
+
constructor(
|
|
11
|
+
// Function to create the DOM element
|
|
12
|
+
createMarker) {
|
|
13
|
+
super();
|
|
14
|
+
this.createMarker = createMarker;
|
|
15
|
+
}
|
|
16
|
+
toDOM() {
|
|
17
|
+
return this.createMarker();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class Gutters {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.effect = StateEffect.define();
|
|
24
|
+
this.state = StateField.define({
|
|
25
|
+
create: () => {
|
|
26
|
+
return new Map();
|
|
27
|
+
},
|
|
28
|
+
update: (current, transaction) => {
|
|
29
|
+
const updatedMap = new Map(current);
|
|
30
|
+
for (const e of transaction.effects) {
|
|
31
|
+
if (e.is(this.effect)) {
|
|
32
|
+
updatedMap.set(e.value.lineNr, e.value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return updatedMap;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
applyClasses(marker) {
|
|
40
|
+
const classes = { classNames: this.config.markerClasses };
|
|
41
|
+
appendClasses(classes, "_tw-px-1 papyros-gutter-marker");
|
|
42
|
+
marker.elementClass += classes.classNames;
|
|
43
|
+
return marker;
|
|
44
|
+
}
|
|
45
|
+
hasMarker(view, lineNr) {
|
|
46
|
+
const guttersInfo = view.state.field(this.state);
|
|
47
|
+
return guttersInfo.has(lineNr) && guttersInfo.get(lineNr).on;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Set a marker with the given info
|
|
51
|
+
* @param {EditorView} view View in which the Gutters live
|
|
52
|
+
* @param {Info} info Info used to render the marker
|
|
53
|
+
*/
|
|
54
|
+
setMarker(view, info) {
|
|
55
|
+
if (this.hasMarker(view, info.lineNr) !== info.on) {
|
|
56
|
+
view.dispatch({
|
|
57
|
+
effects: this.effect.of(info)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @param {EditorView} view The view in which the Gutters live
|
|
63
|
+
* @return {Set<number>} The 1-based line numbers with a breakpoint
|
|
64
|
+
*/
|
|
65
|
+
getMarkedLines(view) {
|
|
66
|
+
const markedLines = new Set();
|
|
67
|
+
const guttersInfo = view.state.field(this.state);
|
|
68
|
+
guttersInfo.forEach((info, lineNr) => {
|
|
69
|
+
if (info.on) {
|
|
70
|
+
markedLines.add(lineNr);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return markedLines;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @return {Extension} The Gutters as a CodeMirror Extension
|
|
77
|
+
*/
|
|
78
|
+
toExtension() {
|
|
79
|
+
// TODO correct type: https://github.com/codemirror/codemirror.next/issues/839
|
|
80
|
+
const handlers = {};
|
|
81
|
+
if (this.config.onClick) {
|
|
82
|
+
handlers["mousedown"] = (view, line) => {
|
|
83
|
+
const markings = view.state.field(this.state);
|
|
84
|
+
const lineNr = view.state.doc.lineAt(line.from).number;
|
|
85
|
+
const markerInfo = markings.get(lineNr);
|
|
86
|
+
// Line numbers start at 1
|
|
87
|
+
this.config.onClick(view, markerInfo);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return [
|
|
91
|
+
this.state,
|
|
92
|
+
gutter({
|
|
93
|
+
class: `cm-${this.config.name}-gutter`,
|
|
94
|
+
lineMarker: (view, line) => {
|
|
95
|
+
// Lookup whether the element should be drawn
|
|
96
|
+
const guttersInfo = view.state.field(this.state);
|
|
97
|
+
const lineNr = view.state.doc.lineAt(line.from).number;
|
|
98
|
+
if (guttersInfo.has(lineNr) && guttersInfo.get(lineNr).on) {
|
|
99
|
+
return this.applyClasses(this.marker(guttersInfo.get(lineNr)));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
lineMarkerChange: update => {
|
|
106
|
+
return update.startState.field(this.state) !== update.state.field(this.state);
|
|
107
|
+
},
|
|
108
|
+
initialSpacer: () => {
|
|
109
|
+
return this.applyClasses(this.marker({ lineNr: -1, on: true }));
|
|
110
|
+
},
|
|
111
|
+
domEventHandlers: handlers
|
|
112
|
+
}),
|
|
113
|
+
this.config.extraExtensions || []
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gutters to show and allow toggling of breakpoints
|
|
119
|
+
*/
|
|
120
|
+
export class BreakpointsGutter extends Gutters {
|
|
121
|
+
constructor() {
|
|
122
|
+
super({
|
|
123
|
+
name: "breakpoint",
|
|
124
|
+
onClick: (view, info) => {
|
|
125
|
+
info.on = !info.on;
|
|
126
|
+
this.setMarker(view, info);
|
|
127
|
+
},
|
|
128
|
+
extraExtensions: [
|
|
129
|
+
EditorView.baseTheme({
|
|
130
|
+
".cm-breakpoint-gutter .cm-gutterElement": {
|
|
131
|
+
color: "red",
|
|
132
|
+
paddingLeft: "5px",
|
|
133
|
+
cursor: "default"
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
marker() {
|
|
140
|
+
return new SimpleMarker(() => document.createTextNode("🔴"));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Gutters to show a checkmark for used input
|
|
145
|
+
*/
|
|
146
|
+
export class UsedInputGutters extends Gutters {
|
|
147
|
+
constructor() {
|
|
148
|
+
super({
|
|
149
|
+
name: "input"
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
marker(info) {
|
|
153
|
+
return new SimpleMarker(() => {
|
|
154
|
+
const node = document.createElement("div");
|
|
155
|
+
node.replaceChildren(document.createTextNode("✔"));
|
|
156
|
+
node.setAttribute("title", info.title);
|
|
157
|
+
// Text interface tells us that more complex node will be processed into Text nodes
|
|
158
|
+
return node;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=Gutters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Gutters.js","sourceRoot":"","sources":["../../src/editor/Gutters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAa,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAa,MAAM,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;GAEG;AACH,MAAM,YAAa,SAAQ,YAAY;IACnC;IACI,qCAAqC;IAC7B,YAAwB;QAEhC,KAAK,EAAE,CAAC;QAFA,iBAAY,GAAZ,YAAY,CAAY;IAGpC,CAAC;IACe,KAAK;QACjB,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;IAC/B,CAAC;CACJ;AAmCD,MAAM,OAAgB,OAAO;IAkBzB,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,EAAQ,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,MAAM,CAA0B;YACpD,MAAM,EAAE,GAAG,EAAE;gBACT,OAAO,IAAI,GAAG,EAAE,CAAC;YACrB,CAAC;YACD,MAAM,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE;gBAC7B,MAAM,UAAU,GAA4B,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC7D,KAAK,MAAM,CAAC,IAAI,WAAW,CAAC,OAAO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wBAClB,MAAM,EAAE,SAAS;qBACpB;iBACJ,CAAC;aACL;SACJ,CAAC,CAAC;IACP,CAAC;IAEkB,MAAM;QACrB,OAAO,IAAI,YAAY,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC;CACJ;AAWD;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,OAA4B;IAC9D;QACI,KAAK,CAAC;YACF,IAAI,EAAE,OAAO;SAChB,CAAC,CAAC;IACP,CAAC;IAEkB,MAAM,CAAC,IAAyB;QAC/C,OAAO,IAAI,YAAY,CAAC,GAAG,EAAE;YACzB,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAC3C,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;YACnD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;YACvC,mFAAmF;YACnF,OAAO,IAAmB,CAAC;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ProgrammingLanguage } from "../ProgrammingLanguage";
|
|
2
|
+
import { JAVASCRIPT_EXAMPLES } from "./JavaScriptExamples";
|
|
3
|
+
import { PYTHON_EXAMPLES } from "./PythonExamples";
|
|
4
|
+
const EXAMPLES_MAP = new Map([
|
|
5
|
+
[ProgrammingLanguage.JavaScript, JAVASCRIPT_EXAMPLES],
|
|
6
|
+
// Hello, World! as key seems to cause issues for TypeScript
|
|
7
|
+
[ProgrammingLanguage.Python, PYTHON_EXAMPLES]
|
|
8
|
+
]);
|
|
9
|
+
export function getExamples(language) {
|
|
10
|
+
if (EXAMPLES_MAP.has(language)) {
|
|
11
|
+
return EXAMPLES_MAP.get(language);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function getExampleNames(language) {
|
|
18
|
+
return Object.keys(getExamples(language));
|
|
19
|
+
}
|
|
20
|
+
export function getCodeForExample(language, name) {
|
|
21
|
+
return getExamples(language)[name];
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=Examples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Examples.js","sourceRoot":"","sources":["../../src/examples/Examples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMnD,MAAM,YAAY,GAAuC,IAAI,GAAG,CAAC;IAC7D,CAAC,mBAAmB,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACrD,4DAA4D;IAC5D,CAAC,mBAAmB,CAAC,MAAM,EAAE,eAA2B,CAAC;CAC5D,CAAC,CAAC;AAEH,MAAM,UAAU,WAAW,CAAC,QAA6B;IACrD,IAAI,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;IACvC,CAAC;SAAM,CAAC;QACJ,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAA6B;IACzD,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAA6B,EAAE,IAAY;IACzE,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const JAVASCRIPT_EXAMPLES = {
|
|
2
|
+
"Hello world!": "console.log(\"Hello, World!\");",
|
|
3
|
+
"Input": `const name = prompt('What is your name?')
|
|
4
|
+
console.log(\`Hello, \${name}!\`)`,
|
|
5
|
+
"Fibonacci": `function fibonacci(n){
|
|
6
|
+
if (n <= 1) {
|
|
7
|
+
return n;
|
|
8
|
+
}
|
|
9
|
+
return fibonacci(n - 2) + fibonacci(n - 1);
|
|
10
|
+
}
|
|
11
|
+
for(let i = 0; i < 10; i += 1){
|
|
12
|
+
console.log(fibonacci(i));
|
|
13
|
+
}
|
|
14
|
+
`
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=JavaScriptExamples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JavaScriptExamples.js","sourceRoot":"","sources":["../../src/examples/JavaScriptExamples.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAC/B,cAAc,EAAE,iCAAiC;IACjD,OAAO,EACH;kCAC0B;IAC9B,WAAW,EACP;;;;;;;;;CASP;CACA,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
export const PYTHON_EXAMPLES = {
|
|
2
|
+
"Hello, World!": "print('Hello, World!')",
|
|
3
|
+
"Input": `name = input('What is your name?')
|
|
4
|
+
print(f'Hello, {name}!')`,
|
|
5
|
+
"Fibonacci": `def fibonacci(n):
|
|
6
|
+
return n if n <= 1 else fibonacci(n- 2) + fibonacci(n - 1)
|
|
7
|
+
|
|
8
|
+
print([fibonacci(n) for n in range(10)])`,
|
|
9
|
+
"Doctests": `def factorial(n):
|
|
10
|
+
"""Return the factorial of n, an exact integer >= 0.
|
|
11
|
+
|
|
12
|
+
>>> [factorial(n) for n in range(6)]
|
|
13
|
+
[1, 1, 2, 6, 24, 120]
|
|
14
|
+
>>> factorial(30)
|
|
15
|
+
265252859812191058636308480000000
|
|
16
|
+
>>> factorial(-1)
|
|
17
|
+
Traceback (most recent call last):
|
|
18
|
+
...
|
|
19
|
+
ValueError: n must be >= 0
|
|
20
|
+
|
|
21
|
+
Factorials of floats are OK, but the float must be an exact integer:
|
|
22
|
+
>>> factorial(30.1)
|
|
23
|
+
Traceback (most recent call last):
|
|
24
|
+
...
|
|
25
|
+
ValueError: n must be exact integer
|
|
26
|
+
>>> factorial(30.0)
|
|
27
|
+
265252859812191058636308480000000
|
|
28
|
+
|
|
29
|
+
It must also not be ridiculously large:
|
|
30
|
+
>>> factorial(1e100)
|
|
31
|
+
Traceback (most recent call last):
|
|
32
|
+
...
|
|
33
|
+
OverflowError: n too large
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
import math
|
|
37
|
+
if not n >= 0:
|
|
38
|
+
raise ValueError("n must be >= 0")
|
|
39
|
+
if math.floor(n) != n:
|
|
40
|
+
raise ValueError("n must be exact integer")
|
|
41
|
+
if n+1 == n: # catch a value like 1e300
|
|
42
|
+
raise OverflowError("n too large")
|
|
43
|
+
result = 1
|
|
44
|
+
factor = 2
|
|
45
|
+
while factor <= n:
|
|
46
|
+
result *= factor
|
|
47
|
+
factor += 1
|
|
48
|
+
return result
|
|
49
|
+
|
|
50
|
+
def wrong_factorial(n):
|
|
51
|
+
"""
|
|
52
|
+
>>> [wrong_factorial(n) for n in range(6)]
|
|
53
|
+
[1, 1, 2, 6, 24, 120]
|
|
54
|
+
>>> wrong_factorial(30)
|
|
55
|
+
265252859812191058636308480000000
|
|
56
|
+
"""
|
|
57
|
+
return 0
|
|
58
|
+
`,
|
|
59
|
+
"Async": `import asyncio
|
|
60
|
+
|
|
61
|
+
async def nested():
|
|
62
|
+
print(42)
|
|
63
|
+
|
|
64
|
+
async def main():
|
|
65
|
+
# Schedule nested() to run soon concurrently
|
|
66
|
+
# with "main()".
|
|
67
|
+
task = asyncio.create_task(nested())
|
|
68
|
+
|
|
69
|
+
# "task" can now be used to cancel "nested()", or
|
|
70
|
+
# can simply be awaited to wait until it is complete:
|
|
71
|
+
await task
|
|
72
|
+
|
|
73
|
+
await main()
|
|
74
|
+
`,
|
|
75
|
+
"Erroneous": `def bitonic_search(numbers, query):
|
|
76
|
+
if not numbers:
|
|
77
|
+
return -1
|
|
78
|
+
if len(numbers) == 1:
|
|
79
|
+
return 0 if numbers[0] == query else -1
|
|
80
|
+
int top_index = find_max_index(numbers, 0, len(numbers))
|
|
81
|
+
possible_position = find_bitonic_query(numbers,query,0,top_index+1, lambda a, b: a - b)
|
|
82
|
+
if possible_position != -1:
|
|
83
|
+
return possible_position
|
|
84
|
+
else:
|
|
85
|
+
return find_bitonic_query(numbers,query,top_index, len(numbers), lambda a, b: b - a)
|
|
86
|
+
|
|
87
|
+
def find_max_index(numbers, start, stop):
|
|
88
|
+
while start <= stop:
|
|
89
|
+
if stop - start <= 1:
|
|
90
|
+
return start
|
|
91
|
+
middle = (start + stop) / 2;
|
|
92
|
+
if numbers[middle] < numbers[middle+1]:
|
|
93
|
+
start = midden + 1
|
|
94
|
+
else:
|
|
95
|
+
stop = midden
|
|
96
|
+
|
|
97
|
+
def find_bitonic_query(numbers, query, start, stop, comp):
|
|
98
|
+
while start <= stop:
|
|
99
|
+
if stop - start <= 1:
|
|
100
|
+
return start if numbers[start] == query else -1
|
|
101
|
+
middle = (start + stop) / 2;
|
|
102
|
+
if comp(numbers[midden], query) <= 0:
|
|
103
|
+
start = midden
|
|
104
|
+
else:
|
|
105
|
+
stop = midden
|
|
106
|
+
`,
|
|
107
|
+
"Unicode": `import random
|
|
108
|
+
emoji = '🎅🤶👪🦌🌟❄️☃️🔥🎄🎁🧦🔔🎶🕯️🦆'
|
|
109
|
+
for _ in range(10):
|
|
110
|
+
print(''.join(random.choice(emoji) for _ in range(30)))
|
|
111
|
+
`,
|
|
112
|
+
"Files": `with open("names.txt", "w") as out_file:
|
|
113
|
+
for name in ["Alice", "Bob", "Claire"]:
|
|
114
|
+
print(name, file=out_file)
|
|
115
|
+
|
|
116
|
+
with open("names.txt", "r") as in_file:
|
|
117
|
+
for line in in_file:
|
|
118
|
+
print(line.rstrip())
|
|
119
|
+
`,
|
|
120
|
+
"Matplotlib": `import matplotlib.pyplot as plt
|
|
121
|
+
import networkx as nx
|
|
122
|
+
|
|
123
|
+
plt.rcParams["font.size"] = 10
|
|
124
|
+
plt.figure()
|
|
125
|
+
plt.title('Random graph')
|
|
126
|
+
|
|
127
|
+
plt.tick_params(
|
|
128
|
+
axis='both', left='off', top='off', right='off',
|
|
129
|
+
bottom='off', labelleft='off', labeltop='off',
|
|
130
|
+
labelright='off', labelbottom='off'
|
|
131
|
+
)
|
|
132
|
+
G = nx.random_geometric_graph(512, 0.125)
|
|
133
|
+
pos=nx.spring_layout(G)
|
|
134
|
+
nx.draw_networkx_edges(G, pos, alpha=0.2)
|
|
135
|
+
nx.draw_networkx_nodes(G, pos, node_color='r', node_size=12)
|
|
136
|
+
|
|
137
|
+
plt.show()
|
|
138
|
+
`,
|
|
139
|
+
"Sleep": `import time
|
|
140
|
+
text = """What is the air-speed velocity of an unladen swallow?
|
|
141
|
+
What do you mean? An African or European swallow?
|
|
142
|
+
What? I, I don't know that.
|
|
143
|
+
"""
|
|
144
|
+
for character in text:
|
|
145
|
+
print(character, end="")
|
|
146
|
+
time.sleep(0.1)
|
|
147
|
+
`,
|
|
148
|
+
"Overflow": `from functools import lru_cache
|
|
149
|
+
|
|
150
|
+
@lru_cache
|
|
151
|
+
def fibonacci(n):
|
|
152
|
+
return n if n <= 1 else fibonacci(n- 2) + fibonacci(n - 1)
|
|
153
|
+
|
|
154
|
+
for index in range(5000):
|
|
155
|
+
print(f'{index}: {fibonacci(index)}')
|
|
156
|
+
`,
|
|
157
|
+
"Interrupt": `i = 0
|
|
158
|
+
while i >= 0:
|
|
159
|
+
print(i)
|
|
160
|
+
i += 1
|
|
161
|
+
`
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=PythonExamples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PythonExamples.js","sourceRoot":"","sources":["../../src/examples/PythonExamples.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;IAC3B,eAAe,EAAE,wBAAwB;IACzC,OAAO,EACH;yBACiB;IACrB,WAAW,EACP;;;yCAGiC;IACrC,UAAU,EACN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDP;IACG,OAAO,EACH;;;;;;;;;;;;;;;CAeP;IACG,WAAW,EACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BP;IACG,SAAS,EACL;;;;CAIP;IACG,OAAO,EACH;;;;;;;CAOP;IACG,YAAY,EACR;;;;;;;;;;;;;;;;;;CAkBP;IACG,OAAO,EAAE;;;;;;;;CAQZ;IACG,UAAU,EAAE;;;;;;;;CAQf;IACG,WAAW,EAAE;;;;CAIhB;CACA,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { InputMode } from "../InputManager";
|
|
2
|
+
import { UserInputHandler } from "./UserInputHandler";
|
|
3
|
+
import { t } from "../util/Util";
|
|
4
|
+
import { BatchInputEditor } from "../editor/BatchInputEditor";
|
|
5
|
+
export class BatchInputHandler extends UserInputHandler {
|
|
6
|
+
/**
|
|
7
|
+
* Construct a new BatchInputHandler
|
|
8
|
+
* @param {function()} inputCallback Callback for when the user has entered a value
|
|
9
|
+
*/
|
|
10
|
+
constructor(inputCallback) {
|
|
11
|
+
super(inputCallback);
|
|
12
|
+
this.lineNr = 0;
|
|
13
|
+
this.previousInput = "";
|
|
14
|
+
this.running = false;
|
|
15
|
+
this.prompts = [];
|
|
16
|
+
this.batchEditor = new BatchInputEditor();
|
|
17
|
+
this.batchEditor.onChange({
|
|
18
|
+
onChange: this.handleInputChanged.bind(this),
|
|
19
|
+
delay: 0
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Handle new input, potentially sending it to the awaiting receiver
|
|
24
|
+
* @param {string} newInput The new user input
|
|
25
|
+
*/
|
|
26
|
+
handleInputChanged(newInput) {
|
|
27
|
+
const newLines = newInput ? newInput.split("\n") : [];
|
|
28
|
+
if (newLines.length < this.lineNr) {
|
|
29
|
+
this.lineNr = newLines.length;
|
|
30
|
+
}
|
|
31
|
+
if (this.waiting && newLines.length > this.lineNr + 1) {
|
|
32
|
+
// Require explicitly pressing enter
|
|
33
|
+
this.inputCallback(this.next());
|
|
34
|
+
}
|
|
35
|
+
this.highlight(this.running);
|
|
36
|
+
this.previousInput = newInput;
|
|
37
|
+
}
|
|
38
|
+
toggle(active) {
|
|
39
|
+
if (active) {
|
|
40
|
+
this.batchEditor.setText(this.previousInput);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.previousInput = this.batchEditor.getText();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
getInputMode() {
|
|
47
|
+
return InputMode.Batch;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Retrieve the lines of input that the user has given so far
|
|
51
|
+
* @return {Array<string>} The entered lines
|
|
52
|
+
*/
|
|
53
|
+
get lines() {
|
|
54
|
+
return this.batchEditor.getLines();
|
|
55
|
+
}
|
|
56
|
+
hasNext() {
|
|
57
|
+
return this.lineNr < this.lines.length;
|
|
58
|
+
}
|
|
59
|
+
highlight(running, whichLines = (i) => i < this.lineNr) {
|
|
60
|
+
this.batchEditor.highlight({
|
|
61
|
+
running,
|
|
62
|
+
getInfo: (lineNr) => {
|
|
63
|
+
let message = t("Papyros.used_input");
|
|
64
|
+
const index = lineNr - 1;
|
|
65
|
+
const shouldShow = whichLines(index);
|
|
66
|
+
if (index < this.prompts.length && this.prompts[index]) {
|
|
67
|
+
message = t("Papyros.used_input_with_prompt", { prompt: this.prompts[index] });
|
|
68
|
+
}
|
|
69
|
+
return { lineNr, on: shouldShow, title: message };
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
next() {
|
|
74
|
+
const nextLine = this.lines[this.lineNr];
|
|
75
|
+
this.lineNr += 1;
|
|
76
|
+
this.highlight(true);
|
|
77
|
+
return nextLine;
|
|
78
|
+
}
|
|
79
|
+
onRunStart() {
|
|
80
|
+
this.running = true;
|
|
81
|
+
this.lineNr = 0;
|
|
82
|
+
this.prompts = [];
|
|
83
|
+
this.highlight(true, () => false);
|
|
84
|
+
}
|
|
85
|
+
onRunEnd() {
|
|
86
|
+
this.running = false;
|
|
87
|
+
this.highlight(false);
|
|
88
|
+
}
|
|
89
|
+
waitWithPrompt(waiting, prompt) {
|
|
90
|
+
super.waitWithPrompt(waiting, prompt);
|
|
91
|
+
if (this.waiting) {
|
|
92
|
+
this.prompts.push(prompt || "");
|
|
93
|
+
if (this.hasNext()) {
|
|
94
|
+
this.inputCallback(this.next());
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
setPlaceholder(placeholderValue) {
|
|
99
|
+
this.batchEditor.setPlaceholder(placeholderValue);
|
|
100
|
+
}
|
|
101
|
+
focus() {
|
|
102
|
+
this.batchEditor.focus();
|
|
103
|
+
}
|
|
104
|
+
_render(options) {
|
|
105
|
+
this.batchEditor.render(options);
|
|
106
|
+
if (options.inputStyling) {
|
|
107
|
+
this.batchEditor.setStyling(options.inputStyling);
|
|
108
|
+
}
|
|
109
|
+
this.highlight(this.running);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=BatchInputHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BatchInputHandler.js","sourceRoot":"","sources":["../../src/input/BatchInputHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,MAAM,OAAO,iBAAkB,SAAQ,gBAAgB;IAuBnD;;;OAGG;IACH,YAAY,aAAqC;QA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