altercation / solarized

precision color scheme for multiple applications (terminal, vim, etc.) with both dark/light modes
http://ethanschoonover.com/solarized
MIT License
15.76k stars 3.52k forks source link

enable italics in iTerm2 #311

Open AprilArcus opened 9 years ago

AprilArcus commented 9 years ago

Italics are now supported in iTerm2, if the user supplies an emended terminfo file. See Enabling italic fonts in iTerm2, tmux, and vim by Alex Pierce for a detailed walkthrough.

Right now, vim-colors-solarized/colors/solarized.vim lines 137-157 employ an if/else tree to determine compatibility with italics by testing against a hard-coded list of known-compatible terminal emulators:

" Terminals that support italics
let s:terms_italic=[
            \"rxvt",
            \"gnome-terminal"
            \]
" For reference only, terminals are known to be incomptible.
" Terminals that are in neither list need to be tested.
let s:terms_noitalic=[
            \"iTerm.app",
            \"Apple_Terminal"
            \]
if has("gui_running")
    let s:terminal_italic=1 " TODO: could refactor to not require this at all
else
    let s:terminal_italic=0 " terminals will be guilty until proven compatible
    for term in s:terms_italic
        if $TERM_PROGRAM =~ term
            let s:terminal_italic=1
        endif
    endfor
endif

I think a more general approach would be to shell out to infocmp and test for a sitm entry:

if has("gui_running") || system("infocmp") =~ "sitm"
    let s:terminal_italic=1
else
    let s:terminal_italic=0
endif

would this have any negative consequences for Windows console users?

AprilArcus commented 9 years ago

infocmp isn't in POSIX, but tput is. I think this should work everywhere:

if has("gui_running") || ( has("unix") && system("tput sitm") == "\033[3m" )
    let s:terminal_italic=1
else
    let s:terminal_italic=0
endif
AprilArcus commented 9 years ago

Filed a pull request.