Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code echo'ed when running a command quickly #100

Open
0neGal opened this issue Apr 24, 2021 · 7 comments
Open

Code echo'ed when running a command quickly #100

0neGal opened this issue Apr 24, 2021 · 7 comments

Comments

@0neGal
Copy link

0neGal commented Apr 24, 2021

ble version: 0.4.0-devel3+0506df2
Bash version: 5.1.4(1)-release

For some reason when running certain commands right after or during startup a long piece of code is echo'ed out. From the process title for map in vi-insert vi-command emacs; I can presume this has something to do with me having vimode enabled.

This is the result of opening fzf:

$ fzf
[2]   Done                    for map in vi-insert vi-command emacs;
do
    local cache=$_ble_base_cache/decode.readline.$_ble_bash.$map.txt; if ! [[ -s $cache && $cache -nt $_ble_base/ble.sh ]]; then
        INPUTRC=/dev/null "$BASH" --noprofile --norc -i -c "builtin bind -m $map -p" | LC_ALL= LC_CTYPE=C ble/bin/sed '/^#/d;s/"\\M-/"\\e/' >| $cache.part && ble/bin/mv "$cache.part" "$cache" || continue;
    fi; ble/util/print __CLEAR__; ble/util/print KEYMAP="$map"; ble/util/print __BIND0__; ble/bin/cat "$cache"; if ((_ble_bash>=40300)); then
        ble/util/print __BINDX__; builtin bind -m "$map" -X;
    fi; ble/util/print __BINDS__; builtin bind -m "$map" -s; ble/util/print __BINDP__; builtin bind -m "$map" -p; ble/util/print __PRINT__;
done | LC_ALL= LC_CTYPE=C ble/bin/awk -v q="$q" -v _ble_bash="$_ble_bash" '
    function keymap_register(key, val, type) {
      if (!haskey[key]) {
        keys[nkey++] = key;
        haskey[key] = 1;
      }
      keymap[key] = val;
      keymap_type[key] = type;
    }
    function keymap_clear(_, i, key) {
      for(i = 0; i < nkey; i++) {
        key = keys[i];
        delete keymap[key];
        delete keymap_type[key];
        delete keymap0[key];
        haskey[key] = 0;
      }
      nkey = 0;
    }
    function keymap_print(_, i, key, type, value, text, line) {
      for (i = 0; i < nkey; i++) {
        key = keys[i];
        type = keymap_type[key];
        value = keymap[key];
        if (type == "" && value == keymap0[key]) continue;
        text = key ": " value;
        gsub(/'$q'/, q "\\" q q, text);
        line = "bind";
        if (KEYMAP != "") line = line " -m " KEYMAP;
        if (type == "x") line = line " -x";
        line = line " " q text q;
        print line;
      }
    }
    /^__BIND0__$/ { mode = 0; next; }
    /^__BINDX__$/ { mode = 1; next; }
    /^__BINDS__$/ { mode = 2; next; }
    /^__BINDP__$/ { mode = 3; next; }
    /^__CLEAR__$/ { keymap_clear(); next; }
    /^__PRINT__$/ { keymap_print(); next; }
    sub(/^KEYMAP=/, "") { KEYMAP = $0; }
    /ble-decode\/.hook / { next; }
    function workaround_bashbug(keyseq, _, rex, out, unit) {
      out = "";
      while (keyseq != "") {
        if (mode == 0 || mode == 3) {
          match(keyseq, /^\\C-\\(\\"$)?|^\\M-|^\\.|^./);
        } else {
          match(keyseq, /^\\[CM]-|^\\.|^./);
        }
        unit = substr(keyseq, 1, RLENGTH);
        keyseq = substr(keyseq, 1 + RLENGTH);
        if (unit == "\\C-\\") {
          unit = unit "\\";
        } else if (unit == "\\M-") {
          unit = "\\e";
        }
        out = out unit;
      }
      return out;
    }
    match($0, /^"(\\.|[^"])+": /) {
      key = substr($0, 1, RLENGTH - 2);
      val = substr($0, 1 + RLENGTH);
      if (_ble_bash < 50100)
        key = workaround_bashbug(key);
      if (mode) {
        type = mode == 1 ? "x" : mode == 2 ? "s" : "";
        keymap_register(key, val, type);
      } else {
        keymap0[key] = val;
      }
    }
  ' 2> /dev/null
[3]   Done                    '/usr/bin/stty' "$@"

And also sometimes I get some rather more confusing text:

