Commit e8e6a7df authored by Camil Staps's avatar Camil Staps 🚀

stats

parent 0327374d
......@@ -3,6 +3,7 @@ search
builddb
CloogleServer
*.prj
*.json
*.1
types.db
cloogle.log
node_modules/
......@@ -2,70 +2,6 @@ var form_str = document.getElementById('search_str');
var sform = document.getElementById('search_form');
var sresults = document.getElementById('search_results');
function highlight(type) {
str = '';
var lex = {
start: [
[/^(\s+)(.*)/, ['whitespace']],
[/^(.+)(::.*)/, ['funcname'], 'type']
],
type: [
[/^(\s+)(.*)/, ['whitespace']],
[/^([a-z][a-zA-Z]*)(.*)/, ['typevar']],
[/^([A-Z]\w*)(.*)/, ['type']],
[/^(\/\/.*)(.*?)/, ['comment']],
[/^(\|)(.*)/, ['punctuation'], 'context'],
[/^(\W)(.*)/, ['punctuation']]
],
context: [
[/^(\s+)(.*)/, ['whitespace']],
[/^(\/\/.*)(.*?)/, ['comment']],
[/^(,)(.*)/, ['punctuation']],
[/^(\S+)(,.*)/, ['classname']],
[/^(\S+)(.*)/, ['classname'], 'contextType']
],
contextType: [
[/^(\s+)(.*)/, ['whitespace']],
[/^(\/\/.*)(.*?)/, ['comment']],
[/^([,&])(.*)/, ['punctuation'], 'context'],
[/^([^\s,]+)(.*)/, ['typevar']]
]
};
state = 'start';
while (true) {
var found = false;
for (i in lex[state]) {
patt = lex[state][i][0];
clss = lex[state][i][1];
if (type.match(patt)) {
parts = patt.exec(type);
var j = 0;
for (k in clss) {
j = parseInt(k)+1;
str += '<span class="' + clss[k] + '">' + escapeHTML(parts[j]) + '</span>';
}
type = parts[j+1];
found = true;
if (lex[state][i].length > 2)
state = lex[state][i][2];
break;
}
}
if (!found || type == '')
return str;
}
}
function escapeHTML(unsafe) {
var map = { "&": "&amp;", "<": "&lt;", ">": "&gt;",
'"': '&quot;', "'": '&#39;', "/": '&#x2F;' };
return String(unsafe).replace(/[&<>"'\/]/g, function(s){return map[s];});
}
function getResults(str, page) {
var url = 'api.php?str=' + encodeURIComponent(str) + '&page=' + page;
var xmlHttp = new XMLHttpRequest();
......@@ -122,10 +58,10 @@ function makeUnifier(ufr) {
var from_right = ufr[1];
var s = '';
for (i in from_right) {
s += from_right[i][0] + ' &rarr; ' + from_right[i][1] + '; ';
s += '<tt>' + from_right[i][0] + '</tt> &rarr; <tt>' + from_right[i][1] + '</tt>; ';
}
for (i in from_left) {
s += from_left[i][1] + ' &larr; ' + from_left[i][0] + '; ';
s += '<tt>' + from_left[i][1] + '</tt> &larr; <tt>' + from_left[i][0] + '</tt>; ';
}
return s.substring(0, s.length - 2);
}
......
.comment { color: #aaaaaa; }
.funcname { color: #5998c2; font-weight: bold; }
.classname { color: #5998c2; }
.typevar { color: #59c28a; font-weight: bold; }
.type { color: #e3890b; font-weight: bold; }
.punctuation { color: #777777; }
function highlight(type) {
str = '';
var lex = {
start: [
[/^(\s+)(.*)/, ['whitespace']],
[/^(.*)(::.*)/, ['funcname'], 'type'],
[/^(\S+)(.*)/, ['funcname']]
],
type: [
[/^(\s+)(.*)/, ['whitespace']],
[/^([a-z][a-zA-Z]*)(.*)/, ['typevar']],
[/^([A-Z]\w*)(.*)/, ['type']],
[/^(\/\/.*)(.*?)/, ['comment']],
[/^(\|)(.*)/, ['punctuation'], 'context'],
[/^(\W)(.*)/, ['punctuation']]
],
context: [
[/^(\s+)(.*)/, ['whitespace']],
[/^(\/\/.*)(.*?)/, ['comment']],
[/^(,)(.*)/, ['punctuation']],
[/^(\S+)(,.*)/, ['classname']],
[/^(\S+)(.*)/, ['classname'], 'contextType']
],
contextType: [
[/^(\s+)(.*)/, ['whitespace']],
[/^(\/\/.*)(.*?)/, ['comment']],
[/^([,&])(.*)/, ['punctuation'], 'context'],
[/^([^\s,]+)(.*)/, ['typevar']]
]
};
state = 'start';
while (true) {
var found = false;
for (i in lex[state]) {
patt = lex[state][i][0];
clss = lex[state][i][1];
if (type.match(patt)) {
parts = patt.exec(type);
var j = 0;
for (k in clss) {
j = parseInt(k)+1;
str += '<span class="' + clss[k] + '">' + escapeHTML(parts[j]) + '</span>';
}
type = parts[j+1];
found = true;
if (lex[state][i].length > 2)
state = lex[state][i][2];
break;
}
}
if (!found || type == '')
return str;
}
}
function escapeHTML(unsafe) {
var map = { "&": "&amp;", "<": "&lt;", ">": "&gt;",
'"': '&quot;', "'": '&#39;', "/": '&#x2F;' };
return String(unsafe).replace(/[&<>"'\/]/g, function(s){return map[s];});
}
......@@ -5,14 +5,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="api.js" type="text/javascript" defer="defer"></script>
<style type="text/css">
.comment { color: #aaaaaa; }
.funcname { color: #5998c2; font-weight: bold; }
.classname { color: #5998c2; }
.typevar { color: #59c28a; font-weight: bold; }
.type { color: #e3890b; font-weight: bold; }
.punctuation { color: #777777; }
</style>
<script src="clean.js" type="text/javascript" defer="defer"></script>
<link rel="stylesheet" href="clean.css" type="text/css"/>
</head>
<body>
<a href="https://github.com/dopefishh/cloogle">
......
#!/bin/sh
while :
do
< types.db \
stdbuf -i0 -o0 -e0 \
./CloogleServer 31215 \
| tee -a cloogle.log
done
var searches = [];
Date.prototype.timeNow = function () {
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+
((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+
((this.getSeconds() < 10)?"0":"") + this.getSeconds();
}
function updateSearches() {
query = searches[0];
console.log(query);
var last = document.getElementById('last-search');
last.innerHTML = '<pre>' + highlight(query) + '</pre>';
last.innerHTML += '<div class="time">' + new Date().timeNow() + '</div>';
var previous = document.getElementById('previous-searches');
previous.innerHTML = '';
for (var i in searches) {
if (i == 0) continue;
var color = 100 + i * 20;
var color = 'rgb(' + color + ',' + color + ',' + color + ')';
previous.innerHTML += '<tt style="color:' + color + ';">' + searches[i] + '</tt><br/>';
}
}
connection = new WebSocket('ws://127.0.0.1:31216/', 'cloogle-stats');
connection.onopen = function() { console.log('Connection open'); }
connection.onclose = function() { console.log('Connection closed'); }
connection.onmessage = function(msg) {
console.log(msg.data);
var req = JSON.parse(msg.data);
var query = req.name + (req.unify ? ' :: ' + req.unify : '');
console.log(query);
searches.splice(0, 0, query);
if (searches.length > 10)
searches.splice(searches.length - 1, searches.length);
updateSearches();
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Live Cloogle stats</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Live Cloogle Stats</title>
<script type="text/javascript" src="client.js" defer="defer"></script>
<script type="text/javascript" src="../clean.js" defer="defer"></script>
<link rel="stylesheet" href="../clean.css" type="text/css"/>
<style type="text/css">
#last-search {
font-family: monospace;
font-size: 70px;
margin-bottom: 40px;
text-align: center;
width: 100%;
}
#last-search pre {
margin-bottom: 20px;
}
#last-search .time {
color: #888;
font-size: 35%;
}
#previous-searches {
font-size: 20px;
margin: 0 auto;
width: 200px;
}
</style>
</head>
<body>
<div id="last-search"></div>
<div id="previous-searches"></div>
</body>
</html>
{
"name": "cloogle-stats",
"version": "1.0.0",
"description": "Live Cloogle stats",
"main": "server.js",
"dependencies": {
"websocket": "^1.0.22"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dopefishh/cloogle.git"
},
"author": ["Mart Lubbers", "Camil Staps"],
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/dopefishh/cloogle/issues"
},
"homepage": "https://github.com/dopefishh/cloogle#readme"
}
var util = require('util');
var spawn = require('child_process').spawn;
var WebSocketServer = require('websocket').server;
var filename = process.argv[2];
if (!filename)
return util.puts("Usage: node server.js <LOG>");
http = require('http');
var server = http.createServer(function(req,res){
res.writeHead(400);
res.end();
});
server.listen(31216);
var ws = new WebSocketServer({
httpServer: server,
autoAcceptConnections: false
});
ws.on('request', function(req){
var con = req.accept('cloogle-stats', req.origin);
var tail = spawn("tail", ["-f", filename]);
tail.stdout.on('data', function(data){
var match = /<-- (\{.*\})/.exec(data);
if (match != null) {
console.log(match[1]);
con.sendUTF(match[1]);
}
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment