UNPKG

4.8 kBHTMLView Raw
1<!DOCTYPE html>
2
3<script src="https://codemirror.net/lib/codemirror.js"></script>
4<script src="https://codemirror.net/addon/mode/simple.js"></script>
5<script src="https://codemirror.net/addon/edit/matchbrackets.js"></script>
6<script src="lib/ergo-mode.js"></script>
7<script src="./extracted/ergotopcore.js"></script>
8<link rel="stylesheet" href="https://codemirror.net/lib/codemirror.css">
9<link rel="stylesheet" href="https://codemirror.net/theme/eclipse.css">
10
11<style>
12html, body {height: 100%}
13body {
14 background: white;
15 color: black;
16 font-family: Georgia;
17 margin: 0;
18 font-size: 14pt;
19}
20h1 {
21 font-variant: small-caps;
22 font-weight: 100;
23 font-size: 1em;
24 text-align: right;
25 color: #aaa;
26 border-bottom: 1px solid;
27 margin: 0;
28 height: 5%;
29}
30textarea {
31 width: 100%;
32 font-family: monospace;
33 font-size: 1em;
34 border: none;
35 padding: 0.5em;
36}
37textarea:focus {
38 outline: none;
39 background: white;
40}
41pre {
42 padding-left: 0.5em;
43 white-space: pre-wrap;
44 color: #555;
45}
46
47pre, .CodeMirror {
48 font-family: Menlo;
49}
50
51
52span.emit { color: hotpink; }
53span.failure { color: red; }
54span.state { color: blue; }
55span.response { color: green; }
56
57#left {width: 49%;}
58#right {width: 49%; overflow: auto;}
59
60#left, #right {
61 float: left;
62 height: 90%;
63 border-left: 1px solid #aaa;
64}
65.clearer {clear: both; border-top: 1px solid #aaa;}
66
67#right .CodeMirror { height: auto; background-color: #eee;}
68#left .CodeMirror { height: 100%;}
69</style>
70
71<h1>
72<a href="https://docs.accordproject.org/docs/logic-ergo.html" target="_blank">Ergo</a>
73&middot; v<script type="text/javascript">document.write(ergotop.version);</script>
74&middot; <script type="text/javascript">document.write(ergotop.buildate);</script>
75&middot;
76<img height="20" align="right" src="ergologo.png"/>
77</h1>
78
79
80<div id="left">
81 <textarea id="left-editor"></textarea>
82</div>
83
84<div id="right">
85 <pre id="stdout"></pre>
86 <button onclick="update(editor_rt)">Evaluate [&#x2318; &#x21B5;]</button>
87 <button id="importlibs">Import "contract" library</button>
88 <button id="clearctxts">Clear</button>
89 <textarea autofocus type="text" id="right-editor" placeholder="return 42;" rows=5></textarea>
90</div>
91
92<div class="clearer"></div>
93
94<script src="./cheatsheet.js"></script>
95<script>
96var ctx = ergotop.initRCtxt;
97
98var stdin = document.getElementById('right-editor');
99var stdout = document.getElementById('stdout');
100
101function setup_editor(id) {
102 var editor = CodeMirror.fromTextArea(
103 document.getElementById(id),
104 {value: "123", mode: "ergo", theme: "eclipse", matchBrackets: true/*, viewportMargin: Infinity*/}
105 );
106 editor.setOption("extraKeys", {
107 "Cmd-Enter": update,
108 "Cmd-1": selectcheat1,
109 "Cmd-2": selectcheat2,
110 "Cmd-3": selectcheat3,
111 "Ctrl-P": cheat
112 });
113 return editor;
114}
115
116var editor_lt = setup_editor('left-editor');
117var editor_rt = setup_editor('right-editor');
118
119stdin.addEventListener('keydown', function(evt) {
120 if (evt.keyCode === 9) {
121 evt.preventDefault();
122 }
123 if (evt.keyCode === 13 && evt.shiftKey) {
124 evt.preventDefault();
125 update();
126 }
127}, false);
128
129document.getElementById('importlibs').addEventListener('click', function() {
130 var x = ergotop.runLine(
131 ctx,
132 "import org.accordproject.cicero.contract.*\n" +
133 "import org.accordproject.cicero.runtime.*\n"
134 );
135 if (x) {
136 ctx = x.ctx;
137 }
138 this.remove();
139}, false);
140
141document.getElementById('clearctxts').addEventListener('click', function() {
142 ctx = ergotop.initRCtxt;
143 stdout.innerHTML = '';
144}, false);
145
146function update(editor) {
147 var src = editor.getValue();
148 var x = ergotop.runLine(ctx, src);
149 if (x) {
150 ctx = x.ctx;
151 stdout.innerHTML += "<small>" + src.replace(/</g, "&lt;") + "</small>" + "\n";
152 stdout.innerHTML +=
153 x.out
154 .replace(/</g, "&lt;")
155 .replace(/^Response\./gm, '<span class="response">Response.</span>')
156 .replace(/^Emit\./gm, '<span class="emit">Emit.</span>')
157 .replace(/^Failure\./gm, '<span class="failure">Failure.</span>')
158 .replace(/^State\./gm, '<span class="state">State.</span>')
159 .replace(/`([^']*)'/gm, '<u>$1</u>')
160 stdout.innerHTML += "<hr/>\n"
161 editor_rt.setValue("");
162 editor_rt.focus();
163 }
164}
165
166cheatsheet = allcheatsheets[0];
167function pickcheat(num) {
168 cheatsheet = allcheatsheets[num-1];
169};
170function selectcheat1(editor) {
171 pickcheat(1);
172};
173function selectcheat2(editor) {
174 pickcheat(2);
175};
176function selectcheat3(editor) {
177 pickcheat(3);
178};
179function cheat(editor) {
180 editor.setValue(editor.getValue() + (cheatsheet.shift() || ""));
181 editor.setCursor(1000000, 0);
182}
183</script>