Powerlevel9k / powerlevel9k

Powerlevel9k was a tool for building a beautiful and highly functional CLI, customized for you. P9k had a substantial impact on CLI UX, and its legacy is now continued by P10k.
https://github.com/romkatv/powerlevel10k
MIT License
13.46k stars 947 forks source link

fonts work in intellij terminal and not iterm2 #945

Closed Kristaphonie-zz closed 6 years ago

Kristaphonie-zz commented 6 years ago

For some odd reason, the terminal in intellij is displaying correctly, but my iterm2 is not.

Click on them for bigger size Intellij: screen shot 2018-08-06 at 10 35 56 am

Iterm2:

screen shot 2018-08-06 at 11 17 09 am

The intellij terminal is showing weird line endings, but I saw there were fixes for that in the troubleshooting guide, and honestly is not a real issue as it still looks better then default terminal.

I've been going through multiple different issues on github, and other tutorial articles, and the github installation instructions multiple times, and it seems to have worked.. for intellij. So the config seems to be okay, or else intellij would be having a hard time too I assume.

I've tried the font installation instructions multiple times, and I've tried going through the iterm2 preferences and tinkered around a bit, but nothing seems to do much. I'm using oh-my-zsh. I've tried playing around with individual settings in my .zshrc file, regarding the powrlevel9k theme, mostly parameters I've found in other peoples configs. Now I'm just back to good ol vanilla parameters, theme and font parameters only.

Zsh version: zsh 5.5.1 (x86_64-apple-darwin17.5.0) Cloned the powerlevel9k repo Using v0.6.5 Iterm2 I'm using the awesome-fontconfig

font-issues.zsh

#!/usr/bin/env zsh
#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8

# Taken from NeoFetch (slightly modified)
get_term() {
    local term
    # If function was run, stop here.
    #((term_run == 1)) && return

    # Workaround for macOS systems that
    # don't support the block below.
    case "$TERM_PROGRAM" in
        "iTerm.app") term="iTerm2" ;;
        "Terminal.app") term="Apple Terminal" ;;
        "Hyper") term="HyperTerm" ;;
        *) term="${TERM_PROGRAM/\.app}" ;;
    esac

    # Check $PPID for terminal emulator.
    while [[ -z "$term" ]]; do
        parent="$(get_ppid "$parent")"
        name="$(get_process_name "$parent")"

        case "${name// }" in
            "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su"*) ;;
            "login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;;
            "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) break ;;
            "gnome-terminal-") term="gnome-terminal" ;;
            *) term="${name##*/}" ;;
        esac
    done

    # Log that the function was run.
    #term_run=1

    echo "${term}"
}

