content_image/865567.jpg
## 4 Displaying Text 

From a C programmer’s point of view, curses may sometimes look like a twisty maze of functions, all subtly different. For example, addstr() displays a string at the current cursor location in the stdscr window, while$_{mvaddstr()}$ moves to a given y,x coordinate first before displaying the string. waddstr() is just like addstr() , but allows specifying a window to use instead of using$_{stdscr}$by default. mvwaddstr() allows specifying both a window and a coordinate. 

Fortunately the Python interface hides all these details.$_{stdscr}$is a window object like any other, and methods such as addstr() accept multiple argument forms. Usually there are four different forms. 

<img src='content_image/865567.jpg'>

Attributes allow displaying text in highlighted forms such as boldface, underline, reverse code, or in color. They’ll be explained in more detail in the next subsection. 

The$_{addstr()}$ method takes a Python string or bytestring as the value to be displayed. The contents of bytestrings are sent to the terminal as-is. Strings are encoded to bytes using the value of the window’s$_{encoding}$attribute; this defaults to the default system encoding as returned by$_{locale.getpreferredencoding()}$ . 

The$_{addch()}$ methods take a character, which can be either a string of length 1, a bytestring of length 1, or an integer. 

Constants are provided for extension characters; these constants are integers greater than 255. For example, ACS_PLMINUS is a +/- symbol, and$_{ACS_ULCORNER}$ is the upper left corner of a box (handy for drawing borders). You can also use the appropriate Unicode character. 

Windows remember where the cursor was left after the last operation, so if you leave out the y,x coordinates, the string or character will be displayed wherever the last operation left off. You can also move the cursor with the move(y,x) method. Because some terminals always display a flashing cursor, you may want to ensure that the cursor is positioned in some location where it won’t be distracting; it can be confusing to have the cursor blinking at some apparently random location. 

If your application doesn’t need a blinking cursor at all, you can call$_{curs_set(False)}$ to make it invisible. For compatibility with older curses versions, there’s a$_{leaveok(bool)}$ function that’s a synonym for$_{curs_set()}$ . When bool is true, the curses library will attempt to suppress the flashing cursor, and you won’t need to worry about leaving it in odd locations. 

## 4.1 Attributes and Color 

Characters can be displayed in different ways. Status lines in a text-based application are commonly shown in reverse video, or a text viewer may need to highlight certain words. curses supports this by allowing you to specify an attribute for each cell on the screen. 

An attribute is an integer, each bit representing a different attribute. You can try to display text with multiple attribute bits set, but curses doesn’t guarantee that all the possible combinations are available, or that they’re all visually distinct. That depends on the ability of the terminal being used, so it’s safest to stick to the most commonly available attributes, listed here. 

