mirror of
https://github.com/cjdenio/crossword.git
synced 2026-10-03 11:06:19 +00:00
Compare commits
4
Commits
60d1bd644c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d50b572fb5 | ||
|
|
7b35f86e32 | ||
|
|
419f0ae3cf | ||
|
|
b918c5be23 |
No files matched your search
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Caleb Denio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+12
-10
@@ -341,22 +341,24 @@ func (state *State) RenderUI(w io.Writer, width int) int {
|
||||
io.WriteString(w, "\r\n")
|
||||
uiHeight += 1
|
||||
}
|
||||
fmt.Fprintf(w, "%s\r\n", state.Puzzle.Copyright)
|
||||
uiHeight += 1
|
||||
if state.Puzzle.Copyright != "" {
|
||||
fmt.Fprintf(w, "%s\r\n\r\n", state.Puzzle.Copyright)
|
||||
uiHeight += 2
|
||||
}
|
||||
|
||||
switch state.UIState {
|
||||
case StateGame:
|
||||
fmt.Fprintln(w, AnsiDimmed("\r\n[enter]/[tab]: next word | [ctrl+a]: menu | [ctrl+c]: exit"))
|
||||
uiHeight += 2
|
||||
fmt.Fprint(w, AnsiDimmed("[enter]/[tab]: next word | [ctrl+a]: menu | [ctrl+c]: exit\r\n"))
|
||||
uiHeight += 1
|
||||
case StateMenu:
|
||||
fmt.Fprintln(w, AnsiDimmed("\r\n[c]: check puzzle/word | [r]: reveal puzzle/word | [x]: clear grid | [q]: exit menu"))
|
||||
uiHeight += 2
|
||||
fmt.Fprint(w, AnsiDimmed("[c]: check puzzle/word | [r]: reveal puzzle/word | [x]: clear grid | [q]: exit menu\r\n"))
|
||||
uiHeight += 1
|
||||
case StateCheckMenu:
|
||||
fmt.Fprintln(w, AnsiDimmed("\r\n[w]: check word | [p]: check puzzle | [q]: exit menu"))
|
||||
uiHeight += 2
|
||||
fmt.Fprint(w, AnsiDimmed("[w]: check word | [p]: check puzzle | [q]: exit menu\r\n"))
|
||||
uiHeight += 1
|
||||
case StateRevealMenu:
|
||||
fmt.Fprintln(w, AnsiDimmed("\r\n[w]: reveal word | [p]: reveal puzzle | [q]: exit menu"))
|
||||
uiHeight += 2
|
||||
fmt.Fprint(w, AnsiDimmed("[w]: reveal word | [p]: reveal puzzle | [q]: exit menu\r\n"))
|
||||
uiHeight += 1
|
||||
}
|
||||
|
||||
switch state.SolveState {
|
||||
|
||||
+5
-2
@@ -63,6 +63,8 @@ func ParseIPuz(file []byte) (*Puzzle, error) {
|
||||
|
||||
puzzle := new(Puzzle)
|
||||
|
||||
puzzle.RebusCells = make(map[int]string)
|
||||
|
||||
puzzle.Title = parsed.Title
|
||||
puzzle.Author = parsed.Author
|
||||
puzzle.Copyright = parsed.Copyright
|
||||
@@ -95,12 +97,13 @@ func ParseIPuz(file []byte) (*Puzzle, error) {
|
||||
puzzle.State = state.String()
|
||||
|
||||
solution := strings.Builder{}
|
||||
for _, row := range parsed.Solution {
|
||||
for _, cell := range row {
|
||||
for y, row := range parsed.Solution {
|
||||
for x, cell := range row {
|
||||
if cell == "#" {
|
||||
solution.WriteRune('.')
|
||||
} else if len(cell) > 1 {
|
||||
solution.WriteByte(cell[0])
|
||||
puzzle.RebusCells[y*puzzle.Width+x] = cell
|
||||
puzzle.HasRebus = true
|
||||
} else if len(cell) == 1 {
|
||||
solution.WriteString(cell)
|
||||
|
||||
+29
-1
@@ -7,6 +7,8 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
@@ -123,6 +125,8 @@ func ParsePuz(file []byte) (*Puzzle, error) {
|
||||
|
||||
puzzle := new(Puzzle)
|
||||
|
||||
puzzle.RebusCells = make(map[int]string)
|
||||
|
||||
_, err = r.Seek(10, io.SeekCurrent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -217,6 +221,8 @@ func ParsePuz(file []byte) (*Puzzle, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extraBlocks := make(map[string]*ExtraBlock)
|
||||
|
||||
for {
|
||||
extra, err := readExtraBlock(buf)
|
||||
if errors.Is(err, io.EOF) {
|
||||
@@ -224,8 +230,30 @@ func ParsePuz(file []byte) (*Puzzle, error) {
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if extra.Name == "RTBL" {
|
||||
extraBlocks[extra.Name] = extra
|
||||
}
|
||||
|
||||
grbs, grbsOk := extraBlocks["GRBS"]
|
||||
trbl, trblOk := extraBlocks["RTBL"]
|
||||
if grbsOk && trblOk {
|
||||
puzzle.HasRebus = true
|
||||
rebusCellMap := make(map[int][]int)
|
||||
for i, b := range grbs.Data {
|
||||
if b > 0 {
|
||||
rebusCellMap[int(b)-1] = append(rebusCellMap[int(b)-1], i)
|
||||
}
|
||||
}
|
||||
|
||||
rebusData := regexp.MustCompile(`\s*(\d+):(\w+);\s*`).FindAllStringSubmatch(string(trbl.Data), -1)
|
||||
for _, rebus := range rebusData {
|
||||
cell, err := strconv.Atoi(rebus[1])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, c := range rebusCellMap[cell] {
|
||||
puzzle.RebusCells[c] = rebus[2]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ type Puzzle struct {
|
||||
Cells [][2]*Clue
|
||||
|
||||
HasRebus bool
|
||||
|
||||
RebusCells map[int]string
|
||||
}
|
||||
|
||||
func LoadPuzzle(r io.Reader) (*Puzzle, error) {
|
||||
|
||||
+16
-4
@@ -39,8 +39,20 @@ func main() {
|
||||
io.WriteString(s, "\x1b[?25h")
|
||||
}()
|
||||
|
||||
pty, _, _ := s.Pty() // TODO: actually handle terminal size changes
|
||||
uiHeight := state.RenderUI(s, pty.Window.Width)
|
||||
pty, winCh, isPty := s.Pty()
|
||||
if !isPty {
|
||||
return
|
||||
}
|
||||
|
||||
windowWidth := pty.Window.Width
|
||||
|
||||
uiHeight := state.RenderUI(s, windowWidth)
|
||||
|
||||
go func() {
|
||||
for window := range winCh {
|
||||
windowWidth = window.Width
|
||||
}
|
||||
}()
|
||||
|
||||
scanner := bufio.NewScanner(s)
|
||||
scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||
@@ -72,14 +84,14 @@ func main() {
|
||||
state.SelectedCell = -1
|
||||
fmt.Fprintf(s, "\r\x1b[%dA", uiHeight)
|
||||
fmt.Fprint(s, "\x1b[J")
|
||||
state.RenderUI(s, pty.Window.Width)
|
||||
state.RenderUI(s, windowWidth)
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Fprintf(s, "\r\x1b[%dA", uiHeight)
|
||||
fmt.Fprint(s, "\x1b[J")
|
||||
|
||||
uiHeight = state.RenderUI(s, pty.Window.Width)
|
||||
uiHeight = state.RenderUI(s, windowWidth)
|
||||
}
|
||||
|
||||
log.Printf("%s disconnected\n", s.RemoteAddr().String())
|
||||
|
||||
Reference in new issue
Block a user