chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.62k stars 143 forks source link

Problems in `set /p` #553

Closed chrisant996 closed 9 months ago

chrisant996 commented 9 months ago

Discussed in https://github.com/chrisant996/clink/discussions/552

Originally posted by @boka-boka January 25, 2024 Hello, I have a very simple bat file that works well in standard cmd, but doesn't work when executed in a clink context: ```batchfile @echo off set /p test=enter file name using tab completion: call :PRINT goto :EOF :PRINT echo test is : "%test%" goto :EOF ``` Idea is to retrieve the name of a file found through completion capability. When I launch script, and use "tab" to complete to any file in the current directory, output is different with clink compared to basic cmd. With cmd: ```batchfile C:\tmp>c:\tmp\test.bat enter file name using tab completion:myfile.txt test is : "myfile.txt" ``` With clink/cmd: ```batchfile C:\tmp>c:\tmp\test.bat enter file name using tab completion:myfile.txt test is : "" ``` Should I proceed differently ? Is that a known behavior ? Thank you, Erwan
chrisant996 commented 9 months ago

When I run the script in a cmd with clink injected, Tab doesn't even do completion; it just inserts raw TAB characters.

I'll debug and fix both issues.

P.S. This used to work as of v1.4.0, so something has regressed since then.

v1.4.0

  • Fixed #370; Tab inside set /p var= mistakenly discards any previous input.
chrisant996 commented 9 months ago

When I run the script in a cmd with clink injected, Tab doesn't even do completion; it just inserts raw TAB characters.

The reason Tab completion isn't working for me is because the control parameter is NULL in the intercepted ReadConsoleW call. https://github.com/chrisant996/clink/blob/864f246de34b16236fa2de6bd10ea6631efc3c50/clink/app/src/host/host_cmd.cpp#L548

Oh, and that's because I have my CMD shortcuts configured to explicitly pass /f:off which turns off completion. There was a reason I did that, but I forget why. 🤷‍♂️

chrisant996 commented 9 months ago

@boka-boka What version of Clink are you using? Can you share the full output from clink info?

When I run the test bat script in CMD with Clink v1.6.1 injected, I get the expected results:

image

boka-boka commented 9 months ago

This is the output from clink info. Clearly an old version... I'll install the latest one to check my scenario.

clink  info
version  : 1.3.15.6e6e45
session  : 25644
binaries : C:\Program Files\ConEmu\ConEmu\clink
state    : C:\Users\evb\AppData\Local\clink
log      : C:\Users\evb\AppData\Local\clink\clink.log
settings : C:\Users\evb\AppData\Local\clink\clink_settings
history  : C:\Users\evb\AppData\Local\clink\clink_history
scripts  : C:\Program Files\ConEmu\ConEmu\clink ; C:\Users\evb\AppData\Local\clink
inputrc  : %clink_inputrc%
             (unset)
         : state directory
             C:\Users\evb\AppData\Local\clink\.inputrc
             C:\Users\evb\AppData\Local\clink\_inputrc
         : %userprofile%
             C:\Users\evb\.inputrc
             C:\Users\evb\_inputrc
         : %localappdata%
             C:\Users\evb\AppData\Local\.inputrc
             C:\Users\evb\AppData\Local\_inputrc
         : %appdata%
             C:\Users\evb\AppData\Roaming\.inputrc
             C:\Users\evb\AppData\Roaming\_inputrc
         : %home%
             C:\Users\evb\.inputrc
             C:\Users\evb\_inputrc

After installing latest version (version : 1.6.1.c7c448), it works very well.

Really sorry for this false alarm, and thanks a lot for your work on this great tool.

chrisant996 commented 9 months ago

Oh yeah, that explains it. It was fixed in 1.4.0 a while back.

Thanks for reporting it, and I'm glad it's working now after the update.