realh/roxterm

Odd characters printed

Closed this issue · 8 comments

ekohl commented

I just upgraded from 3.1.5-r1 (as packaged in Gentoo) to 3.9.2 with the intent of updating the version in Gentoo.

When typing in the console I see odd characters at the start of the line:

ekohl@donald ~ $ cd dev/[i^C
ekohl@donald ~ $ cd dev/puppet-foreman
0�ax
ekohl@donald ~/dev/puppet-foreman (drop-rails-repo) $ cd ~/dev
"ekohl@donald ~/dev $ cd
tionekohl@donald ~ $ cd
mandekohl@donald ~ $ ls

I'm not sure what info is useful to be able to debug this but I'd be happy to provide any.

realh commented

I've never seen it do anything like that. Are any other terminals affected, especially ones using vte (eg gnome-terminal)? And are tab and window titles affected too? Would you be able to try swapping the terminal title and command prompt in your shell? It looks as if you're using something like oh-my-zsh, which I use myself, but I'm not familiar enough with it to know how to do that.

ekohl commented

My shell is bash so I'm not using oh-my-zsh. The installed version is vte 0.58.3. I don't have any other terminals installed that depend on vte.

The interesting thing is that it appears very regularly as a normal user but it doesn't appear to show up as root. I'll see if I have anything in my bash config that might have an impact.

Edit:

And are tab and window titles affected too?

Not that I can see.

Would you be able to try swapping the terminal title and command prompt in your shell?

Reducing PS1 to \$ doesn't appear to make a difference.

ekohl commented

So I've traced this to /etc/profile.d/vte-2.91.sh which I'll paste for completeness:

# Copyright © 2006 Shaun McCance <shaunm@gnome.org>
# Copyright © 2013 Peter De Wachter <pdewacht@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Not bash or zsh?
[ -n "$BASH_VERSION" -o -n "$ZSH_VERSION" ] || return 0

# Not an interactive shell?
[[ $- == *i* ]] || return 0

# Not running under vte?
[ "${VTE_VERSION:-0}" -ge 3405 ] || return 0

__vte_urlencode() (
  # This is important to make sure string manipulation is handled
  # byte-by-byte.
  LC_ALL=C
  str="$1"
  while [ -n "$str" ]; do
    safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}"
    printf "%s" "$safe"
    str="${str#"$safe"}"
    if [ -n "$str" ]; then
      printf "%%%02X" "'$str"
      str="${str#?}"
    fi
  done
)

# Print a warning so that anyone who's added this manually to his PS1 can adapt.
# The function will be removed in a later version.
__vte_ps1() {
  echo -n "(__vte_ps1 is obsolete)"
}

__vte_osc7 () {
  printf "\033]7;file://%s%s\033\\" "${HOSTNAME:-}" "$(__vte_urlencode "${PWD}")"
}

__vte_prompt_command() {
  local command=$(HISTTIMEFORMAT= history 1 | sed 's/^ *[0-9]\+ *//')
  command="${command//;/ }"
  local pwd='~'
  [ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
  pwd="${pwd//[[:cntrl:]]}"
  printf '\033]777;notify;Command completed;%s\033\\\033]777;precmd\033\\\033]0;%s@%s:%s\033\\%s' "${command}" "${USER}" "${HOSTNAME%%.*}" "${pwd}" "$(__vte_osc7)"
}

case "$TERM" in
  xterm*|vte*)
    [ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command" && PS0=$(printf "\033]777;preexec\033\\")
    [ -n "$ZSH_VERSION"  ] && precmd_functions+=(__vte_osc7)
    ;;
esac

true

It's provided by x11-libs/vte-0.58.3. Its source is https://gitlab.gnome.org/GNOME/vte/-/blob/master/src/vte.sh.in though in my 0.58.3 version it was not a .in file yet.

Setting PROMPT_COMMAND and PS0 to an empty string in my .bashrc is now a workaround.

printf '\033]777;notify;Command completed;%s\033\\\033]777;precmd\033\\\033]0;%s@%s:%s\033\\%s' "${command}" "${USER}" "${HOSTNAME%%.*}" "${pwd}" "$(__vte_osc7)"
[...] && PS0=$(printf "\033]777;preexec\033\\")

FYI: These are added by a downstream patch, not part of official VTE.

realh commented

@ekohl Please could you test in some more terminals, both vte and non-vte. I don't think this problem is likely to be roxterm-specific because getting output from the shell/child process onto the screen is done internally by vte. But if roxterm 3.1 was OK with the same version of vte it could be that I'm currently initialising/configuring something in vte incorrectly.

ekohl commented

FYI: These are added by a downstream patch, not part of official VTE.

This was key. If I emerge x11-libs/vte with USE="vanilla", the patch is not applied and it works as expected.

https://github.com/gentoo/gentoo/blob/67370197cd4b6dc594bb6a5b28f2a9375ca0629e/x11-libs/vte/vte-0.58.3.ebuild#L19 is the patch in question, or https://dev.gentoo.org/~leio/distfiles/vte-0.58.3-command-notify.patch.xz. Later in the same build they state it's derived from https://src.fedoraproject.org/rpms/vte291/raw/f31/f/vte291-cntnr-precmd-preexec-scroll.patch

ekohl commented

@ekohl Please could you test in some more terminals, both vte and non-vte.

I can have a look at that later but can't promise I'll get to it before the weekend.

ekohl commented

As it turns out, I don't have time to look into why the Gentoo specific patch breaks things. For now I've ensured that VTE is compiled without the custom patch and had no issues in the past months. If someone does have time to look into this, they should feel free to but I'm going to close this issue for now.