Genivia / ugrep

NEW ugrep 6.5: a more powerful, ultra fast, user-friendly, compatible grep. Includes a TUI, Google-like Boolean search with AND/OR/NOT, fuzzy search, hexdumps, searches (nested) archives (zip, 7z, tar, pax, cpio), compressed files (gz, Z, bz2, lzma, xz, lz4, zstd, brotli), pdfs, docs, and more
https://ugrep.com
BSD 3-Clause "New" or "Revised" License
2.57k stars 109 forks source link

-Q not work correctly with ugrep built using mingw32 gcc on Windows #307

Closed jack6th closed 10 months ago

jack6th commented 10 months ago

I compiled a win32 ugrep.exe using mingw32 gcc on Windows. (ugrep v4.3.1, i686-w64-mingw32, gcc v13.2.0) Without -Q it works. (eg. ugrep -e pattern filename.txt) On cmd.exe, conemu.exe and mintty.exe I tried command below all get the error message.

# on conemu.exe & mintty.exe
$ugrep -Q filename.txt
ugrep: no ANSI terminal keyboard detected
# on cmd.exe
$ugrep -Q filename.txt
←[mugrep: ←[1;31mno ANSI terminal keyboard detected←[m

Is the issue like https://github.com/BurntSushi/ripgrep/issues/94 and https://github.com/BurntSushi/ripgrep/issues/117 ?

genivia-inc commented 10 months ago

Cygwin works. The -Q option checks terminal properties (screen and keyboard). If either fails, then it gives up. In this case the keyboard input isn't detected as a tty device or standard input is not a tty in vkey.cpp function setup:

  tty = open("/dev/tty", O_RDWR);

  if (tty < 0)
  {
    if (isatty(STDIN_FILENO) == 0)
      return false;
    tty = STDIN_FILENO;
  }

Could be something as simple as isatty() failing.

genivia-inc commented 10 months ago

Actually kind of strange that I have not trouble with ugrep running in Cygwin when in your case MinGW fails. Since Cygwin isatty() is fine (as it is likely just calling Windows _isatty()), why wouldn't MinGW not work too? I don't have MinGW installed to check for details. This has nothing to do with the ripgrep bug 117, which in ugrep works fine using isatty() on standard output (instead of standard input in vkey.cpp) and combing some special code for Windows console checking.

genivia-inc commented 10 months ago

What is your Windows OS version?

If your Windows OS version is 7 or even older, then we already know -Q will not work and this is not fixable, see #142 #84.

jack6th commented 10 months ago

Thanks for your reply. My OS is Windows 7 SP1 32bit. I recompiled ugrep with MSYS2 32bit and now -Q works.