Compare commits
8 Commits
3f1053ea61
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c45143dea5 | |||
| d2d5243711 | |||
| 5ddcbd461c | |||
| 2b8b721ec8 | |||
| 0ec93d0a1d | |||
| 30812e9763 | |||
| bbbcebc79c | |||
| bbc87afee1 |
19
.github/workflows/tests.yml
vendored
Normal file
19
.github/workflows/tests.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.25.x'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: go get .
|
||||||
|
- name: Build
|
||||||
|
run: go build -v ./...
|
||||||
|
- name: Test
|
||||||
|
run: go test -v ./...
|
||||||
30
go.mod
30
go.mod
@ -1,35 +1,39 @@
|
|||||||
module git.makyo.dev/makyo/gogogogogram
|
module git.makyo.dev/makyo/gogogogogram
|
||||||
|
|
||||||
go 1.24.6
|
go 1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/charmbracelet/bubbletea v1.3.6
|
charm.land/lipgloss/v2 v2.0.2
|
||||||
|
github.com/charmbracelet/bubbletea v1.3.10
|
||||||
github.com/smartystreets/goconvey v1.8.1
|
github.com/smartystreets/goconvey v1.8.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
github.com/charmbracelet/colorprofile v0.4.3 // indirect
|
||||||
github.com/charmbracelet/lipgloss v1.1.0 // indirect
|
github.com/charmbracelet/lipgloss v1.1.0 // indirect
|
||||||
github.com/charmbracelet/x/ansi v0.9.3 // indirect
|
github.com/charmbracelet/ultraviolet v0.0.0-20260316091819-b93f6a3b8502 // indirect
|
||||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
github.com/charmbracelet/x/ansi v0.11.6 // indirect
|
||||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
|
||||||
|
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||||
|
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||||
|
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||||
|
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||||
|
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||||
github.com/jtolds/gls v4.20.0+incompatible // indirect
|
github.com/jtolds/gls v4.20.0+incompatible // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
github.com/mattn/go-runewidth v0.0.21 // indirect
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||||
github.com/muesli/termenv v0.16.0 // indirect
|
github.com/muesli/termenv v0.16.0 // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/smarty/assertions v1.15.0 // indirect
|
github.com/smarty/assertions v1.15.0 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||||
golang.org/x/mod v0.9.0 // indirect
|
golang.org/x/sync v0.20.0 // indirect
|
||||||
golang.org/x/sync v0.15.0 // indirect
|
golang.org/x/sys v0.42.0 // indirect
|
||||||
golang.org/x/sys v0.33.0 // indirect
|
golang.org/x/text v0.35.0 // indirect
|
||||||
golang.org/x/text v0.3.8 // indirect
|
|
||||||
golang.org/x/tools v0.7.0 // indirect
|
|
||||||
)
|
)
|
||||||
|
|||||||
61
go.sum
61
go.sum
@ -1,38 +1,49 @@
|
|||||||
|
charm.land/lipgloss/v2 v2.0.2 h1:xFolbF8JdpNkM2cEPTfXEcW1p6NRzOWTSamRfYEw8cs=
|
||||||
|
charm.land/lipgloss/v2 v2.0.2/go.mod h1:KjPle2Qd3YmvP1KL5OMHiHysGcNwq6u83MUjYkFvEkM=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||||
github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU=
|
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
|
||||||
github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc=
|
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
|
||||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
|
github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=
|
||||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
|
github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=
|
||||||
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
||||||
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
||||||
github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0=
|
github.com/charmbracelet/ultraviolet v0.0.0-20260316091819-b93f6a3b8502 h1:hzWNs3UQRSUTS6YCbLaQnwqKBFXT5Yh1OOw6+26apqg=
|
||||||
github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
|
github.com/charmbracelet/ultraviolet v0.0.0-20260316091819-b93f6a3b8502/go.mod h1:mkUCcxn9w9j89JJp3pOza5tmDQZPgIB75UfmQlFYvas=
|
||||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
|
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
|
||||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
|
||||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
|
||||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
|
||||||
|
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||||
|
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
|
||||||
|
github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY=
|
||||||
|
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
|
||||||
|
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
|
||||||
|
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
|
||||||
|
github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=
|
||||||
|
github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
|
||||||
|
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
|
||||||
|
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||||
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
|
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
|
||||||
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
|
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
github.com/mattn/go-runewidth v0.0.21 h1:jJKAZiQH+2mIinzCJIaIG9Be1+0NR+5sz/lYEEjdM8w=
|
||||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.21/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
||||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
|
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
|
||||||
@ -41,17 +52,13 @@ github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sS
|
|||||||
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
|
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||||
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
|
|
||||||
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
|
||||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
|
||||||
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
|
|
||||||
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
|
|
||||||
|
|||||||
3
main.go
3
main.go
@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"git.makyo.dev/makyo/gogogogogram/ui"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
p := tea.NewProgram(newModel(4, 4))
|
p := tea.NewProgram(ui.NewModel(4, 4))
|
||||||
if _, err := p.Run(); err != nil {
|
if _, err := p.Run(); err != nil {
|
||||||
fmt.Printf("Ah drat — %v\n", err)
|
fmt.Printf("Ah drat — %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestCursor(t *testing.T) {
|
func TestCursor(t *testing.T) {
|
||||||
Convey("Given a cursor", t, func() {
|
Convey("Given a cursor", t, func() {
|
||||||
s := New(4, 4)
|
s := New(4, 4, false)
|
||||||
So(*s.cursor, ShouldResemble, Point{0, 0})
|
So(*s.cursor, ShouldResemble, Point{0, 0})
|
||||||
|
|
||||||
Convey("When moving cell to cell", func() {
|
Convey("When moving cell to cell", func() {
|
||||||
@ -82,12 +82,12 @@ func TestCursor(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("You can't move up beyond the top", func() {
|
Convey("You can't move up beyond the top", func() {
|
||||||
s.CursorCellUp()
|
s.CursorSectionUp()
|
||||||
So(*s.cursor, ShouldResemble, Point{0, 0})
|
So(*s.cursor, ShouldResemble, Point{0, 0})
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("You can't move left beyond the edge", func() {
|
Convey("You can't move left beyond the edge", func() {
|
||||||
s.CursorCellLeft()
|
s.CursorSectionLeft()
|
||||||
So(*s.cursor, ShouldResemble, Point{0, 0})
|
So(*s.cursor, ShouldResemble, Point{0, 0})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,10 @@ func TestField(t *testing.T) {
|
|||||||
So(f.i(Point{1, 1}), ShouldEqual, 3)
|
So(f.i(Point{1, 1}), ShouldEqual, 3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("You can get the byte for a particular cell", func() {
|
||||||
|
So(f.cell(Point{0, 0}), ShouldEqual, cell(0))
|
||||||
|
})
|
||||||
|
|
||||||
Convey("You can get a string representation of the field", func() {
|
Convey("You can get a string representation of the field", func() {
|
||||||
So(f.String(), ShouldEqual, "\x00\x00\x00\x00")
|
So(f.String(), ShouldEqual, "\x00\x00\x00\x00")
|
||||||
})
|
})
|
||||||
|
|||||||
117
state/history.go
117
state/history.go
@ -1,20 +1,27 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import "strconv"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
// History returns the gameplay history for replays
|
// History returns the gameplay history for replays
|
||||||
func (s *State) History() string {
|
func (s *State) History() string {
|
||||||
return s.history
|
return s.history
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnmarshalAll(history string) *State {
|
func UnmarshalAll(history string) (*State, error) {
|
||||||
s := Unmarshal(history)
|
s := Unmarshal(history)
|
||||||
for {
|
for {
|
||||||
if !s.Step() {
|
res, err := s.Step()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !res {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Unmarshal(history string) *State {
|
func Unmarshal(history string) *State {
|
||||||
@ -25,16 +32,33 @@ func Unmarshal(history string) *State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) Step() bool {
|
func (s *State) Step() (bool, error) {
|
||||||
if s.historyIndex >= len(s.history) {
|
if s.historyIndex >= len(s.history) {
|
||||||
return false
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch s.history[s.historyIndex] {
|
||||||
|
case 'i', 'm', 'f', 'c', 'r', 'l', 'u', 'd', 'R', 'L', 'U', 'D':
|
||||||
|
err := s.beforeAct()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch s.history[s.historyIndex] {
|
switch s.history[s.historyIndex] {
|
||||||
case 'g':
|
case 'g':
|
||||||
s.historyStart()
|
if s.initialized {
|
||||||
|
return false, fmt.Errorf("initialization step in invalid location (index %d)", s.historyIndex)
|
||||||
|
}
|
||||||
|
err := s.historyStart()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
case 'i':
|
case 'i':
|
||||||
s.historyInitSection()
|
err := s.historyInitSection()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
case 'm':
|
case 'm':
|
||||||
s.mark(*s.cursor)
|
s.mark(*s.cursor)
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -57,15 +81,43 @@ func (s *State) Step() bool {
|
|||||||
s.cursorSectionUp()
|
s.cursorSectionUp()
|
||||||
case 'D':
|
case 'D':
|
||||||
s.cursorSectionDown()
|
s.cursorSectionDown()
|
||||||
|
case 't': // TODO for now, this is just sugar. Will be a timestamp for events completed.
|
||||||
|
for {
|
||||||
|
s.historyIndex++
|
||||||
|
if s.historyIndex >= len(s.history) || s.history[s.historyIndex] == ')' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case ' ', '\n', '\t':
|
||||||
|
break
|
||||||
|
case '#':
|
||||||
|
for {
|
||||||
|
s.historyIndex++
|
||||||
|
if s.historyIndex >= len(s.history) || s.history[s.historyIndex] == '\n' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false, fmt.Errorf("invalid step in history: %s (index %d)", string(s.history[s.historyIndex]), s.historyIndex)
|
||||||
}
|
}
|
||||||
s.historyIndex++
|
s.historyIndex++
|
||||||
|
|
||||||
return true
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) historyStart() {
|
func (s *State) beforeAct() error {
|
||||||
|
if !s.initialized {
|
||||||
|
return fmt.Errorf("tried to act on an uninitialized state (index %d)", s.historyIndex)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *State) historyStart() error {
|
||||||
peek := s.historyIndex + 1
|
peek := s.historyIndex + 1
|
||||||
p, peek := s.historyPoint(peek)
|
p, peek, err := s.historyPoint(peek)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
s.sectionSize = p.X
|
s.sectionSize = p.X
|
||||||
s.cellsPerSection = p.Y
|
s.cellsPerSection = p.Y
|
||||||
s.cells = newField(s.size())
|
s.cells = newField(s.size())
|
||||||
@ -75,11 +127,17 @@ func (s *State) historyStart() {
|
|||||||
s.colHeaders = make([]header, s.size())
|
s.colHeaders = make([]header, s.size())
|
||||||
s.historyIndex = peek
|
s.historyIndex = peek
|
||||||
s.score.Blackout = make([]bool, s.size())
|
s.score.Blackout = make([]bool, s.size())
|
||||||
|
s.initialized = true
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) historyInitSection() {
|
func (s *State) historyInitSection() error {
|
||||||
peek := s.historyIndex + 1
|
peek := s.historyIndex + 1
|
||||||
p, peek := s.historyPoint(peek)
|
p, peek, err := s.historyPoint(peek)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
segment := []byte(s.history[peek : peek+s.cellsPerSection*s.cellsPerSection])
|
segment := []byte(s.history[peek : peek+s.cellsPerSection*s.cellsPerSection])
|
||||||
for i, c := range segment {
|
for i, c := range segment {
|
||||||
curr := Point{
|
curr := Point{
|
||||||
@ -98,42 +156,49 @@ func (s *State) historyInitSection() {
|
|||||||
peek++
|
peek++
|
||||||
}
|
}
|
||||||
s.historyIndex = peek
|
s.historyIndex = peek
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) historyPoint(index int) (Point, int) {
|
func (s *State) historyPoint(index int) (Point, int, error) {
|
||||||
var x, y string
|
var x, y string
|
||||||
|
|
||||||
// Advance past paren
|
// Advance past opening paren
|
||||||
index++
|
index++
|
||||||
for {
|
for {
|
||||||
|
if index >= len(s.history) {
|
||||||
|
return Point{}, 0, fmt.Errorf("point.X never ended? (index %d)", index)
|
||||||
|
}
|
||||||
switch s.history[index] {
|
switch s.history[index] {
|
||||||
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||||
x += string(s.history[index])
|
x += string(s.history[index])
|
||||||
index++
|
index++
|
||||||
continue
|
continue
|
||||||
|
case ',':
|
||||||
|
index++
|
||||||
|
default:
|
||||||
|
return Point{}, 0, fmt.Errorf("invalid character in point.X: %s (index %d)", string(s.history[index]), index)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance past comma
|
|
||||||
index++
|
|
||||||
for {
|
for {
|
||||||
|
if index >= len(s.history) {
|
||||||
|
return Point{}, 0, fmt.Errorf("point.Y never ended? (index %d)", index)
|
||||||
|
}
|
||||||
switch s.history[index] {
|
switch s.history[index] {
|
||||||
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||||
y += string(s.history[index])
|
y += string(s.history[index])
|
||||||
index++
|
index++
|
||||||
continue
|
continue
|
||||||
|
case ')':
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return Point{}, 0, fmt.Errorf("invalid character in point.Y: %s (index %d)", string(s.history[index]), index)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
pX, err := strconv.Atoi(x)
|
pX, _ := strconv.Atoi(x)
|
||||||
if err != nil {
|
pY, _ := strconv.Atoi(y)
|
||||||
panic(err)
|
return Point{pX, pY}, index, nil
|
||||||
}
|
|
||||||
pY, err := strconv.Atoi(y)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return Point{pX, pY}, index
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ func TestHistory(t *testing.T) {
|
|||||||
Convey("Given a game's history", t, func() {
|
Convey("Given a game's history", t, func() {
|
||||||
|
|
||||||
Convey("You can maintain a history of all actions", func() {
|
Convey("You can maintain a history of all actions", func() {
|
||||||
s := New(2, 2)
|
s := New(2, 2, false)
|
||||||
s.Flag()
|
s.Flag()
|
||||||
s.Mark()
|
s.Mark()
|
||||||
s.Clear()
|
s.Clear()
|
||||||
@ -31,8 +32,9 @@ func TestHistory(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("You can load a game from its saved history", func() {
|
Convey("You can load a game from its saved history", func() {
|
||||||
history := "g(2,2)i(0,0)oxoxi(1,0)xoxoi(0,1)ooooi(1,1)xxxxfRmDcLUrldu"
|
history := "g(2,2)i(0,0)oxoxi(1,0)xoxoi(0,1)ooooi(1,1)xxxx\n# Here we goooo~\nfRmDcLUrldut(1773881959)"
|
||||||
s := UnmarshalAll(history)
|
s, err := UnmarshalAll(history)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
Convey("It sets the history", func() {
|
Convey("It sets the history", func() {
|
||||||
So(s.History(), ShouldEqual, history)
|
So(s.History(), ShouldEqual, history)
|
||||||
@ -53,5 +55,44 @@ func TestHistory(t *testing.T) {
|
|||||||
So(s.String(), ShouldEqual, "X. \n \no .\n....\n")
|
So(s.String(), ShouldEqual, "X. \n \no .\n....\n")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Errors are handled during loading", func() {
|
||||||
|
Convey("It raises errors if acting on an uninitialized state", func() {
|
||||||
|
s, err := UnmarshalAll("m")
|
||||||
|
So(err, ShouldResemble, errors.New("tried to act on an uninitialized state (index 0)"))
|
||||||
|
So(s, ShouldBeNil)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("It raises errors if trying to initialize an initialized state", func() {
|
||||||
|
s, err := UnmarshalAll("g(1,1)g(1,1)")
|
||||||
|
So(err, ShouldResemble, errors.New("initialization step in invalid location (index 6)"))
|
||||||
|
So(s, ShouldBeNil)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("It raises errors in reading points", func() {
|
||||||
|
s, err := UnmarshalAll("g(1")
|
||||||
|
So(err, ShouldResemble, errors.New("point.X never ended? (index 3)"))
|
||||||
|
So(s, ShouldBeNil)
|
||||||
|
|
||||||
|
s, err = UnmarshalAll("g(a,1)")
|
||||||
|
So(err, ShouldResemble, errors.New("invalid character in point.X: a (index 2)"))
|
||||||
|
So(s, ShouldBeNil)
|
||||||
|
|
||||||
|
s, err = UnmarshalAll("g(1,1)i(0,1")
|
||||||
|
So(err, ShouldResemble, errors.New("point.Y never ended? (index 11)"))
|
||||||
|
So(s, ShouldBeNil)
|
||||||
|
|
||||||
|
s, err = UnmarshalAll("g(1,a)")
|
||||||
|
So(err, ShouldResemble, errors.New("invalid character in point.Y: a (index 4)"))
|
||||||
|
So(s, ShouldBeNil)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("It only accepts valid steps", func() {
|
||||||
|
history := "g(2,2)i(0,0)oxoxi(1,0)xoxoi(0,1)ooooi(1,1)xxxxz"
|
||||||
|
s, err := UnmarshalAll(history)
|
||||||
|
So(err, ShouldResemble, errors.New("invalid step in history: z (index 46)"))
|
||||||
|
So(s, ShouldBeNil)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Point struct {
|
type Point struct {
|
||||||
@ -25,6 +26,8 @@ type header struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
|
initialized bool
|
||||||
|
|
||||||
cursor *Point
|
cursor *Point
|
||||||
|
|
||||||
score score
|
score score
|
||||||
@ -38,7 +41,7 @@ type State struct {
|
|||||||
rowHeaders, colHeaders []header
|
rowHeaders, colHeaders []header
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(sectionSize, cellsPerSection int) *State {
|
func New(sectionSize, cellsPerSection int, reveal bool) *State {
|
||||||
s := &State{
|
s := &State{
|
||||||
sectionSize: sectionSize,
|
sectionSize: sectionSize,
|
||||||
cellsPerSection: cellsPerSection,
|
cellsPerSection: cellsPerSection,
|
||||||
@ -55,7 +58,34 @@ func New(sectionSize, cellsPerSection int) *State {
|
|||||||
s.initSection(Point{x, y})
|
s.initSection(Point{x, y})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO reveal 1 row per section, 1 col per sections/2
|
if reveal {
|
||||||
|
for i := 0; i < s.sectionSize; i++ {
|
||||||
|
reveal := i*s.cellsPerSection + rand.Intn(s.cellsPerSection)
|
||||||
|
s.history += fmt.Sprintf("ry(%d)", reveal)
|
||||||
|
for x := 0; x < s.size(); x++ {
|
||||||
|
p := Point{x, reveal}
|
||||||
|
if s.cells.state(p) {
|
||||||
|
s.mark(p)
|
||||||
|
} else {
|
||||||
|
s.flag(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rand.Int()%2 == 0 {
|
||||||
|
reveal = i*s.cellsPerSection + rand.Intn(s.cellsPerSection)
|
||||||
|
s.history += fmt.Sprintf("rx(%d)", reveal)
|
||||||
|
for y := 0; y < s.size(); y++ {
|
||||||
|
p := Point{reveal, y}
|
||||||
|
if s.cells.state(p) {
|
||||||
|
s.mark(p)
|
||||||
|
} else {
|
||||||
|
s.flag(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.initialized = true
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,9 +144,6 @@ func (s *State) Clear() {
|
|||||||
s.clear(*s.cursor, true)
|
s.clear(*s.cursor, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) view(cursor []int) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) initSection(p Point) {
|
func (s *State) initSection(p Point) {
|
||||||
s.history += fmt.Sprintf("i%s", p)
|
s.history += fmt.Sprintf("i%s", p)
|
||||||
s.sections.clear(p, false)
|
s.sections.clear(p, false)
|
||||||
@ -213,13 +240,6 @@ func (s *State) scoreValidCompletedSections() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateAllHeaders runs updateHeaders for every row/column.
|
|
||||||
func (s *State) updateAllHeaders() {
|
|
||||||
for i := 0; i < s.size(); i++ {
|
|
||||||
s.updateHeaders(Point{i, i})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// updateHeaders makes sure that the counts of alive cells in rows/columns are accurate, and whether or not the row/column is complete.
|
// updateHeaders makes sure that the counts of alive cells in rows/columns are accurate, and whether or not the row/column is complete.
|
||||||
func (s *State) updateHeaders(p Point) {
|
func (s *State) updateHeaders(p Point) {
|
||||||
var rowHeader, colHeader header
|
var rowHeader, colHeader header
|
||||||
@ -269,6 +289,7 @@ func (s *State) update(p Point) {
|
|||||||
s.sections.setCorrect(sectionPoint, true)
|
s.sections.setCorrect(sectionPoint, true)
|
||||||
s.updateCompletedSections()
|
s.updateCompletedSections()
|
||||||
s.scoreValidCompletedSections()
|
s.scoreValidCompletedSections()
|
||||||
|
s.history += fmt.Sprintf("t(%d)", time.Now().Unix())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestState(t *testing.T) {
|
func TestState(t *testing.T) {
|
||||||
Convey("Given a game state", t, func() {
|
Convey("Given a game state", t, func() {
|
||||||
s := New(2, 2)
|
s := New(2, 2, false)
|
||||||
for x := 0; x < 4; x++ {
|
for x := 0; x < 4; x++ {
|
||||||
for y := 0; y < 4; y++ {
|
for y := 0; y < 4; y++ {
|
||||||
s.cells.kill(Point{x, y})
|
s.cells.kill(Point{x, y})
|
||||||
@ -48,6 +50,13 @@ func TestState(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("You can get the score", func() {
|
||||||
|
score := s.Score()
|
||||||
|
So(score.Clears, ShouldEqual, 0)
|
||||||
|
So(score.Score, ShouldEqual, 0)
|
||||||
|
So(score.Blackout, ShouldResemble, []bool{false, false, false, false})
|
||||||
|
})
|
||||||
|
|
||||||
Convey("You can complete sections and clear portions of the board", func() {
|
Convey("You can complete sections and clear portions of the board", func() {
|
||||||
s.cells.vivify(Point{0, 0})
|
s.cells.vivify(Point{0, 0})
|
||||||
s.cells.vivify(Point{2, 0})
|
s.cells.vivify(Point{2, 0})
|
||||||
@ -55,10 +64,13 @@ func TestState(t *testing.T) {
|
|||||||
s.cells.vivify(Point{2, 2})
|
s.cells.vivify(Point{2, 2})
|
||||||
|
|
||||||
Convey("It marks sections as correct when they are correctly guessed", func() {
|
Convey("It marks sections as correct when they are correctly guessed", func() {
|
||||||
s.mark(Point{0, 0})
|
s.Mark()
|
||||||
So(s.cells.correct(Point{0, 0}), ShouldBeTrue)
|
So(s.cells.correct(Point{0, 0}), ShouldBeTrue)
|
||||||
So(s.sections.correct(Point{0, 0}), ShouldBeTrue)
|
So(s.sections.correct(Point{0, 0}), ShouldBeTrue)
|
||||||
So(s.String(), ShouldEqual, "O . \n \n. . \n \n")
|
So(s.String(), ShouldEqual, "O . \n \n. . \n \n")
|
||||||
|
Convey("It adds a timestamp to the history when a section is completed", func() {
|
||||||
|
So(s.history, ShouldEndWith, fmt.Sprintf("mt(%d)", time.Now().Unix()))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("It marks sections as complete if they meet the criteria", func() {
|
Convey("It marks sections as complete if they meet the criteria", func() {
|
||||||
@ -77,7 +89,6 @@ func TestState(t *testing.T) {
|
|||||||
s.mark(Point{2, 0})
|
s.mark(Point{2, 0})
|
||||||
s.mark(Point{0, 2})
|
s.mark(Point{0, 2})
|
||||||
s.mark(Point{2, 2})
|
s.mark(Point{2, 2})
|
||||||
//So(res, ShouldResemble, []bool{true, true, true, true})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
102
state/view.go
Normal file
102
state/view.go
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package state
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"charm.land/lipgloss/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
cursorStyle = lipgloss.NewStyle().
|
||||||
|
Background(lipgloss.White)
|
||||||
|
|
||||||
|
gridStyle = lipgloss.NewStyle().
|
||||||
|
Foreground(lipgloss.Black)
|
||||||
|
|
||||||
|
markedStyle = lipgloss.NewStyle()
|
||||||
|
|
||||||
|
complete = []string{"██ ", "██ "}
|
||||||
|
flagged = []string{"╲╱ ", "╱╲ "}
|
||||||
|
marked = []string{" ", " "}
|
||||||
|
blank = []string{" ", " "}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *cell) View() []string {
|
||||||
|
if c.complete() {
|
||||||
|
return complete
|
||||||
|
} else if c.flagged() {
|
||||||
|
return flagged
|
||||||
|
} else if c.marked() {
|
||||||
|
return marked
|
||||||
|
} else {
|
||||||
|
return blank
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *field) View(p *Point, sectionSize, cellsPerSection int) string {
|
||||||
|
res := gridStyle.Render("┌─")
|
||||||
|
for c := 0; c < cellsPerSection*sectionSize*3; c++ {
|
||||||
|
res += gridStyle.Render("─")
|
||||||
|
if c == cellsPerSection*sectionSize*3-1 {
|
||||||
|
res += gridStyle.Render("┐") + "\n"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if c%(cellsPerSection*3) == cellsPerSection*3-1 {
|
||||||
|
res += gridStyle.Render("┬─")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resA := gridStyle.Render("│ ")
|
||||||
|
resB := gridStyle.Render("│ ")
|
||||||
|
for i, c := range f.cells {
|
||||||
|
cellRes := c.View()
|
||||||
|
if i == f.i(*p) {
|
||||||
|
resA += cursorStyle.Render(cellRes[0])
|
||||||
|
resB += cursorStyle.Render(cellRes[1])
|
||||||
|
} else if c.marked() {
|
||||||
|
markedStyle = lipgloss.NewStyle().
|
||||||
|
Background(lipgloss.Color(fmt.Sprintf("%d", i%214+16)))
|
||||||
|
resA += markedStyle.Render(cellRes[0])
|
||||||
|
resB += markedStyle.Render(cellRes[1])
|
||||||
|
} else {
|
||||||
|
resA += cellRes[0]
|
||||||
|
resB += cellRes[1]
|
||||||
|
}
|
||||||
|
if i%cellsPerSection == cellsPerSection-1 {
|
||||||
|
resA += gridStyle.Render("│ ")
|
||||||
|
resB += gridStyle.Render("│ ")
|
||||||
|
}
|
||||||
|
if i%f.size == f.size-1 {
|
||||||
|
res += fmt.Sprintf("%s\n%s\n", resA, resB)
|
||||||
|
resA = gridStyle.Render("│ ")
|
||||||
|
resB = gridStyle.Render("│ ")
|
||||||
|
}
|
||||||
|
if i != 0 && i%(cellsPerSection*cellsPerSection*sectionSize) == 0 {
|
||||||
|
res += gridStyle.Render("├─")
|
||||||
|
for section := 0; section < sectionSize; section++ {
|
||||||
|
for sectionCell := 0; sectionCell < cellsPerSection; sectionCell++ {
|
||||||
|
res += gridStyle.Render("───")
|
||||||
|
}
|
||||||
|
if section < sectionSize-1 {
|
||||||
|
res += gridStyle.Render("┼─")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res += gridStyle.Render("┤") + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res += gridStyle.Render("└─")
|
||||||
|
for c := 0; c < cellsPerSection*sectionSize*3; c++ {
|
||||||
|
res += gridStyle.Render("─")
|
||||||
|
if c == cellsPerSection*sectionSize*3-1 {
|
||||||
|
res += gridStyle.Render("┘\n")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if c%(cellsPerSection*3) == cellsPerSection*3-1 {
|
||||||
|
res += gridStyle.Render("┴─")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *State) View() string {
|
||||||
|
return s.cells.View(s.cursor, s.sectionSize, s.cellsPerSection)
|
||||||
|
}
|
||||||
@ -1,24 +1,31 @@
|
|||||||
package main
|
package ui
|
||||||
|
|
||||||
import "git.makyo.dev/makyo/gogogogogram/state"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.makyo.dev/makyo/gogogogogram/state"
|
||||||
|
)
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
fieldSize, sectionSize, cellsPerSection int
|
fieldSize, sectionSize, cellsPerSection int
|
||||||
|
|
||||||
state *state.State
|
state *state.State
|
||||||
|
|
||||||
|
filename string
|
||||||
|
file *os.File
|
||||||
|
|
||||||
clears, score, factor, track int
|
clears, score, factor, track int
|
||||||
|
|
||||||
columnStates, rowStates [][]int
|
columnStates, rowStates [][]int
|
||||||
columnsCorrect, rowsCorrect []bool
|
columnsCorrect, rowsCorrect []bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newModel(sectionSize, cellsPerSection int) model {
|
func NewModel(sectionSize, cellsPerSection int) model {
|
||||||
m := model{
|
m := model{
|
||||||
fieldSize: sectionSize * cellsPerSection,
|
fieldSize: sectionSize * cellsPerSection,
|
||||||
sectionSize: sectionSize,
|
sectionSize: sectionSize,
|
||||||
cellsPerSection: cellsPerSection,
|
cellsPerSection: cellsPerSection,
|
||||||
state: state.New(sectionSize, cellsPerSection),
|
state: state.New(sectionSize, cellsPerSection, true),
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package main
|
package ui
|
||||||
|
|
||||||
import tea "github.com/charmbracelet/bubbletea"
|
import tea "github.com/charmbracelet/bubbletea"
|
||||||
|
|
||||||
@ -17,6 +17,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case "ctrl+c":
|
case "ctrl+c":
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
||||||
|
// Saving
|
||||||
|
case "ctrl+s":
|
||||||
|
return m, nil
|
||||||
|
|
||||||
// Movement by cell
|
// Movement by cell
|
||||||
case "up", "w":
|
case "up", "w":
|
||||||
m.state.CursorCellUp()
|
m.state.CursorCellUp()
|
||||||
@ -31,17 +35,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.state.CursorCellLeft()
|
m.state.CursorCellLeft()
|
||||||
|
|
||||||
// Movement by section
|
// Movement by section
|
||||||
case "ctrl+up", "ctrl+w", "shift+up", "shift+w":
|
case "shift+up", "W":
|
||||||
m.state.CursorSectionUp()
|
m.state.CursorSectionUp()
|
||||||
|
|
||||||
case "ctrl+down", "ctrl+s", "shift+down", "shift+s":
|
case "shift+down", "S":
|
||||||
m.state.CursorSectionDown()
|
m.state.CursorSectionDown()
|
||||||
|
|
||||||
case "ctrl+right", "ctrl+d", "shift+right", "shift+d":
|
case "shift+right", "D":
|
||||||
m.state.CursorSectionRight()
|
m.state.CursorSectionRight()
|
||||||
|
|
||||||
case "ctrl+left", "ctrl+a", "shift+left", "shift+a":
|
case "shift+left", "A":
|
||||||
m.state.CursorSectionRight()
|
m.state.CursorSectionLeft()
|
||||||
|
|
||||||
// Marking/flagging
|
// Marking/flagging
|
||||||
case " ", "enter":
|
case " ", "enter":
|
||||||
@ -52,6 +56,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
|
|
||||||
case "delete", "backspace":
|
case "delete", "backspace":
|
||||||
m.state.Clear()
|
m.state.Clear()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,5 +64,5 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
return ""
|
return m.state.View()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user