cantino / mcfly

Fly through your shell history. Great Scott!
MIT License
6.77k stars 176 forks source link

Strange "illegal byte sequence" results when using Mcfly #223

Closed SamShowalter closed 2 years ago

SamShowalter commented 2 years ago

M1 Mac: 12.1 (Monterey) iTerm: 3.4.15 zsh: 5.8 mcfly version: 0.5.11 zsh plugins: {zsh} | -z, -autosuggestions, autojump, git, vi-mode other plugins: tldr

When I run mcfly search {keyword} the history bar pops up like normal. However, any attempt to complete something from this menu results in a strange "illegal byte sequence" error. The zvm_update_repeat_commands error is the result of vi-mode choking on the byte sequences (but removing that plugin does not resolve the issue). I have removed all plugins and witnessed the same behavior.

Please see the two screenshots I have added below.

Screen Shot 2022-01-09 at 10 23 15 AM

After hitting Enter or Tab

Screen Shot 2022-01-09 at 10 23 37 AM
rm-hull commented 2 years ago

I see something similar - it shows question marks instead (with bash)

18:43 $ mcfly search
18:43 $ ????????????????
-bash: $'\317\317\317\317\317\317\317\317\317\317\317\317\317\317\317\317': command not found
18:44 $ mcfly --version
McFly 0.5.11
arunpersaud commented 2 years ago

Hi, I'm getting the same with the latest git version (0.5.12); also on an M1 and installed via brew.

Don't really know much about rust or ioctl calls, but for what it is worth I played around with the source code a bit and fake_typer:use_tiocsti does get the correct string, so perhaps the issue is somewhere in the ioctl call? I did try calling ioctl using python on the same computer and there it works

In [2]: import fcntl
In [3]: import termios
In [4]: import sys
In [5]: for c in "test":
   ...:     fcntl.ioctl(sys.stdin, termios.TIOCSTI, c)
test
In [6]: test

Not sure if this is helpful. Looking forward to getting this bug fixed though ;) Also happy to try things out on my laptop if that helps.

arunpersaud commented 2 years ago

played around a bit more and this seems to work for me: fake_typer.rs

use libc;
extern {
    pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
}

pub fn use_tiocsti(string: &str) {
    for byte in string.as_bytes() {
    let a: *const u8 = byte;
        if unsafe { ioctl(0, libc::TIOCSTI, a) } < 0 {
            panic!("Error encountered when calling ioctl");
        }
    }
}

Note: first time rust user, so I really have no idea what I'm doing here ;)

cantino commented 2 years ago

Hey @arunpersaud, awesome! That seems to still work fine for me on my non-M1 Mac. Does that mean that https://github.com/cantino/mcfly/pull/228 fixes the issue for you @arunpersaud and @SamShowalter and @rm-hull?

arunpersaud commented 2 years ago

Just tried out the fix-tiocsti-cast-bug branch (69fd1f2c606) and that seems to work on my computer. Thanks!

SamShowalter commented 2 years ago

Looks good to me!

cantino commented 2 years ago

Thanks! I'll get a new release out shortly.

cantino commented 2 years ago

Released in v0.5.13.

rm-hull commented 2 years ago

v0.5.13 works for me now on M1 with bash Thank you