|
6 | 6 | <style> |
7 | 7 | * { |
8 | 8 | margin: 0; |
| 9 | + box-sizing: border-box; |
9 | 10 | } |
10 | 11 | body { |
11 | 12 | font-family: monospace; |
12 | 13 | height: 100vh; |
13 | | - display: flex; |
| 14 | + display: grid; |
| 15 | + grid-template-columns: 1fr 1fr; |
| 16 | + grid-template-rows: auto 1fr; |
14 | 17 | } |
15 | 18 | textarea, |
16 | | - pre { |
17 | | - width: 50%; |
| 19 | + #print { |
| 20 | + grid-column: 1; |
| 21 | + } |
| 22 | + textarea { |
18 | 23 | padding: 1rem; |
19 | 24 | border: none; |
| 25 | + border-right: 1px solid grey; |
| 26 | + border-bottom: 1px solid grey; |
20 | 27 | outline: none; |
21 | 28 | resize: none; |
| 29 | + height: 65vh; |
22 | 30 | } |
23 | | - textarea { |
| 31 | + #print { |
| 32 | + padding: 1rem; |
24 | 33 | border-right: 1px solid grey; |
| 34 | + white-space: pre-wrap; |
| 35 | + word-break: break-word; |
| 36 | + overflow: auto; |
| 37 | + background: dimgray; |
| 38 | + color: whitesmoke; |
25 | 39 | } |
26 | | - pre { |
| 40 | + #parse { |
| 41 | + white-space: pre; |
| 42 | + padding: 1rem; |
27 | 43 | overflow: auto; |
28 | 44 | background: whitesmoke; |
| 45 | + grid-column: 2; |
| 46 | + grid-row: 1 / -1; |
29 | 47 | } |
30 | 48 | </style> |
31 | 49 | </head> |
32 | 50 | <body> |
33 | | - <textarea id="in" spellcheck="false"> |
| 51 | + <textarea id="input" spellcheck="false"> |
34 | 52 | echo "hello $USER" |
35 | 53 | for f in *.log; do |
36 | 54 | cat "$f" | grep ERROR |
37 | 55 | done</textarea |
38 | 56 | > |
39 | | - <pre id="out"></pre> |
| 57 | + <output id="parse"></output> |
| 58 | + <output id="print"></output> |
40 | 59 | <script type="module"> |
41 | 60 | import { parse } from "/parser.js"; |
42 | | - const _in = document.getElementById("in"); |
43 | | - const _out = document.getElementById("out"); |
| 61 | + import { print } from "/printer.js"; |
| 62 | + const _input = document.getElementById("input"); |
| 63 | + const _parse = document.querySelector("output#parse"); |
| 64 | + const _print = document.querySelector("output#print"); |
44 | 65 | const update = () => { |
45 | 66 | try { |
46 | | - _out.textContent = JSON.stringify(parse(_in.value), null, 2); |
| 67 | + const src = _input.value; |
| 68 | + const ast = parse(src); |
| 69 | + _parse.textContent = JSON.stringify(ast, null, 2); |
| 70 | + _print.textContent = print(ast); |
47 | 71 | } catch (e) { |
48 | | - _out.textContent = e.message; |
| 72 | + _parse.textContent = e.message; |
| 73 | + _print.textContent = e.message; |
49 | 74 | } |
50 | 75 | }; |
51 | | - _in.oninput = update; |
| 76 | + _input.oninput = update; |
52 | 77 | update(); |
53 | 78 | </script> |
54 | 79 | </body> |
|
0 commit comments