Port bundled linenoise to windows #1612
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adapted from https://github.com/microsoftarchive/redis/blob/3.0/deps/linenoise/linenoise.c and https://github.com/LuaDist-testing/linenoise-windows/blob/master/linenoise-windows/linenoise.c.
Those also make some more changes which I'm not sure are necessary, but (linenoise-windows replaces some control characters with windows API calls; which may be necessary with older versions of windows since it sounds like the ANSI control code support is recent, but I tried to keep this as small as possible rather than blindly copying stuff, particularly since linenoise-windows is for an older version of linenoise which is missing a bunch of stuff).
Generally it seems to work. I tested the basic functionality and most of the control codes (one thing I had to fix myself; the ports linked above tried had special handling to read the control codes which seemed to be broken, but it works without the special case).
I had to disable highlighting on windows, which was badly broken. According to https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences it should be possible to use colour codes if you set the
ENABLE_VIRTUAL_TERMINAL_PROCESSING
console mode flag, but setting that always failed on the terminal I was testing with. Even without that the colour codes had an effect (it did seem to turn text green), but behaved badly. There are windows API calls which can be used to control the formatting instead, but I don't think that would work very well with the current way highlighting is done since I think they all write directly to the console, rather than to a buffer (since they don't use special characters I guess).There are also some alternative libraries which are cross-platform, but this seemed like the most straightforward way of getting it working.