Initial work towards web config UI

This commit is contained in:
Peter Ammon 2012-03-15 03:43:45 -07:00
parent 52d8fb301c
commit 63b330439e
3 changed files with 9460 additions and 0 deletions

142
web_config/index.html Normal file
View File

@ -0,0 +1,142 @@
<html>
<head>
<style type="text/css">
body {
background-color: #292929;
font-family: Courier, "Courier New", monospace;
color: white;
}
#ancestor {
width: 800px;
margin-left: auto;
margin-right: auto;
margin-top: 25px;
}
#parent {
width: 100%;
background-color: black;
min-height: 200px;
margin-top: 30px;
}
#tab_parent {
width: 100%;
}
.tab, .selected_tab {
border-style: groove;
border-color: #292929;
border-width: 2px;
margin-left: -2px;
margin-right: -2px;
font-size: 17pt;
padding-top: 20px;
padding-bottom: 20px;
text-align: center;
width: 25%;
float: left;
background-color: #292929;
}
.selected_tab {
background-color: inherit;
border-style: none;
margin-left: 0px;
margin-right: -1px;
}
.footer {
clear: both;
height: 30px;
}
#master {
float: left;
text-align: right;
width: 200px;
font-size: 16pt;
padding-top: 24px;
}
.master_element {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 5px;
font-size: smaller;
}
.master_element_text {
text-decoration: none;
padding-bottom: 1px;
border-bottom: 1px solid white;
}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
/* Adds a new element to master */
function create_master_element(contents) {
$('<div/>', {
class: 'master_element',
click: function(){
$(this).toggleClass('master_element');
}
}).append(
$("<span/>", {
class: 'master_element_text',
text: contents
})
).appendTo('#master')
}
$(document).ready(function() {
$('#thelink').click(function() {
req = $.ajax({
type: "GET",
url: "/colors/",
success: function(data){
$.each($.parseJSON(data), function(idx, contents) {
var key = contents[0]
var value = contents[1]
create_master_element(key)
})
},
fail: function(){
alert('fail')
}
})
})
})
</script>
</head>
<body>
<div id="ancestor">
<span style="font-size: 68pt">fish</span>
<div id="parent">
<div id="tab_parent">
<div class="selected_tab">colors</div>
<div class="tab">functions</div>
<div class="tab">variables</div>
<div class="tab">history</div>
</div>
<div id="master">
<!--- <div class="master_element"><span class="master_element_text">command</span></div> -->
</div>
<div class="footer">
</div>
</div>
</div>
<a id="thelink">Click me</a>
</body></html>

9266
web_config/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

52
web_config/webconfig.py Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/python
import SimpleHTTPServer
import SocketServer
import webbrowser
import subprocess
import re
import json
def run_fish_cmd(text):
from subprocess import PIPE
p = subprocess.Popen(["fish"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
out, err = p.communicate(text)
return out, err
class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_get_colors(self):
"Look for fish_color_*"
result = []
out, err = run_fish_cmd('set')
for match in re.finditer(r"fish_color_(\S+) (.+)", out):
color_name, color_value = match.group(1, 2)
result.append([color_name, color_value])
print result
return result
def do_GET(self):
p = self.path
if p == '/colors/':
output = self.do_get_colors()
else:
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
# Return valid output
self.send_response(200)
self.send_header('Content-type','text/html')
self.wfile.write('\n')
# Output JSON
json.dump(output, self.wfile)
PORT = 8011
Handler = FishConfigHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
webbrowser.open("http://localhost:%d" % PORT)
print "serving at port", PORT
httpd.serve_forever()