From: Ward Cunningham Date: Thu, 28 Nov 2024 20:42:19 +0000 (-0800) Subject: add headings and buttons X-Git-Url: https://dreyeck.freedombox.rocks/gitweb/idiomatic.git/commitdiff_plain/7d3a9854e6d5e13961db099f73efc29cda4d68bb?hp=f0a44e8482fdfa29b5a32d6a407509efe9984e3c add headings and buttons --- diff --git a/index.js b/index.js index 020a168..b8d5a57 100644 --- a/index.js +++ b/index.js @@ -22,14 +22,15 @@ async function load(file) { // P A G E S -const style = title => ` +const style = (title,here='') => ` - — ${title} —` +
— ${title}  ${escape(here)}  —
` const app = express() app.get('/index', async (req,res,next) => { @@ -59,30 +60,37 @@ app.get('/terminal', (req,res) => { const lits = counter() const doit = branch => {if(branch.type==type) lits.count(branch[field])} visitor.wander(mods,doit) - const result = style('terminal')+` + const result = style('terminal',type)+`

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

${lits.tally() - .map(([k,v]) => `
${v}${escape(k)}`) + .map(([k,v]) => `
${v}${escape(k)}`) .join("\n")}
` res.send(result) }) app.get('/usage', (req,res) => { - const {type,field,key,up,see} = req.query + const {type,field,key,width,depth} = 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[up ?? 2], see ?? 3)}`) + ${sxpr(stack[width ?? 2], depth ?? 3)}`) } visitor.wander(mods,doit) 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')+` + const q = (id,delta) => Object.entries(req.query) + .map(([k,v]) => k == id ? `${k}=${+v+delta}` : `${k}=${v}`) + .join('&') + const p = id => ` + ` + const m = id => ` − ` + const d = id => `${id} ${p(id)} ${m(id)}` + res.send(style('usage',key)+`

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

— ${d('width')} ${d('depth')} —

${list.join("\n")}
`) })