Previous: , Up: Attributes   [Contents][Index]


4.8.4 chgat function

The function chgat, which is short for change attributes, can be used to set attributes for a group of characters already on the screen without moving the cursor. It changes the attributes of a given number of characters starting at the current cursor location.

You can pass it -1 as the character count to update until the end of the current line.

The following example changes the attributes of characters from the current position to the end of the line to reverse video on a window named win1.

(chgat win1 -1 A_REVERSE 0)

The are optional key parameters #:y and #:x can be used with chgat.

The following example will print a string on the screen. Then it will set the first 5 characters of the string to blink and change color to cyan.

#!/usr/bin/guile
!#

(use-modules (ncurses curses))

(define stdscr (initscr))

;; Prep the color functions
(start-color!)

;; Label cyan on black as color-pair #1
(init-pair! 1 COLOR_CYAN COLOR_BLACK)

(addstr stdscr "Blink Don't Blink")

(chgat   stdscr              ; window
         5                   ; num of chars
         A_BLINK             ; attributes
         1                   ; use color pair #1
         #:y 0               ; start y
         #:x 0)              ; start x

;; Move the cursor out of the way
(move stdscr 1 0)

(refresh stdscr)
(getch stdscr)
(endwin)

This example also introduces us to the color world of curses. Colors will be explained in detail later. Use 0 for white on black.

Now wait... Did you try running this little script? Did it work? Blinking is one of those features that may not be implemented on your terminal. As of the moment of this writing, Gnome terminal doesn’t do blinking. The standard xterm does do blinking, but, it doesn’t blink at the location of the cursor.


Previous: , Up: Attributes   [Contents][Index]