I am using urwid to design a curses ui. I can use display attributes to show text bold, underlined, or standout. Is it possible to use italics?
In theory, yes.
In practice: not yet.
Basically, curses uses the so-called ‘ANSI escape sequences’ from ECMA-48 to do cursor movement, colours or anything that is not pure, linear text output. (It really is more convoluted than that, cf. terminfo, but that’s what it eventually boils down to.)
Colours, bold text and so on are specified as part of the SGR (‘Select Graphic Rendition’) command: CSI $n m
(with CSI
being the ‘Control Sequence Introducer’ ^[[
, that is ESC
+[
). Amongst a baffling array of stuff bordering on the bizarre (There’s even support for blackletter! On the console!), there is a control sequence for italic text: ^[[3m
to enable, ^[[23m
to disable.
Wikipedia has a list of SGR commands. However, most of the more… esoteric sequences are ‘hardly ever supported’. Bold and standout are almost universally supported, underlined is common. While italic seems to be gaining traction, many (?) terminal emulators still don’t support it—which might be a concern if your program needs to function in a heterogeneous environment. And better not place any bets on blackletter support coming anytime soon.
Right now, xterm, urxvt, and st do support it; PuTTy does not.
You can try out for yourself if your terminal would support it. You have to use Ctrl+V+Esc to get a ‘real’ escape character instead of ^[
, which is merely a notational shorthand.
print 'plain text ^[[3m italic text ^[[0m plain text'
ncurses already seems to support italic text. Urwid, however, does not yet (as of version 1.3.0). I’ve looked through the source code (the interesting bits are display_common.py
, curses_display.py
and raw_display.py
). I guess it shouldn’t be too difficult to patch in support for italic text, but as an Urwid beginner myself that’s out of reach for me right now.