-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows console history via F7 does not work in terminal mode #1097
Comments
OK, something totally weird is happening upon F7: Using the avrdude code with
and selecting a string of '123' from the history gives me a input buffer with
|
Hm, did some playing and it seems The glory details...#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <windows.h>
#define USE_UNICODE 1
char* terminal_get_input(const char* prompt)
{
printf("%s", prompt);
#if USE_UNICODE
DWORD dwCharsRead = 0;
WCHAR wcBuffer[256] = { 0 };
if (ReadConsoleW(
GetStdHandle(STD_INPUT_HANDLE),
wcBuffer,
ARRAYSIZE(wcBuffer),
&dwCharsRead,
NULL))
{
CHAR acBuffer[256] = { 0 };
int nChars = WideCharToMultiByte(
GetConsoleCP(),
0,
wcBuffer,
dwCharsRead,
acBuffer,
ARRAYSIZE(acBuffer) - 1,
NULL,
NULL);
if (nChars > 0)
{
acBuffer[nChars] = 0;
return _strdup(acBuffer);
}
}
return NULL;
#else
DWORD dwCharsRead = 0;
CHAR acBuffer[256] = { 0 };
if (ReadConsoleA(
GetStdHandle(STD_INPUT_HANDLE),
acBuffer,
ARRAYSIZE(acBuffer) - 1,
&dwCharsRead,
NULL))
{
if (dwCharsRead > 0)
{
acBuffer[dwCharsRead] = 0;
return _strdup(acBuffer);
}
}
return NULL;
#endif
#if OLD_IMPLEMENTATION
char input[256] = { 0 };
char* returns = fgets(input, sizeof(input), stdin);
if (returns)
{
return _strdup(input);
}
else
{
return NULL;
}
#endif
}
int main()
{
while (1)
{
char* buffer = terminal_get_input("avrdude> ");
printf("Got: '%s'\n", buffer);
free(buffer);
}
} |
I think this can be a low priority. If we can get #1186 fixed, then I believe it does not really matter much any more. |
#1264 seems to be able to fix this issue. |
| something totally weird is happening upon F7 I suspect this is '123' in 32-bit unicode, not? Hence your success when using the Unicode API ReadConsoleW... |
No, it's random. Sometimes the first few characters are returned (i.e. as ANSI bytes), and the rest is missing (which may look like UTF32?). I tried reading from the Unicode stream std::wcin, but it appears it is still using ReadFile and not ReadConsoleW, so this did not work. Anyway, I will not spend more time on this, as converting a stream into a line is not trivial. I submitted a bug report to Microsoft, lets see if anybody cares. |
Can we close this issue? At least the MSVC version now works with F7. For MinGW version, we have #1271. Even if F7 does not work under MinGW, I would not think it is a real issue. |
I will close this issue now since it works with MSVC version. I do not think it is a real issue for MinGW build. |
When I use the console shortcut
F7
in terminal mode to bring up the history, the history shows, but when selecting an item, it seems only the first character is being read, and not the entire command. Other editing commands such as cursor up/down, F3, etc. seem to work.The text was updated successfully, but these errors were encountered: