From 8c20a29b54acddcd80551915691d498be2bdeac7 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 12 Feb 2026 19:41:14 -0700 Subject: [PATCH] fixing pretty printer. adding updateAt. getting maximize windows going. fixing scrolling. new windows start focused --- src/ast.ts | 9 ++++++++- src/cg/01-stdlib.cg | 5 +++++ src/cg/10-os.cg | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index 3ad6079..f214470 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -191,7 +191,14 @@ export function prettyPrint(ast: AST, indent = 0): string { case 'apply': const func = prettyPrint(ast.func, 0); - const args = ast.args.map(a => prettyPrint(a, 0)).join(' '); + const args = ast.args.map(a => { + const printed = prettyPrint(a, 0); + if (a.kind === 'lambda' || a.kind === 'match' || a.kind === 'let' || a.kind === 'rebind') { + return `(${printed})`; + } + return printed; + }).join(' '); + return `(${func} ${args})` case 'let': diff --git a/src/cg/01-stdlib.cg b/src/cg/01-stdlib.cg index 6a12a52..a7d08b6 100644 --- a/src/cg/01-stdlib.cg +++ b/src/cg/01-stdlib.cg @@ -32,6 +32,11 @@ filter = f list \ list | True \ [x, ...filter f xs] | False \ filter f xs); +# updateAt +updateAt = i f list \ mapWithIndex (x j \ + (i == j | True \ f x | False \ x) +) list; + # fold : (b \ a \ b) \ b \ List a \ b fold = f acc list \ list | [] \ acc diff --git a/src/cg/10-os.cg b/src/cg/10-os.cg index a61fe4e..f3c9ab5 100644 --- a/src/cg/10-os.cg +++ b/src/cg/10-os.cg @@ -5,17 +5,29 @@ osState = { windows = [], wm = { focusedIndex = 0, - scrollOffset = 0 + scrollOffset = 0, + defaultWindowWidth = 800 }, nextId = 0 }; +windowWidth = window \ window.fullWidth + | True \ viewport.width + | False \ window.width; + openWindow = title content \ id = osState.nextId; batch [ osState.nextId := id + 1, - osState.windows := osState.windows & [{ id = id, title = title, content = content, width = 400 }], - osState.palette.visible := False + osState.windows := osState.windows & [{ + id = id, + title = title, + content = content, + width = osState.wm.defaultWindowWidth, + fullWidth = False + }], + osState.palette.visible := False, + focusWindow id ]; closeWindowByIndex = i \ @@ -28,7 +40,8 @@ closeWindowByIndex = i \ batch [ osState.windows := (take i osState.windows) & (drop (i + 1) osState.windows), - osState.wm.focusedIndex := min newFocused (len osState.windows - 2) + focusWindow newFocused + # osState.wm.focusedIndex := min newFocused (len osState.windows - 2) ]; closeFocusedWindow = _ \ closeWindowByIndex osState.wm.focusedIndex; @@ -37,12 +50,16 @@ closeWindowById = id \ i = index id (map (w \ w.id) osState.windows); closeWindowByIndex (unwrapOr 0 i); +toggleMaximizeFocusedWindow = _ \ + idx = osState.wm.focusedIndex; + osState.windows := updateAt idx (w \ w.{ fullWidth = not w.fullWidth }) osState.windows; + scrollToWindow = index \ windows = osState.windows; - widths = map (w \ w.width) windows; + widths = map windowWidth windows; gap = 1; windowX = (sum (take index widths)) + (index * gap); - windowW = unwrapOr 400 (nth index widths); + windowW = unwrapOr osState.wm.defaultWindowWidth (nth index widths); scrollOffset = osState.wm.scrollOffset; vw = viewport.width; (windowX < scrollOffset @@ -66,10 +83,11 @@ onSelect = input \ renderWindow = window isActive \ titleBarHeight = 30; + ui.stack { children = [ # background - ui.rect { w = window.width, h = viewport.height, color = (isActive | True \ "#0a2a3a" | False \ "#061820")}, + ui.rect { w = (windowWidth window), h = viewport.height, color = (isActive | True \ "#0a2a3a" | False \ "#061820")}, # title bar ui.positioned { @@ -77,7 +95,7 @@ renderWindow = window isActive \ child = ui.stack { children = [ # background - ui.rect { w = window.width, h = titleBarHeight, color = (isActive | True \ "#a15f80" | False \ "#0f3348") }, + ui.rect { w = (windowWidth window), h = titleBarHeight, color = (isActive | True \ "#a15f80" | False \ "#0f3348") }, ui.row { children = [ # close button @@ -107,7 +125,7 @@ renderWindow = window isActive \ ui.positioned { x = 0, y = titleBarHeight, child = ui.clip { - w = window.width, + w = (windowWidth window), h = viewport.height - titleBarHeight, child = window.content } @@ -161,6 +179,8 @@ os = ui.stateful { ) | Key { key = "d", meta = True } \ { state = state, emit = [closeFocusedWindow 0] } + | Key { key = "f", meta = True } \ + { state = state, emit = [toggleMaximizeFocusedWindow 0] } | _ \ { state = state, emit = [] }, view = state \