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")
|
io.WriteString(w, "\r\n")
|
||||||
uiHeight += 1
|
uiHeight += 1
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "%s\r\n", state.Puzzle.Copyright)
|
if state.Puzzle.Copyright != "" {
|
||||||
uiHeight += 1
|
fmt.Fprintf(w, "%s\r\n\r\n", state.Puzzle.Copyright)
|
||||||
|
uiHeight += 2
|
||||||
|
}
|
||||||
|
|
||||||
switch state.UIState {
|
switch state.UIState {
|
||||||
case StateGame:
|
case StateGame:
|
||||||
fmt.Fprintln(w, AnsiDimmed("\r\n[enter]/[tab]: next word | [ctrl+a]: menu | [ctrl+c]: exit"))
|
fmt.Fprint(w, AnsiDimmed("[enter]/[tab]: next word | [ctrl+a]: menu | [ctrl+c]: exit\r\n"))
|
||||||
uiHeight += 2
|
uiHeight += 1
|
||||||
case StateMenu:
|
case StateMenu:
|
||||||
fmt.Fprintln(w, AnsiDimmed("\r\n[c]: check puzzle/word | [r]: reveal puzzle/word | [x]: clear grid | [q]: exit menu"))
|
fmt.Fprint(w, AnsiDimmed("[c]: check puzzle/word | [r]: reveal puzzle/word | [x]: clear grid | [q]: exit menu\r\n"))
|
||||||
uiHeight += 2
|
uiHeight += 1
|
||||||
case StateCheckMenu:
|
case StateCheckMenu:
|
||||||
fmt.Fprintln(w, AnsiDimmed("\r\n[w]: check word | [p]: check puzzle | [q]: exit menu"))
|
fmt.Fprint(w, AnsiDimmed("[w]: check word | [p]: check puzzle | [q]: exit menu\r\n"))
|
||||||
uiHeight += 2
|
uiHeight += 1
|
||||||
case StateRevealMenu:
|
case StateRevealMenu:
|
||||||
fmt.Fprintln(w, AnsiDimmed("\r\n[w]: reveal word | [p]: reveal puzzle | [q]: exit menu"))
|
fmt.Fprint(w, AnsiDimmed("[w]: reveal word | [p]: reveal puzzle | [q]: exit menu\r\n"))
|
||||||
uiHeight += 2
|
uiHeight += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
switch state.SolveState {
|
switch state.SolveState {
|
||||||
|
|||||||
+5
-2
@@ -63,6 +63,8 @@ func ParseIPuz(file []byte) (*Puzzle, error) {
|
|||||||
|
|
||||||
puzzle := new(Puzzle)
|
puzzle := new(Puzzle)
|
||||||
|
|
||||||
|
puzzle.RebusCells = make(map[int]string)
|
||||||
|
|
||||||
puzzle.Title = parsed.Title
|
puzzle.Title = parsed.Title
|
||||||
puzzle.Author = parsed.Author
|
puzzle.Author = parsed.Author
|
||||||
puzzle.Copyright = parsed.Copyright
|
puzzle.Copyright = parsed.Copyright
|
||||||
@@ -95,12 +97,13 @@ func ParseIPuz(file []byte) (*Puzzle, error) {
|
|||||||
puzzle.State = state.String()
|
puzzle.State = state.String()
|
||||||
|
|
||||||
solution := strings.Builder{}
|
solution := strings.Builder{}
|
||||||
for _, row := range parsed.Solution {
|
for y, row := range parsed.Solution {
|
||||||
for _, cell := range row {
|
for x, cell := range row {
|
||||||
if cell == "#" {
|
if cell == "#" {
|
||||||
solution.WriteRune('.')
|
solution.WriteRune('.')
|
||||||
} else if len(cell) > 1 {
|
} else if len(cell) > 1 {
|
||||||
solution.WriteByte(cell[0])
|
solution.WriteByte(cell[0])
|
||||||
|
puzzle.RebusCells[y*puzzle.Width+x] = cell
|
||||||
puzzle.HasRebus = true
|
puzzle.HasRebus = true
|
||||||
} else if len(cell) == 1 {
|
} else if len(cell) == 1 {
|
||||||
solution.WriteString(cell)
|
solution.WriteString(cell)
|
||||||
|
|||||||
+30
-2
@@ -7,6 +7,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/text/encoding/charmap"
|
"golang.org/x/text/encoding/charmap"
|
||||||
@@ -123,6 +125,8 @@ func ParsePuz(file []byte) (*Puzzle, error) {
|
|||||||
|
|
||||||
puzzle := new(Puzzle)
|
puzzle := new(Puzzle)
|
||||||
|
|
||||||
|
puzzle.RebusCells = make(map[int]string)
|
||||||
|
|
||||||
_, err = r.Seek(10, io.SeekCurrent)
|
_, err = r.Seek(10, io.SeekCurrent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -217,6 +221,8 @@ func ParsePuz(file []byte) (*Puzzle, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extraBlocks := make(map[string]*ExtraBlock)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
extra, err := readExtraBlock(buf)
|
extra, err := readExtraBlock(buf)
|
||||||
if errors.Is(err, io.EOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
@@ -224,8 +230,30 @@ func ParsePuz(file []byte) (*Puzzle, error) {
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if extra.Name == "RTBL" {
|
extraBlocks[extra.Name] = extra
|
||||||
puzzle.HasRebus = true
|
}
|
||||||
|
|
||||||
|
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
|
Cells [][2]*Clue
|
||||||
|
|
||||||
HasRebus bool
|
HasRebus bool
|
||||||
|
|
||||||
|
RebusCells map[int]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadPuzzle(r io.Reader) (*Puzzle, error) {
|
func LoadPuzzle(r io.Reader) (*Puzzle, error) {
|
||||||
|
|||||||
+16
-4
@@ -39,8 +39,20 @@ func main() {
|
|||||||
io.WriteString(s, "\x1b[?25h")
|
io.WriteString(s, "\x1b[?25h")
|
||||||
}()
|
}()
|
||||||
|
|
||||||
pty, _, _ := s.Pty() // TODO: actually handle terminal size changes
|
pty, winCh, isPty := s.Pty()
|
||||||
uiHeight := state.RenderUI(s, pty.Window.Width)
|
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 := bufio.NewScanner(s)
|
||||||
scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||||
@@ -72,14 +84,14 @@ func main() {
|
|||||||
state.SelectedCell = -1
|
state.SelectedCell = -1
|
||||||
fmt.Fprintf(s, "\r\x1b[%dA", uiHeight)
|
fmt.Fprintf(s, "\r\x1b[%dA", uiHeight)
|
||||||
fmt.Fprint(s, "\x1b[J")
|
fmt.Fprint(s, "\x1b[J")
|
||||||
state.RenderUI(s, pty.Window.Width)
|
state.RenderUI(s, windowWidth)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(s, "\r\x1b[%dA", uiHeight)
|
fmt.Fprintf(s, "\r\x1b[%dA", uiHeight)
|
||||||
fmt.Fprint(s, "\x1b[J")
|
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())
|
log.Printf("%s disconnected\n", s.RemoteAddr().String())
|
||||||
|
|||||||
Reference in new issue
Block a user