Taking functions out of state so i can persist it

This commit is contained in:
Dustin Swan 2026-04-02 19:37:06 -06:00
parent f7c3dff80f
commit ae7ee9418b
No known key found for this signature in database
GPG key ID: 30D46587E2100467

View file

@ -3,16 +3,21 @@
osState = { osState = {
palette = { visible = False }, palette = { visible = False },
windows = [], windows = [],
blah = 53,
wm = { wm = {
focusedIndex = 0, focusedIndex = 0,
scrollOffset = 0, scrollOffset = 0,
defaultWindowWidth = 800 defaultWindowWidth = 800
}, },
nextId = 6 nextId = 8
}; };
paletteHistory = ["textEditor \"palette\"", "gt", "textEditor \"os\""]; paletteHistory = [
"textEditor \"osState\"",
"osState",
"textEditor \"palette\"",
"join",
"textEditor \"os\""
];
os = openPalette = _ \ osState.palette.visible := not osState.palette.visible; os = openPalette = _ \ osState.palette.visible := not osState.palette.visible;
@ -41,14 +46,14 @@ focusWindow = index \ batch [
osState.wm.scrollOffset := scrollToWindow index osState.wm.scrollOffset := scrollToWindow index
]; ];
openWindow = title content width \ openWindow = title appExpr width \
id = osState.nextId; id = osState.nextId;
batch [ batch [
osState.nextId := id + 1, osState.nextId := id + 1,
osState.windows := osState.windows & [{ osState.windows := osState.windows & [{
id = id, id = id,
title = title, title = title,
content = content, appExpr = appExpr,
width = width, width = width,
fullWidth = False fullWidth = False
}], }],
@ -78,10 +83,10 @@ toggleMaximizeFocusedWindow = _ \
idx = osState.wm.focusedIndex; idx = osState.wm.focusedIndex;
osState.windows := updateAt idx (w \ w.{ fullWidth = not w.fullWidth }) osState.windows; osState.windows := updateAt idx (w \ w.{ fullWidth = not w.fullWidth }) osState.windows;
openOrFocus = title content width \ openOrFocus = title appExpr width \
index title (map (w \ w.title) osState.windows) index title (map (w \ w.title) osState.windows)
| (Some i) \ focusWindow i | (Some i) \ focusWindow i
| None \ openWindow title content width; | None \ openWindow title appExpr width;
renderWindow = window isActive \ renderWindow = window isActive \
titleBarHeight = 36; titleBarHeight = 36;
@ -130,12 +135,17 @@ renderWindow = window isActive \
child = ui.clip { child = ui.clip {
w = windowWidth window, w = windowWidth window,
h = viewport.height - titleBarHeight, h = viewport.height - titleBarHeight,
child = window.content { child = eval! window.appExpr
w = windowWidth window, | (Value app) \ (hasField "view" app
h = viewport.height - titleBarHeight, | True \ app.view {
openApp = openOrFocus, w = windowWidth window,
close = _ \ closeWindowById window.id h = viewport.height - titleBarHeight,
} openApp = openOrFocus,
close = _ \ closeWindowById window.id
}
| False \ text (show app))
| (Err msg) \ text msg
| _ \ text "App not found"
} }
} }
] }; ] };
@ -187,23 +197,18 @@ search = q \
onSelect = input \ onSelect = input \
historyEvent = paletteHistory := take 50 [input, ...filter (e \ e != input) paletteHistory]; historyEvent = paletteHistory := take 50 [input, ...filter (e \ e != input) paletteHistory];
dw = osState.wm.defaultWindowWidth; dw = osState.wm.defaultWindowWidth;
appWidth = app \
hasField "width" app
| True \ app.width
| false \ dw;
openEvent = eval! input openEvent = eval! input
| (Defined name) \ (app = inspector { name = name }; | (Defined name) \ openOrFocus name input dw
openOrFocus name app.view (appWidth app)) | (Value v) \ (hasField "view" v
| (Value v) \ (hasField "_tag" v | True \ openOrFocus input input (hasField "width" v
| True \ batch [historyEvent, v] | True \ v.width
| False \ (hasField "view" v | False \ dw)
| True \ openOrFocus input v.view (appWidth v) | False \ (hasField "_tag" v
| False \ ((getSource input) == "" | True \ batch [historyEvent, v]
| True \ openOrFocus input (_ \ renderText { content = show v, color = "white" }) dw | False \ openOrFocus input input dw))
| False \ (app = inspector { name = input };
openOrFocus input app.view (appWidth app)))))
| (Err msg) \ (_ = debug! "OS Error" msg; | (Err msg) \ (_ = debug! "OS Error" msg;
noOp); noOp)
| _ \ noOp;
batch [historyEvent, openEvent]; batch [historyEvent, openEvent];
handleFocusLeftEvent = state \ handleFocusLeftEvent = state \