Big improvement to web config history speed

Nice dashed table seprators
This commit is contained in:
ridiculousfish 2012-03-19 11:51:44 -07:00
parent 1889db3263
commit c8bc535f22
2 changed files with 54 additions and 24 deletions

View File

@ -94,10 +94,15 @@ body {
}
.data_table_cell {
padding-bottom: 10px;
padding-top: 5px;
padding-bottom: 5px;
overflow:hidden;
border-bottom: #444 dotted 1px;
}
.no_overflow {
text-overflow: ellipsis;
white-space: nowrap;
white-space: nowrap;
}
.colorpicker_term256_row {
@ -146,6 +151,7 @@ function switch_tab(new_tab) {
/* Hide some things */
$('#colorpicker_term256').hide()
$('#data_table').hide()
$('#data_table').empty()
/* Load something new */
if (new_tab == 'tab_colors') {
@ -169,7 +175,10 @@ function switch_tab(new_tab) {
})
$('#data_table').show()
} else if (new_tab == 'tab_history') {
run_get_request('/history/', function(contents){
create_data_table_element([contents])
})
$('#data_table').show()
} else {
alert("Unknown tab");
}
@ -225,23 +234,39 @@ function create_master_element(contents) {
).appendTo('#master')
}
/* Toggle the no_overflow class */
function toggle_overflow(who) {
$(who).toggleClass('no_overflow')
}
/* Creates a new row in the data table */
function create_data_table_element(contents_list) {
var row = $('<tr>', {
class: 'data_table_row'
})
for (idx = 0; idx < contents_list.length; idx++) {
/* Align the first one right, subsequent ones left */
if (idx == 0) {
cell_style = 'text-align: right; padding-right: 30px;'
/* If we have more than one, then align the first one right, subsequent ones left */
if (idx == 0 && contents_list.length > 1) {
cell = $('<td>', {
class: 'data_table_cell no_overflow',
style: 'text-align: right; padding-right: 30px;'
});
} else {
cell_style = 'text-align: left;'
cell = $('<td>', {
class: 'data_table_cell no_overflow',
style: 'text-align: left',
onClick: "toggle_overflow(this)"
});
}
row.append($('<td>', {
class: 'data_table_cell',
style: cell_style,
text: contents_list[idx]
}))
text_list = contents_list[idx].split("\n")
for (j=0; j < text_list.length; j++) {
cell.append($('<p>', {
text: text_list[j]
}))
}
row.append(cell)
}
$('#data_table').append(row)
}
@ -282,10 +307,10 @@ $(document).ready(function() {
<span style="font-size: 68pt">fish</span>
<div id="parent">
<div id="tab_parent">
<div class="tab selected_tab" id="tab_colors" onClick="javascript: switch_tab('tab_colors')">colors</div>
<div class="tab" id="tab_functions" onClick="javascript: switch_tab('tab_functions')">functions</div>
<div class="tab" id="tab_variables" onClick="javascript: switch_tab('tab_variables')">variables</div>
<div class="tab" id="tab_history" onClick="javascript: switch_tab('tab_history')">history</div>
<div class="tab selected_tab" id="tab_colors" onClick="switch_tab('tab_colors')">colors</div>
<div class="tab" id="tab_functions" onClick="switch_tab('tab_functions')">functions</div>
<div class="tab" id="tab_variables" onClick="switch_tab('tab_variables')">variables</div>
<div class="tab" id="tab_history" onClick="switch_tab('tab_history')">history</div>
</div>
<div id="master">
<!--- <div class="master_element"><span class="master_element_text">command</span></div> -->

View File

@ -55,7 +55,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
return out.split('\n')
def do_get_variables(self):
out, err = run_fish_cmd('set')
out, err = run_fish_cmd('set -L')
# Put all the variables into a dictionary
vars = {}
@ -65,15 +65,20 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
fish_var = FishVar(comps[0], comps[1])
vars[fish_var.name] = fish_var
# Mark universal variables
for name in self.do_get_variable_names('set -nU'):
# Mark universal variables. L means don't abbreviate.
for name in self.do_get_variable_names('set -nUL'):
if name in vars: vars[name].universal = True
# Mark exported variables
for name in self.do_get_variable_names('set -nx'):
# Mark exported variables. L means don't abbreviate.
for name in self.do_get_variable_names('set -nxL'):
if name in vars: vars[name].exported = True
return [vars[key].get_json_obj() for key in sorted(vars.keys(), key=str.lower)]
def do_get_history(self):
# Use \x1e ("record separator") to distinguish between history items. The first
# backslash is so Python passes one backslash to fish
out, err = run_fish_cmd('for val in $history; echo -n $val \\x1e; end')
return out.split('\x1e')
def do_get_color_for_variable(self, name):
@ -89,6 +94,8 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
output = self.do_get_functions()
elif p == '/variables/':
output = self.do_get_variables()
elif p == '/history/':
output = self.do_get_history()
elif re.match(r"/color/(\w+)/", p):
name = re.match(r"/color/(\w+)/", p).group(1)
output = self.do_get_color_for_variable(name)
@ -101,8 +108,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.wfile.write('\n')
# Output JSON
print len(output)
print output
json.dump(output, self.wfile)