note + fix bug

This commit is contained in:
cjdenio committed 2026-10-03 10:46:20 -06:00
1 parent d50b572fb5
commit 6242535184
4 files changed
+28 -3

No files matched your search

+23 -1
View File
@@ -40,6 +40,7 @@ type State struct {
SolveState SolveState
CheckState []rune
UIState UIState
NoteVisible bool
}
func RenderWithLineWrap(s string, width int) (out string, lines int) {
@@ -327,8 +328,17 @@ func (state *State) RenderUI(w io.Writer, width int) int {
uiHeight += 2
fmt.Fprintf(w, "AUTHOR: %s\r\n", state.Puzzle.Author)
uiHeight += 1
if state.Puzzle.Note != "" && state.NoteVisible {
note, noteLines := RenderWithLineWrap(state.Puzzle.Note, min(width, 60))
fmt.Fprintf(w, "\r\n%s\r\n", AnsiDimmed(note))
uiHeight += noteLines + 2
}
fmt.Fprint(w, state.RenderPuzzle()+"\r\n")
uiHeight += state.Puzzle.Height + 3
if state.SelectedClue != nil {
directionStr := "down"
if state.SelectedClue.Direction == puz.DirectionAcross {
@@ -348,7 +358,12 @@ func (state *State) RenderUI(w io.Writer, width int) int {
switch state.UIState {
case StateGame:
fmt.Fprint(w, AnsiDimmed("[enter]/[tab]: next word | [ctrl+a]: menu | [ctrl+c]: exit\r\n"))
line := "[enter]/[tab]: next word | [ctrl+a]: menu | [ctrl+c]: exit"
if state.Puzzle.Note != "" {
line += " | [ctrl+n]: toggle note"
}
line += " | [ctrl+c]: exit\r\n"
fmt.Fprint(w, AnsiDimmed(line))
uiHeight += 1
case StateMenu:
fmt.Fprint(w, AnsiDimmed("[c]: check puzzle/word | [r]: reveal puzzle/word | [x]: clear grid | [q]: exit menu\r\n"))
@@ -586,6 +601,11 @@ func (state *State) HandleInput(buffer []byte) (exited bool) {
return false
}
if buffer[0] == '\x0E' {
state.NoteVisible = !state.NoteVisible
return false
}
if buffer[0] == ' ' {
state.SwitchDirections()
}
@@ -628,10 +648,12 @@ func (state *State) HandleInput(buffer []byte) (exited bool) {
// is there a filled cell underneath the cursor?
if state.PuzzleState[state.SelectedCell] != '-' {
state.PuzzleState[state.SelectedCell] = '-'
state.CheckState[state.SelectedCell] = 0x00
} else {
i := slices.Index(state.SelectedClue.Cells, state.SelectedCell)
if i > 0 {
state.PuzzleState[state.SelectedClue.Cells[i-1]] = '-' // clear the previous cell
state.CheckState[state.SelectedClue.Cells[i-1]] = 0x00
state.SelectedCell = state.SelectedClue.Cells[i-1]
}
}
+2
View File
@@ -21,6 +21,7 @@ type iPuzFile struct {
Title string `json:"title"`
Author string `json:"author"`
Copyright string `json:"copyright"`
Notes string `json:"notes"`
Puzzle [][]any `json:"puzzle"`
Solution [][]string `json:"solution"`
Dimensions iPuzDimensions `json:"dimensions"`
@@ -68,6 +69,7 @@ func ParseIPuz(file []byte) (*Puzzle, error) {
puzzle.Title = parsed.Title
puzzle.Author = parsed.Author
puzzle.Copyright = parsed.Copyright
puzzle.Note = parsed.Notes
puzzle.Width = parsed.Dimensions.Width
puzzle.Height = parsed.Dimensions.Height
+2 -2
View File
@@ -215,11 +215,11 @@ func ParsePuz(file []byte) (*Puzzle, error) {
clues = append(clues, clue)
}
// read the "note" field, currently unused
_, err = readText(buf, string(version[0]))
note, err := readText(buf, string(version[0]))
if err != nil {
return nil, err
}
puzzle.Note = note
extraBlocks := make(map[string]*ExtraBlock)
+1
View File
@@ -29,6 +29,7 @@ type Puzzle struct {
Title string
Author string
Copyright string
Note string
Solution string
State string