get_term_font() {
    local term="${1}"
    #((term_run != 1)) && get_term

    case "$term" in
        "alacritty"*)
            term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${XDG_CONFIG_HOME}/alacritty/alacritty.yml")"
            term_font="${term_font/*family:}"
            term_font="${term_font/$'\n'*}"
            term_font="${term_font/\#*}"
        ;;

        "Apple_Terminal")
            term_font="$(osascript -e 'tell application "Terminal" to font name of window frontmost')"
        ;;
        "iTerm2")
            # Unfortunately the profile name is not unique, but it seems to be the only thing
            # that identifies an active profile. There is the "id of current session of current window"
            # thou, but that does not match to a guid in the plist.
            # So, be warned! Collisions may occur!
            # See: https://groups.google.com/forum/#!topic/iterm2-discuss/0tO3xZ4Zlwg
            # and: https://gitlab.com/gnachman/iterm2/issues/5586
            local currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window')

            # Warning: Dynamic profiles are not taken into account here!
            # https://www.iterm2.com/documentation-dynamic-profiles.html

            local nonAsciiFont

            # Count Guids in "New Bookmarks"; they should be unique
            local profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep -c "Guid")
            for idx in $(seq 0 "${profilesCount}"); do
                local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null)
                if [[ "${profileName}" == "${currentProfileName}" ]]; then
                    # "Normal Font"
                    term_font=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)

                    # Font for non-ascii characters
                    # Only check for a different non-ascii font, if the user checked
                    # the "use a different font for non-ascii text" switch.
                    local useDifferentFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)
                    if [[ "$useDifferentFont" == "true" ]]; then
                        local nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)
                        if [[ "$term_font" != "$nonAsciiFont" ]]; then
                            term_font="$term_font (normal) / $nonAsciiFont (non-ascii)"
                        fi
                    fi
                fi
            done
        ;;

        "deepin-terminal"*)
            term_font="$(awk -F '=' '/font=/ {a=$2} /font_size/ {b=$2} END{print a " " b}' "${XDG_CONFIG_HOME}/deepin/deepin-terminal/config.conf")"
        ;;

        "Hyper"*)
            term_font="$(awk -F "," '/fontFamily/ {a=$1} END{print a}' "${HOME}/.hyper.js" | awk -F "'" '{a=$2} END{print a}')"
        ;;

        "konsole"*)
            # Get Process ID of current konsole window / tab
            child="$(get_ppid "$$")"

            konsole_instances=($(qdbus | grep 'org.kde.konsole'))

            for i in "${konsole_instances[@]}"; do
                konsole_sessions=($(qdbus "${i}" | grep '/Sessions/'))
                for session in "${konsole_sessions[@]}"; do
                    if ((child == "$(qdbus "${i}" "${session}" processId)")); then
                        profile="$(qdbus "${i}" "${session}" environment | awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')"
                        break
                    fi
                done
                [[ "$profile" ]] && break
            done

            # We could have two profile files for the same profile name, take first match
            profile_filename="$(grep -l "Name=${profile}" "${HOME}"/.local/share/konsole/*.profile)"
            profile_filename="${profile_filename/$'\n'*}"
            [[ "$profile_filename" ]] && term_font="$(awk -F '=|,' '/Font=/ {print $2 " " $3}' "$profile_filename")"
        ;;

        "mintty")
            term_font="$(awk -F '=' '!/^($|#)/ && /Font/ {printf $2; exit}' "${HOME}/.minttyrc")"
        ;;

        "pantheon"*)
            term_font="$(gsettings get org.pantheon.terminal.settings font)"
            [[ -z "${term_font//\'}" ]] && term_font="$(gsettings get org.gnome.desktop.interface monospace-font-name)"
            term_font="$(trim_quotes "$term_font")"
        ;;

        "sakura"*)
            term_font="$(awk -F '=' '/^font=/ {a=$2} END{print a}' "${XDG_CONFIG_HOME}/sakura/sakura.conf")"
        ;;

        "terminology")
            term_font="$(strings "${XDG_CONFIG_HOME}/terminology/config/standard/base.cfg" | awk '/^font\.name$/{print a}{a=$0}')"
            term_font="${term_font/.pcf}"
            term_font="${term_font/:*}"
        ;;

        "termite")
            [[ -f "${XDG_CONFIG_HOME}/termite/config" ]] && termite_config="${XDG_CONFIG_HOME}/termite/config"
            term_font="$(awk -F '= ' '/\[options\]/ {opt=1} /^font/ {if(opt==1) a=$2; opt=0} END{print a}' "/etc/xdg/termite/config" "$termite_config")"
        ;;

        "urxvt" | "urxvtd" | "rxvt-unicode" | "xterm")
            term_font="$(grep -i -F "${term/d}*font" < <(xrdb -query))"
            term_font="${term_font/*font:}"
            term_font="$(trim "$term_font")"

            # Xresources has two different font formats, this checks which
            # one is in use and formats it accordingly.
            case "$term_font" in
                *"xft:"*)
                    term_font="${term_font/xft:}"
                    term_font="${term_font/:*}"
                ;;

                "-"*) term_font="$(awk -F '\\-' '{printf $3}' <<< "$term_font")" ;;
            esac
        ;;

        "xfce4-terminal")
            term_font="$(awk -F '=' '/^FontName/ {a=$2} END{print a}' "${XDG_CONFIG_HOME}/xfce4/terminal/terminalrc")"
        ;;
    esac

    echo "${term_font}"
}

