Next: , Previous: <code>addstr</code> class of functions, Up: Output functions


4.6.3 A simple addstr example

     #!/usr/bin/guile
     !#
     
     (use-modules (ncurses curses)
                  (srfi srfi-1))
     
     (define stdscr (initscr))
     
     (let* ((mesg "Just a string")
            (len (string-length mesg))
            (siz (getmaxyx stdscr))
            (row (first siz))
            (col (second siz)))
     
       ;; Print the message centered in the window
       (move stdscr
             (round (/ row 2))
             (round (/ (- col len) 2)))
       (addstr stdscr mesg)
     
       ;; Use "format" to generate a message, and then print it
       (addstr stdscr
               (format #f "This screen has ~a rows and ~a columns ~%"
                       row col)
               #:y (- row 2)
               #:x 0)
     
       (addstr stdscr "Try resizing your window (if possible) ")
       (addstr stdscr "and then run this program again")
       (refresh stdscr)
     
       ;; Wait for a keypress
       (getch stdscr)
       (endwin))

The above program demonstrates how easy it is to combine addstr and move to print at a specific location on the screen. It also shows how to use the equivalent key parameters #:y and #:x. They do exactly the same thing. It also shows how (format #f ...) can be used in conjunction with addstr to do formatted output.

The example introduces the new function getmaxyx. It gives the number of columns and the number of rows in a given window. getmaxyx does this by returning a list of two elements, y and x.