chrisant996 / readline_win32_sample

Demonstrate how to use Readline in a Windows console program
GNU General Public License v3.0
1 stars 0 forks source link

Getting Readline working in PSQL #2

Closed chrisant996 closed 1 year ago

chrisant996 commented 2 years ago

But it is currently crashing because "fd" is -1; (the file descriptor). So, I had to HACK a break point, and skip the IsTTY(fd) check, and just run _getch();

Stack is: rl_read_key() -> rl_get_char() [input.c circa line 514] then it calls c = (*rl_getc_function) (rl_instream);

    which calls rl_getc(FILE *stream)

    And this *stream is not properly initialized.
    I think in MY READLINE_INITIALIZE I need to set this to stdin somehow?

Take a look at the sample repo. I don't know exactly what is causing the problems described above, but I think they're probably self-inflicted wounds. 😉

You mentioned earlier something about needing to declare your own copies of some Readline variables. If that's still being done, then don't. That can only create problems.

Originally posted by @chrisant996 in https://github.com/chrisant996/clink/issues/377#issuecomment-1322926264

kirkw commented 2 years ago

@chrisant996 Okay, I ran Dr. Memory on windows against the software... Right at the start, it complains... Maybe you could run your code through it? Dr. Memory on GitHub

Maybe I am supposed to initialize some things with memory sooner? Before some invocation of your stuff?

image

chrisant996 commented 2 years ago

@kirkw No such issue when using c_sample.exe.

The first call to readline() will initialize things if they haven't already been initialized. It is also reasonable to call rl_initialize() as psql is doing.

My other thing ended early, and I'm available now.

Also, looking at terminal.c line 330, I have to question how drmemory reached the conclusion that there is an uninitialized read. _rl_screenheight is explicitly and unconditionally initialized in lines 279-285.

Or maybe our local repos are not using the same version of Readline sources? git rev-parse HEAD should output d184e195494526d477b5792dc16cb0559708a027. Update: oh right, you mentioned you are just using copied files, and you don't actually have a repo on the machine?

I would email you, but your github profile doesn't seem to have a public email address listed. You can email me at the address in my github profile.

I assume that GoToMeeting can be used through the browser, without installing a client program?

kirkw commented 2 years ago

@chrisant996 first, in this reader, why does ctrl-space emit codes? ;5;32~ I assume the 5 = shift state and 32 is the space key... Since I get ;2;32~ for Shift-space.

Probably Debug? (or is it readline internally?)

Next up. have you run this in a CMD shell? the escapes sequences show up, no color? Strange. It works in the terminal window through VS just fine.

Okay, let me confirm. This happens ONLY on the SERVER (Windows Server). It may not be supporting the escape codes for some reason (internal setting)

Caused by VirtualTerminalLevel = 0 [HKEY_CURRENT_USER\Console], change it to 1, and it works fine. WOW, the things you learn!

chrisant996 commented 2 years ago

@chrisant996 first, in this reader, why does ctrl-space emit codes? ;5;32~ I assume the 5 = shift state and 32 is the space key... Since I get ;2;32~ for Shift-space.

It's two things:

  1. If a key is not bound, Readline discards whatever prefix matched a prefix of some existing key binding, and then the rest gets interpreted as separate input. This is just how Readline and most Unix input programs work and have always worked. It's why typing various keys on Unix inserts "gibberish", such as F6. Most Unix keyboard drivers don't handle modifiers keys with Space.
  2. The keyboard driver code is lifted from Clink, where I wanted Ctrl-Space to be bindable. And Clink's keyboard driver integrates more deeply with both Clink and Readline, and uses a callback to ask Clink whether the key sequence it's about to generate has a key binding. If not, then the key sequence is completely discarded, instead of only partially discarded. On Unix, the keyboard driver is part of the OS and can't integrate with apps like that (it could, if someone made changes to the OS and to the C runtime, but changing the C runtime is fraught with peril and compatibility problems and opinions).

I'll put the support for modifier keys with Space behind an #ifdef.

Next up. have you run this in a CMD shell? the escapes sequences show up, no color? Strange. It works in the terminal window through VS just fine.

Okay, let me confirm. This happens ONLY on the SERVER (Windows Server). It may not be supporting the escape codes for some reason (internal setting)

Caused by VirtualTerminalLevel = 0 [HKEY_CURRENT_USER\Console], change it to 1, and it works fine. WOW, the things you learn!

Oh, I didn't realize that the Server default was for support for console ANSI escape codes to be disabled. But also, what version of Windows Server are you using? The whole issue is that different versions of Windows do/don't have support for console ANSI escape codes enabled. That's what the warning message is talking about.