X-Git-Url: https://git.sommitrealweird.co.uk/curses-crossword.git/blobdiff_plain/82188af739361dad2bc9b52eef50d14f9f443da3..6a59f5348fa5b60eaac7b115fb3ec89032a04a11:/curses_crossword.py diff --git a/curses_crossword.py b/curses_crossword.py index 7564376..d18a8d7 100755 --- a/curses_crossword.py +++ b/curses_crossword.py @@ -3,6 +3,22 @@ Play a crossword puzzle in a curses grid. Takes a command line argument of the crossword puzzle file. """ +# curses_crossword.py - play crosswords in a terminal +# Copyright (C) 2009 Brett Parker +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import curses import curses.ascii @@ -203,21 +219,32 @@ def crossword(stdscr, crossworddata): curx += 4 curx -= 1 stdscr.addch(cury, curx, curses.ACS_LRCORNER) - # draw the clues in + # draw the clues in (in their own pad) + cluespad = curses.newpad( \ + len(crossword["across"].keys()) \ + + len(crossword["down"].keys()) \ + + 3, stdscr.getmaxyx()[1]) cury = (len(crossword["grid"]) * 2) + 1 curx = 0 - stdscr.addstr(cury, curx, "Across") + padtlx = curx + padtly = cury + + (padbry, padbrx) = stdscr.getmaxyx() + if padbry > cluespad.getmaxyx()[0] + padtly: + padbry = cluespad.getmaxyx()[0] + padtly + cury = 0 + cluespad.addstr(cury, curx, "Across") cury += 1 for cluenumber in crossword["across"].keys(): - stdscr.addstr(cury, curx, "%3s: %s" \ + cluespad.addstr(cury, curx, "%3s: %s" \ %(str(cluenumber), crossword["across"][cluenumber])) cury += 1 cury += 1 - stdscr.addstr(cury, curx, "Down") + cluespad.addstr(cury, curx, "Down") cury += 1 for cluenumber in crossword["down"].keys(): - stdscr.addstr(cury, curx, "%3s: %s" \ + cluespad.addstr(cury, curx, "%3s: %s" \ %(str(cluenumber), crossword["down"][cluenumber])) cury += 1 @@ -231,11 +258,26 @@ def crossword(stdscr, crossworddata): gridx += 1 stdscr.move(cury, curx) + cluescury = 0 + + cluespad.refresh(cluescury, 0, padtly, padtlx, padbry - 1, padbrx - 1) + cluespad.overlay(stdscr, cluescury, 0, padtly, padtlx, padbry - 1, padbrx - 1) + while 1: inch = stdscr.getch() if inch == curses.ascii.ESC: break + if inch == curses.KEY_NPAGE: + if cluescury < cluespad.getmaxyx()[0] - (padbry - padtly): + cluescury += 1 + cluespad.refresh(cluescury, 0, padtly, padtlx, padbry - 1, padbrx - 1) + stdscr.refresh() + if inch == curses.KEY_PPAGE: + if cluescury > 0: + cluescury -= 1 + cluespad.refresh(cluescury, 0, padtly, padtlx, padbry - 1, padbrx - 1) + stdscr.refresh() if inch == curses.KEY_RIGHT: if gridx < (len(crossword["grid"][0]) - 1): gridx += 1