Adding display, fixing show to include quotes in strings

This commit is contained in:
Dustin Swan 2026-04-06 20:52:05 -06:00
parent d99de85dee
commit 8932fef6b9
No known key found for this signature in database
GPG key ID: 30D46587E2100467
2 changed files with 41 additions and 27 deletions

View file

@ -22,7 +22,7 @@ treeNodeHeight = value path expanded \
| True \ lineH + (sum (mapWithIndex (item i \ | True \ lineH + (sum (mapWithIndex (item i \
(valueLabel item) (valueLabel item)
| Some _ \ lineH | Some _ \ lineH
| None \ lineH + (treeNodeHeight item (path & [show i]) expanded) | None \ lineH + (treeNodeHeight item (path & [display i]) expanded)
) items)) ) items))
| False \ lineH) | False \ lineH)
| _ \ lineH; | _ \ lineH;
@ -40,7 +40,7 @@ visiblePaths = value path expanded \ value
| ListValue items \ ( | ListValue items \ (
[{ path = path, leaf = False }, ...(contains path expanded) [{ path = path, leaf = False }, ...(contains path expanded)
| True \ flatten (mapWithIndex (item i \ | True \ flatten (mapWithIndex (item i \
itemPath = path & [show i]; itemPath = path & [display i];
(valueLabel item) (valueLabel item)
| Some _ \ [{ path = itemPath, leaf = True }] | Some _ \ [{ path = itemPath, leaf = True }]
| None \ visiblePaths item itemPath expanded | None \ visiblePaths item itemPath expanded
@ -142,7 +142,7 @@ treeNode = config \
| True \ [ui.clickable { | True \ [ui.clickable {
onClick = _ \ noOp, onClick = _ \ noOp,
child = ui.column { gap = 0, children = mapWithIndex (item i \ child = ui.column { gap = 0, children = mapWithIndex (item i \
treeNode { value = item, depth = depth + 1, path = config.path & [show i], expanded = config.expanded, onToggle = config.onToggle, selectedPath = config.selectedPath, prefix = (show i) & ": ", editing = config.editing, onDoneEditing = config.onDoneEditing, onEditLeaf = config.onEditLeaf } treeNode { value = item, depth = depth + 1, path = config.path & [display i], expanded = config.expanded, onToggle = config.onToggle, selectedPath = config.selectedPath, prefix = (display i) & ": ", editing = config.editing, onDoneEditing = config.onDoneEditing, onEditLeaf = config.onEditLeaf }
) items } ) items }
}] }]
| False \ []) | False \ [])

View file

@ -66,6 +66,20 @@ export const _rt = {
int: (x: any) => typeof x === 'number' ? Math.floor(x) : parseInt(x, 10) || 0, int: (x: any) => typeof x === 'number' ? Math.floor(x) : parseInt(x, 10) || 0,
show: (value: any): string => { show: (value: any): string => {
if (value === null || value === undefined) return "None"; if (value === null || value === undefined) return "None";
if (typeof value === 'string') return JSON.stringify(value);
if (typeof value === 'number') return String(value);
if (typeof value === 'boolean') return value ? "True" : "False";
if (value._tag) return value._0 !== undefined ? `(${value._tag} ${_rt.show(value._0)})` : value._tag;
if (Array.isArray(value)) return `[${value.map(_rt.show).join(", ")}]`;
if (typeof value === 'function') return "<function>";
if (typeof value === 'object') {
const entries = Object.entries(value).map(([k, v]) => `${k} = ${_rt.show(v)}`);
return `{ ${entries.join(", ")} }`;
}
return String(value);
},
display: (value: any): string => {
if (value === null || value === undefined) return "";
if (typeof value === 'string') return value; if (typeof value === 'string') return value;
if (typeof value === 'number') return String(value); if (typeof value === 'number') return String(value);
if (typeof value === 'boolean') return value ? "True" : "False"; if (typeof value === 'boolean') return value ? "True" : "False";
@ -209,34 +223,34 @@ export const _rt = {
return { _tag: 'Err', _0: e.message }; return { _tag: 'Err', _0: e.message };
} }
}, },
"saveModule!": (moduleName: string) => { //"saveModule!": (moduleName: string) => {
const moduleDefs = [...definitions.values()] // const moduleDefs = [...definitions.values()]
.filter(d => d.module === moduleName); // .filter(d => d.module === moduleName);
if (moduleDefs.length === 0) return { _tag: 'Err', _0: 'No module: ' + moduleName }; // if (moduleDefs.length === 0) return { _tag: 'Err', _0: 'No module: ' + moduleName };
const content = '@' + moduleName + '\n\n' + // const content = '@' + moduleName + '\n\n' +
moduleDefs.map(d => prettyPrint(d)).join('\n\n') + '\n\n@\n'; // moduleDefs.map(d => prettyPrint(d)).join('\n\n') + '\n\n@\n';
fetch('/api/save', { // fetch('/api/save', {
method: 'POST', // method: 'POST',
headers: { 'Content-Type': 'application/json' }, // headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename: moduleName, content }) // body: JSON.stringify({ filename: moduleName, content })
}); // });
return { _tag: 'Defined', _0: moduleName }; // return { _tag: 'Defined', _0: moduleName };
}, //},
"saveDef!": (name: string) => { //"saveDef!": (name: string) => {
const def = definitions.get(name); // const def = definitions.get(name);
if (!def) return { _tag: 'Err', _0: 'Unknown: ' + name }; // if (!def) return { _tag: 'Err', _0: 'Unknown: ' + name };
const content = prettyPrint(def) + '\n'; // const content = prettyPrint(def) + '\n';
fetch('/api/save', { // fetch('/api/save', {
method: 'POST', // method: 'POST',
headers: { 'Content-Type': 'application/json' }, // headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename: name, content }) // body: JSON.stringify({ filename: name, content })
}); // });
return { _tag: 'Defined', _0: name }; // return { _tag: 'Defined', _0: name };
}, //},
rebind: (name: string, pathOrValue: any, maybeValue?: any) => { rebind: (name: string, pathOrValue: any, maybeValue?: any) => {
if (maybeValue === undefined) { if (maybeValue === undefined) {
store[name] = pathOrValue; store[name] = pathOrValue;