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