summary refs log tree commit diff stats
path: root/rod/webrepl.nim
blob: bf59bbfec9fa23c62dc6fa11279529c606b0c9b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
#
#           The Nimrod Compiler
#        (c) Copyright 2010 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## Creates a server, opens a browser and starts serving a Repl for the user.
## Unfortunately it doesn't ever stop...

import httpserver, sockets, browsers, strutils, cgi, options

const
  gui = """
<html>  
  <head>
    <title>Nimrod Interactive Web Console</title>
  </head>
  
  <body>
    <form action="exec" method="get">
      <input type="submit" value="Run" /><br />
      <textarea name="code" cols="80" rows="30">import strutils, os

# your code here</textarea>
      <table border="0">
        <tr>
          <td><input type="checkbox" name="objChecks" checked="true"
               value="on">objChecks</input></td>
          <td><input type="checkbox" name="fieldChecks" checked="true"
               value="on">fieldChecks</input></td>
          <td><input type="checkbox" name="rangeChecks" checked="true"
               value="on">rangeChecks</input></td>
        </tr><tr>
          <td><input type="checkbox" name="boundChecks" checked="true"
               value="on">boundChecks</input></td>
          <td><input type="checkbox" name="overflowChecks" checked="true"
               value="on">overflowChecks</input></td>
          <td><input type="checkbox" name="nanChecks" checked="true"
               value="on">nanChecks</input></td>
        </tr><tr>
          <td><input type="checkbox" name="infChecks" checked="true"
               value="on">infChecks</input></td>
          <td><input type="checkbox" name="assertions" checked="true"
               value="on">assertions</input></td>
        </tr>
      </table>
    </form>
    $1
  </body>
</html>
"""

proc runCode(input: string): string =
  nil

proc handleRequest(client: TSocket, path, query: string) =
  var output = query
  client.send(gui % output & wwwNL)


var s: TServer
open(s, TPort(0))
browsers.openDefaultBrowser("http://localhost:" & $s.port)
while true: 
  next(s)
  handleRequest(s.client, s.path, s.query)
  close(s.client)
close(s)