$ fcÀM-^[[2;1RÀM-^[[>0;0;0c0;0;0>[M-^[ÀR1;2[M-^[cÀ

Here I'm trying to run fc but before clicking enter that gets outputted.

This is all likely just some race conditions or whatever, but I thought I might want to open an issue as this happens quite frequently. Hoping for a fix or similar.

@0neGal 0neGal changed the title Code when running a command quickly Code when echo'ed when running a command quickly Apr 24, 2021
@0neGal 0neGal changed the title Code when echo'ed when running a command quickly Code echo'ed when running a command quickly Apr 24, 2021
@akinomyoga
Copy link
Owner

Thank you for your report! Currently, the problem doesn't reproduce. I'll later check the related code to guess what's happening. It may take some time.

@0neGal
Copy link
Author

0neGal commented Apr 26, 2021

Just to provide some of my configs, below is my inputrc

set colored-stats on
set visible-stats on
set completion-ignore-case on
set show-all-if-unmodified on
set colored-completion-prefix on
set mark-symlinked-directories on
set menu-complete-display-prefix on

set keyseq-timeout 1
Control-l: clear-screen 

Weirdly enough this doesn't happen (as far as I can tell) on my laptop where I've turned off a few settings:

complete -r
bleopt complete_auto_history=
bleopt complete_auto_complete=

Outside of that, the only interesting stuff is my statusline and some vimode stuff in my blerc

opt info_display=bottom

function status/set-up-status-line {
	opt keymap_vi_mode_show=
	opt keymap_vi_mode_update_prompt=1

	function ble/prompt/backslash:status/currentmode {
		local mode; ble/keymap:vi/script/get-mode
		case $mode in
			(*n)	ble/prompt/print $"-- NORMAL --" ;;
			(*v)	ble/prompt/print $"-- VISUAL --" ;;
			(*V)	ble/prompt/print $"-- V-LINE --" ;;
			(*^V)	ble/prompt/print $"-- V-BLOQ --" ;;
			(*s)	ble/prompt/print $"-- SELECT --" ;;
			(*S)	ble/prompt/print $"-- S-LINE --" ;;
			(*^S)	ble/prompt/print $"-- S-BLOQ --" ;;
			(i)		ble/prompt/print $"-- INSERT --" ;;
			(R)		ble/prompt/print $"-- RPLACE --" ;;
			(^R)	ble/prompt/print $"-- VPLACE --" ;;
			(*)		ble/prompt/print $"-- ?????? --" ;;
		esac

		# Change the default color of status line
		case $mode in
			*n)
				color prompt_status_line fg=silver,bold
				;;
			i)
				color prompt_status_line fg=magenta,bold
				;;
			*[vV^VsS^S])
				color prompt_status_line fg=cyan,bold
				;;
			*[iR^R])
				color prompt_status_line fg=red,bold
				;;
			*)
				color prompt_status_line fg=silver,bold
				;;
		esac
	}

	opt prompt_status_line="\q{status/currentmode}"
}
blehook/eval-after-load keymap_vi status/set-up-status-line

@akinomyoga
Copy link
Owner

akinomyoga commented May 9, 2021

Hi, sorry for the delay, and thank you for your additional information. I still cannot reproduce the main problem. Maybe this is related to the way how you source ble.sh and attach to ble.sh session. Can you provide me with your .bashrc, in particular the part you source ble.sh (plus ble-attach if any)?

opt info_display=bottom

Where you defined opt? ble.sh provides bleopt but not opt, so I guess you define some alias or a shell function named opt. Maybe there are also related settings near the place where you defined opt?


And also sometimes I get some rather more confusing text:

$ fcÀM-^[[2;1RÀM-^[[>0;0;0c0;0;0>[M-^[ÀR1;2[M-^[cÀ

For this problem, I could reproduce a similar behavior by setting bleopt input_encoding=C. Maybe this is related to the locale. What is your locale ($LC_CTYPE, $LANG, $LC_ALL, etc.) at the beginning of .bashrc? And what is your locale after the end of .bashrc?

@0neGal
Copy link
Author

0neGal commented May 9, 2021

This is what loads ble:

ble() {
	[ -n "$SKIPBLE" ] && return
	. "$BASH_CONFIG/ble.sh/out/ble.sh"
	. "$BASH_CONFIG/blesh" # My .blerc
}

[ -z "$STARTXORG" ] && [ -t 0 ] && ble  

The whole idea is to allow the user to disable Ble in my dotfiles with a simply variable which is why that's there, furthermore it also doesn't load Ble on TTY's where Xorg will run, as that's just slowing down Xorg.

In terms of the opt, it's simply an alias in the top of my blerc, it's only there to make the config a little bit more pretty.

... What is your locale ...

The only variable that's set is $LANG it being set to en_US.UTF-8

@akinomyoga
Copy link
Owner

akinomyoga commented May 9, 2021

Thank you for the information!

This is what loads ble:

Ah, OK. You are sourcing ble.sh inside a function without arguments. I guess that is important information. I have never tried that combination. I'll again try with it.

In terms of the opt, it's simply an alias in the top of my blerc, it's only there to make the config a little bit more pretty.

OK, so the code shown in your previous reply was just a part of your "$BASH_CONFIG"/blesh? I'm interested in the entire setting. Is it just alias opt=bleopt plus the contents shown in your previous reply? Edit: Where is your vi-mode setting (like set -o vi or set editing-mode vi)? Where is the definition of color (though I guess it is an alias of ble-color-setface).

Also, if you have time, can you check if the problem reproduces without any settings in .bashrc other than what you have shown me?

By the way, I think I'll define a function ble in future which can be used as ble SUBCOMMAND ARGS....

The only variable that's set is $LANG it being set to en_US.UTF-8

OK. This value seems to be fine. Where do you set that variable? Is it a system-wide setting? Or is it a setting that you set inside your .bashrc? More specifically, what is $LANG when you call . "$BASH_CONFIG/ble.sh/out/ble.sh" and what is $LANG when you call ble-attach (if you call it at the bottom of .bashrc)?

@0neGal
Copy link
Author

0neGal commented May 10, 2021

Is it just alias opt=bleopt plus the contents shown in your previous reply?

Yup

Where is the definition of color (though I guess it is an alias of ble-color-setface).

Yeah it's also aliased alias color="ble-color-setface"

Where do you set that variable? Is it a system-wide setting?

It's part of my sourced files in my .bashrc, it's loaded before ble is... It should be the same value before and after. As it's being set when ble isn't loaded and when it is.

I also tested with only the ble() being executed in my .bashrc and it still happens.

@akinomyoga
Copy link
Owner

OK, thank you for the additional information. I'll later continue to investigate the issue. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants