
On Fri, Oct 22, 2010 at 11:18 PM, Anonymous Void
But since I've never seen how the HSCurses functions really integrate together, or any tutorials/examples (besides hsFishEx), I fear toying with it is going to be annoying until I figure it out on my own, especially since I'm already doing a project for someone... So, I was wondering if anyone would be kind enough to point me to (or write me) a basic example of how HSCurses works, maybe w/ some very simple example of interactivity (e.g. getch processing, screen refresh, ..) support. Also, maybe warn me of some of the common pitfalls and differences in hscurses vs ncurses in other languages.
UI.HSCurses.Curses follows ncurses quite closely so you can get pretty far reading the NCurses Programming HOWTO: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ .Don't forget to have the ncurses man pages handy - usually you'll just need to lowercase the name of a HSCurses function to get the name of the same function in ncurses. If you're going to be using colours or styles (bold, underline, etc), do take a look at CursesHelper too - its API documentation is somewhat better than Curses's. You could also try looking at the ContactManager program in hscurses's example directory. Just to get you started, though, here's a trivial HSCurses program to exhibit simple interaction (a walking '@'): module Main where import UI.HSCurses.Curses -- | Useful for transforming a Char to a ChType. Not sure if this is safe outside of the 7-bit ASCII range. castEnum = toEnum . fromEnum -- note that curses positions are (y, x) coordinates, with (0, 0) being the upmost leftmost position moveAbout pY pX = do erase -- clear curses's virtual screen but don't force a redraw mvAddCh pY pX (castEnum '@') -- place a character in curses's virtual screen refresh -- copy the virtual screen to the terminal c <- getCh case c of KeyUp -> moveAbout (pY - 1) pX KeyDown -> moveAbout (pY + 1) pX KeyLeft -> moveAbout pY (pX - 1) KeyRight -> moveAbout pY (pX + 1) _ -> return () main = do initCurses keypad stdScr True -- make the cursor keys usable echo False -- disable terminal echo cursSet CursorInvisible (sizeY, sizeX) <- scrSize moveAbout (sizeY `div` 2) (sizeX `div` 2) endWin