comparison http/src/luan/modules/web/shell.luan @ 493:1d082a0812e0

move web to http
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 15 May 2015 17:29:59 -0600
parents web/src/luan/modules/web/shell.luan@62b457c50594
children
comparison
equal deleted inserted replaced
492:b36cc406d3d2 493:1d082a0812e0
1 local Luan = require "luan:Luan"
2 local ipairs = Luan.ipairs
3 local load = Luan.load
4 local try = Luan.try
5 local Io = require "luan:Io"
6 local print = Io.print
7 local Debug = require "luan:Debug"
8 local Http = require "luan:web/Http"
9 local Html = require "luan:Html"
10
11 per_session = true
12
13 local history = {}
14 env = {}
15
16 function service()
17 if Http.request.parameters.clear ~= nil then
18 history = {}
19 else
20 local cmd = Http.request.parameters.cmd
21 if cmd ~= nil then
22 Io.stdout = {}
23 function Io.stdout.write(...)
24 for v in Luan.values(...) do
25 history[#history+1] = v
26 end
27 end
28 print( "% "..cmd )
29 try {
30 function()
31 local line = load(cmd,"<web_shell>",env,true)
32 Debug.print_if_something( line() )
33 end;
34 catch = function(e)
35 Io.print_to(Io.stderr,e)
36 print(e)
37 end;
38 }
39 end
40 end
41
42 Io.stdout = Http.response.text_writer()
43 %>
44 <html>
45 <head>
46 <% Html.simply_html_head() %>
47 <title>Luan Shell</title>
48 </head>
49 <body>
50 <div container>
51 <h3>Luan Shell</h3>
52 <p>This is a command shell. Enter commands below.</p>
53 <pre><%
54 for _,v in ipairs(history) do
55 Io.stdout.write(v)
56 end
57 %></pre>
58 <form name='form0' method='post'>
59 % <input name='cmd' size="80" autofocus>
60 <input type="submit" value="run" textcolor="white" bgcolor="#337ab7">
61 <input type="submit" name="clear" value="clear" textcolor="white" bgcolor="#337ab7">
62 </form>
63 </div>
64 <% Html.simply_html_body_bottom() %>
65 </body>
66 </html>
67 <%
68 end