junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.3k stars 2.38k forks source link

Can't input non ascii characters #3799

Open sledgehammer999 opened 4 months ago

sledgehammer999 commented 4 months ago

Checklist

Output of fzf --version

0.52.1 (6432f00)

OS

Shell

Problem / Steps to reproduce

Specifically I use bash from git for windows. OS: Win 10 Terminal:

  1. Windows Terminal (1.20.11271.0)
  2. mintty 3.7.0 (shipped with git for windows)

When I hit CTRL+T and try to input greek characters they appear in the prompt either transliterated to their equivalent ascii (eg α becomes a) or printed as the ? character. This happens with both terminals.

Both terminals are able to print greek characters (eg ls a folder with greek filenames) and are able to take greek input in their prompts. So the issue is with fzf's prompt.

Konfekt commented 4 months ago

With the same setup, non-ascii characters make Fzf quit; it's intricate

Konfekt commented 4 months ago

I found out that as soon as I removed the --height option from $FZF_DEFAULT_OPTS, fzf accepts non-ascii characters in Git Bash in Windows Terminal; however I could not make fzf work at all in Git bash.

Regarding the --height option, it's unfortunately set by almost all common commands, such as Ctrl-T. The following lines, say in .bash_profile, remove it wherever possible:

  export FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS//--height[=[:space:]][1-9][0-9]?/ }"
  export FZF_CTRL_T_OPTS="${FZF_CTRL_T_OPTS//--height[=[:space:]][1-9][0-9]?/ }"
  export FZF_CTRL_R_OPTS="${FZF_CTRL_R_OPTS//--height[=[:space:]][1-9][0-9]?/ }"

  export FZF_ALT_C_OPTS="${FZF_DEFAULT_OPTS} --preview='tree.com //F {} | tail +3 | head -\$LINES'"

Ideally, of course, the issue with setting --height in Fzf in Git Bash itself could be fixed.

junegunn commented 4 months ago

You can just append --no-height at the end, because the last one wins.

export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --no-height"
Konfekt commented 4 months ago

Thank you, I was not aware of it. This is more robust. Ideally, since the provided bash scripts set their own custom parameters, add a check for Git Bash, say by [ -z ${MSYSTEM+x} ] || ..., and append --no-height.

sledgehammer999 commented 4 months ago

I can confirm that --no-height works for me too. In both Windows Terminal and mintty(from git bash). BTW echo $FZF_DEFAULT_OPTS is empty so I suppose --height is the default, right?

Konfekt commented 4 months ago

Yes, you can inspect here:

https://github.com/junegunn/fzf/blob/0994d9c881f8380997b96bb0a4a7416b50bc2b0d/shell/key-bindings.bash

__fzf_defaults() {
  # $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
  # $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
  echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
  command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
  echo "${FZF_DEFAULT_OPTS-} $2"
}

__fzf_select__() {
  FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \
  FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \
cpkio commented 2 months ago

For me unability to input non-latin characters was introduced in 0.54, 0.53 works fine.

Konfekt commented 2 months ago

Did you try https://github.com/junegunn/fzf/issues/3799#issuecomment-2117739952 ?

cpkio commented 2 months ago

Now I did, with no result. Will stick to 0.53 for a while.

junegunn commented 2 months ago

If you're experiencing a change of behavior in 0.54.0, this might be the cause.

https://github.com/junegunn/fzf/commit/dca2262fe6f8d7c4a9264464e45d44e684d0e70b

See https://github.com/junegunn/fzf/issues/3847#issuecomment-2162913817

I'll look into it when I get some time.

junegunn commented 2 months ago

I can confirm that the LightRenderer for Windows written by @kelleyma49 cannot take Unicode characters.

https://github.com/junegunn/fzf/blob/2dbc874e3dfa381b2e5492c94bf4056d4a36f3f1/src/tui/light_windows.go#L58-L62

When I type in a Unicode character, it reads it as ? (63).

junegunn commented 2 months ago

Ideally, we should fix LightRenderer to support non-ASCII input, but I don't have the Windows expertise to do that, so I'm going to revert the decision I made in 0.54 to prefer LightRenderer over tcell-based renderer for now.

Related:

kelleyma49 commented 2 months ago

I believe I have a fix for reading and displaying non-ASCII input. Please see #3951