Last active
May 12, 2020 14:35
-
-
Save dockimbel/091cc787b366a3d88972b8cb9e2878b2 to your computer and use it in GitHub Desktop.
Native reactive spreadsheet demo in 14 LOC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;-- Each line is limited to 82 characters. Requires Red build from 07/07/2016 at least. | |
;-- Save it to a file to be able to run it, or type at console's prompt `do [`, paste the code, type `]` and ENTER. | |
Red [] L: charset "ABCDEFGHI" D: union N: charset "123456789" charset "0" repeat | |
y 9 [repeat x 9 [col: either x = 1 [#"^(2028)"][#"A" + (x - 2)] append p: [] set | |
ref:(to word! rejoin [col y - 1]) make face! [size: 90x24 type: pick [text field] | |
header?: (y = 1) or (x = 1) offset: -20x10 + as-pair ((x - 1) * size/x + 2) ((y | |
- 1) * size/y + 1) text: form case [y = 1 [col] x = 1 [y - 1] 'else [copy ""]] | |
para: make para! [align: pick [center right] header?] extra: object [name: form | |
ref formula: old: none] actors: context [on-create: on-unfocus: function [f e][ | |
f/color: none if rel: f/extra/old [react/unlink rel 'all] if #"=" = first | |
f/extra/formula: copy text: copy f/text [parse remove text [any [p: L N not ["/" | |
skip not N] insert p " " insert "/data " | L skip | p: some D opt [some D] insert | |
p " " insert " " | skip]] f/text: rejoin [f/extra/name "/data: any [math/safe [" | |
text {] "#UND"]}] if f/data [any [react f/extra/old: f/data do f/data]]]] | |
on-focus: func [f e][f/text: any [f/extra/formula f/text] f/color: yello]]]]] | |
view [size 840x300 title "PicoSheet" do [self/pane: p]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why all this trouble for a one-liner? ;-)
Great little app.
I have put all variations from http://www.red-lang.org/2016/07/native-reactive-spreadsheet-in-17-loc.html in 1 script without even removing the Red headers and ran the script without any problems from my GUI-console.exe program. Close one "spreadsheet" and the next example opens.
(Just added this comment for the interested followers on https://news.ycombinator.com/item?id=12052016 )