From: Ward Cunningham Date: Thu, 28 Nov 2024 05:35:33 +0000 (-0800) Subject: tabular format X-Git-Url: https://dreyeck.freedombox.rocks/gitweb/idiomatic.git/commitdiff_plain/f0a44e8482fdfa29b5a32d6a407509efe9984e3c?ds=sidebyside;hp=682a7215ae646bc71baf0be528b9c7d55b1cb445 tabular format --- diff --git a/index.js b/index.js index 18f87de..020a168 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,14 @@ async function load(file) { // P A G E S -const style = '' +const style = title => ` + + — ${title} —` const app = express() app.get('/index', async (req,res,next) => { @@ -33,10 +40,10 @@ app.get('/index', async (req,res,next) => { const result = `

${reductions.size()} non-terminals
${reductions.total()} reductions -

${reductions.tally() - .map(([k,v]) => `${v} ${link(k)}`) - .join("
")}` - res.send(style+result); +

${reductions.tally() + .map(([k,v]) => `
${v}${link(k)}`) + .join("\n")}
` + res.send(style('index')+result); next() }) @@ -47,32 +54,36 @@ function link(key) { return key } - app.get('/terminal', (req,res) => { const {type,field} = req.query const lits = counter() const doit = branch => {if(branch.type==type) lits.count(branch[field])} visitor.wander(mods,doit) - const result = ` + const result = style('terminal')+`

${lits.size()} uniques
${lits.total()} total -

${lits.tally() - .map(([k,v]) => `${v} ${escape(k)}`) - .join("
")}` - res.send(style+result) +

${lits.tally() + .map(([k,v]) => `
${v}${escape(k)}`) + .join("\n")}
` + res.send(result) }) app.get('/usage', (req,res) => { - const {type,field,key} = req.query + const {type,field,key,up,see} = req.query const list = [] + const files = counter() const doit = (branch,stack) => { if(branch.type==type && branch[field]==key)list.push(` - + ${stack.at(-1)} - ${sxpr(stack[2],3)}`) + ${sxpr(stack[up ?? 2], see ?? 3)}`) } visitor.wander(mods,doit) - res.send(style+`

${JSON.stringify(req.query,null,2)}
${list.join("
")}`) + const vis = row => row.split(/\n/)[3].trim().replaceAll(/<.*?>/g,'').replaceAll(/\.\.+/g,'..') + list.sort((a,b) => vis(a)>vis(b) ? 1 : -1) + res.send(style('usage')+` +

${files.tally().map(([k,v]) => `
${v}${k}`).join("\n")}
+

${list.join("\n")}
`) }) app.get('/nesting', (req,res) => { @@ -82,17 +93,17 @@ app.get('/nesting', (req,res) => { if(stack.at(-1)==file && branch.type==type && branch.start==start && branch.end==end) { const file = stack.at(-1) const path = stack.slice(0,-1).map((n,i) => ` - - ${n.type}: + + ${n.type}: ${sxpr(n,3,null,stack[i-1])}`).reverse() const hit = stack[1] result.push(` - ${path.join("")}


\n -

${escape(JSON.stringify(hit,omit,2))}
`) +

${path.join("")}

+

${escape(JSON.stringify(hit,omit,2))}
`) } } visitor.wander(mods,doit) - res.send(style+`
${JSON.stringify(req.query,null,2)}
${result.join("
")}`) + res.send(style('nesting')+`${result.join("
")}`) }) @@ -106,6 +117,7 @@ function counter() { counts.set(item, counts.get(item)+1) else counts.set(item,1) + return item }, size() { return counts.size