comparison web/src/luan/modules/web/web_shell.luan @ 325:78a6a71afbfd

use SimplyHTML git-svn-id: https://luan-java.googlecode.com/svn/trunk@326 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 03 Mar 2015 06:00:59 +0000
parents 7f7708e8fdd4
children db37d6aee4db
comparison
equal deleted inserted replaced
324:b24a35612947 325:78a6a71afbfd
3 local load = Luan.load 3 local load = Luan.load
4 local Io = require "luan:Io" 4 local Io = require "luan:Io"
5 local print = Io.print 5 local print = Io.print
6 local Debug = require "luan:Debug" 6 local Debug = require "luan:Debug"
7 local Http = require "luan:web/Http" 7 local Http = require "luan:web/Http"
8 local Html = require "luan:Html"
8 9
9 per_session = true 10 per_session = true
10 11
11 local history = {} 12 local history = {}
12 local env = {} 13 local env = {}
13
14 Io.stdout = {}
15 function Io.stdout.write(...)
16 for _,v in Luan.values(...) do
17 history[#history+1] = v
18 end
19 end
20 14
21 function service() 15 function service()
22 if Http.request.parameters.clear ~= nil then 16 if Http.request.parameters.clear ~= nil then
23 history = {} 17 history = {}
24 else 18 else
25 local cmd = Http.request.parameters.cmd 19 local cmd = Http.request.parameters.cmd
26 if cmd ~= nil then 20 if cmd ~= nil then
21 Io.stdout = {}
22 function Io.stdout.write(...)
23 for _,v in Luan.values(...) do
24 history[#history+1] = v
25 end
26 end
27 print( "% "..cmd ) 27 print( "% "..cmd )
28 try 28 try
29 local line = load(cmd,"<web_shell>",env,true) 29 local line = load(cmd,"<web_shell>",env,true)
30 Debug.print_if_something( line() ) 30 Debug.print_if_something( line() )
31 catch e do 31 catch e do
33 print(e) 33 print(e)
34 end 34 end
35 end 35 end
36 end 36 end
37 37
38 local write = Http.response.text_writer().write 38 Io.stdout = Http.response.text_writer()
39 write(%> 39 Html.simple_html_page{
40 <!DOCTYPE html> 40 head = function() %>
41 <html lang="en"> 41 <title>Luan Shell</title>
42 <head> 42 <% end;
43 <title>Luan Shell</title> 43 body = function() %>
44 <style> 44 <div container>
45 body {font-family:'Arial',sans-serif;font-size:16px;padding:1em 2em} 45 <h3>Luan Shell</h3>
46 input {padding:.5em;border-radius:10px;border:1px solid #ccc;font-size:16px} 46 <p>This is a command shell. Enter commands below.</p>
47 input.btn {background:#3B619D;color:#FFF;padding:.3em 0;font-size:20px;min-width:4em;} 47 <pre><%
48 h1 {font-weight:bold;font-size: 20px} 48 for _,v in ipairs(history) do
49 p {margin:1em 0 .2em} 49 Io.stdout.write(v)
50 </style> 50 end
51 </head> 51 %></pre>
52 <body> 52 <form name='form0' method='post'>
53 <h1>Luan Shell</h1> 53 % <input name='cmd' size="80" autofocus>
54 <p>This is a command shell. Enter commands below.</p> 54 <input type="submit" value="run" textcolor="white" bgcolor="#337ab7">
55 <pre><%) 55 <input type="submit" name="clear" value="clear" textcolor="white" bgcolor="#337ab7">
56 for _,v in ipairs(history) do 56 </form>
57 write(v) 57 </div>
58 end 58 <% end;
59 write(%></pre> 59 }
60 <form name='form0' method='post'>
61 % <input name='cmd' size="60">
62 <input type="submit" class="btn" value="run">
63 <input type="submit" class="btn" name="clear" value="clear">
64 </form>
65
66 <script>document.form0.cmd.focus();</script>
67 </body>
68 </html>
69 <%)
70 60
71 end 61 end