local currentTerminal=$(get_term)
local currentFont=$(get_term_font "${currentTerminal}")
print -P "===== Font debugging ====="
print -P "You are using %F{blue}${currentTerminal}%f with Font %F{blue}${currentFont}%f\n"

if [[ $(echo "${currentFont}" | grep -c -E "Powerline|Awesome|Nerd") -eq 0 ]]; then
    print -P "%F{yellow}WARNING%f It does not seem like you use an Powerline-enabled or Awesome Terminal Font!"
    print -P "Please make sure that your font settings are correct!"
else
    print -P "Your font settings seem to be all right. If you still have issues,"
    print -P "it is more likely to be a font issue than a Powerlevel9k related one."
fi

the output of get_icon_names shows these are ?: POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR:  POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR:  POWERLEVEL9K_ANDROID_ICON: 

Which might explain why iterm is not showing the little triangle end pieces, but I don't know why intellij shows it perfectly.

dritter commented 6 years ago

Hi @Kristaphonie !

That sounds like a lot of questions.. So, first of all, intellij has a builtin terminal that comes with its own fonts AFAIK. That "weird" line endings you see are probably the powerline separators.. But they seem too small for your font size.

But let's focus on iterm2. That question marks you see are the powerline symbols as well. You need to set a powerline enabled font in your settings. And are you sure you have a working fontconfig setup? This is way more complicated than to use a pre-patched font..

Last but not least, you need to set the right POWERLEVEL9K_MODE at the top of your config.

I hope that helps.

Kristaphonie-zz commented 6 years ago

Hello @dritter

So I've done both of those things, here's what I'm setting in my .zshrc file:

POWERLEVEL9K_MODE="awesome-fontconfig"
ZSH_THEME="powerlevel9k/powerlevel9k"

If you click on the images, the iterm terminal one displays all the icons, except for the line ending triangles. And it seems because the seperator fonts are invalid (as shown at the bottom of my original post)? But the rest of the fonts work fine.

And I'm not too worried about the intellij separators being off more then I'm confused about why the fonts are working perfectly in intellij terminals. It definitely comes with it's own fonts, but the POWERLEVEL9k fonts and mappings probably don't come with intellij stock I assume.

I have the font selected:

screen shot 2018-08-06 at 2 48 11 pm

which is the font that I used Xcode to add the 4 other fonts to.

It's literally only the segment fonts that aren't showing up. So I think that's the powerline fonts, but they show up in fontbook:

screen shot 2018-08-06 at 3 02 06 pm

Which some of them are showing up.

dritter commented 6 years ago

The intellij Terminal Emulator fires up a Shell, which then uses your configuration. This means it reads in your default ~/.zshrc. This is like iTerm. The difference is how it displays the things. So in each Terminal Emulator you can change Colors, Fonts, etc. (well, colors being a bit special).

The other thing is that your FontBook App is not the same as fontconfig, which is a different program. It won't be enough to put fonts in FontBook. If you prefer that style, you should install a pre-patched font that already has all icons included. The downside is that you have only a limited set of font available (but even that can be pretty much, if you look at the nerdfonts repo (caveat: if you use nerdfonts, you need to change POWERLEVEL9K_MODE). If you prefer to continue to use awesome-fontconfig, I recommend you have a look in the installation instructions to make sure everything is set up correctly.

Kristaphonie-zz commented 6 years ago

Okay fixed it. I missed the step to source the individual fonts in .zshrc. Which is weird because the other icons are working. But now I just have to fix the small visual issues on it, which the troubleshooting guide fixes I believe.

Thanks @dritter. I appreciate you helping me work through a non-issue. :)

dritter commented 6 years ago

Great to hear @Kristaphonie

If you source the fonts, your P9K mode should be awesome-mapped-fontconfig, and you should source the fonts before you source P9K. That way the codepoints for the glyphs should be more stable, because we then use the glyph-variables internally.

bhilburn commented 6 years ago

Glad to hear everything is up and running!

@Kristaphonie - Any chance you have thoughts on #831?