mirror of https://github.com/adamdruppe/arsd.git
fix annoying bug when hitting escape while moving mouse
This commit is contained in:
parent
0c65c53f21
commit
57ae7fa96b
24
terminal.d
24
terminal.d
|
@ -2069,9 +2069,20 @@ struct RealTimeConsoleInput {
|
||||||
FD_ZERO(&fs);
|
FD_ZERO(&fs);
|
||||||
|
|
||||||
FD_SET(fdIn, &fs);
|
FD_SET(fdIn, &fs);
|
||||||
if(select(fdIn + 1, &fs, null, null, &tv) == -1) {
|
int tries = 0;
|
||||||
|
try_again:
|
||||||
|
auto ret = select(fdIn + 1, &fs, null, null, &tv);
|
||||||
|
if(ret == -1) {
|
||||||
|
import core.stdc.errno;
|
||||||
|
if(errno == EINTR) {
|
||||||
|
tries++;
|
||||||
|
if(tries < 3)
|
||||||
|
goto try_again;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(ret == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
return FD_ISSET(fdIn, &fs);
|
return FD_ISSET(fdIn, &fs);
|
||||||
}
|
}
|
||||||
|
@ -2141,7 +2152,7 @@ struct RealTimeConsoleInput {
|
||||||
else
|
else
|
||||||
assert(0); // read too much, should be impossible
|
assert(0); // read too much, should be impossible
|
||||||
} else version(Windows) {
|
} else version(Windows) {
|
||||||
char[8] buf;
|
char[1] buf;
|
||||||
DWORD d;
|
DWORD d;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
if(!ReadFile(inputHandle, buf.ptr, cast(int) buf.length, &d, null))
|
if(!ReadFile(inputHandle, buf.ptr, cast(int) buf.length, &d, null))
|
||||||
|
@ -2432,7 +2443,7 @@ struct RealTimeConsoleInput {
|
||||||
|
|
||||||
// The helper reads just one actual event from the pipe...
|
// The helper reads just one actual event from the pipe...
|
||||||
// for UseVtSequences....
|
// for UseVtSequences....
|
||||||
InputEvent[] readNextEventsHelper() {
|
InputEvent[] readNextEventsHelper(int remainingFromLastTime = int.max) {
|
||||||
InputEvent[] charPressAndRelease(dchar character) {
|
InputEvent[] charPressAndRelease(dchar character) {
|
||||||
if((flags & ConsoleInputFlags.releasedKeys))
|
if((flags & ConsoleInputFlags.releasedKeys))
|
||||||
return [
|
return [
|
||||||
|
@ -2787,13 +2798,13 @@ struct RealTimeConsoleInput {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto c = nextRaw(true);
|
auto c = remainingFromLastTime == int.max ? nextRaw(true) : remainingFromLastTime;
|
||||||
if(c == -1)
|
if(c == -1)
|
||||||
return null; // interrupted; give back nothing so the other level can recheck signal flags
|
return null; // interrupted; give back nothing so the other level can recheck signal flags
|
||||||
if(c == 0)
|
if(c == 0)
|
||||||
return [InputEvent(EndOfFileEvent(), terminal)];
|
return [InputEvent(EndOfFileEvent(), terminal)];
|
||||||
if(c == '\033') {
|
if(c == '\033') {
|
||||||
if(timedCheckForInput(50)) {
|
if(timedCheckForInput_bypassingBuffer(50)) {
|
||||||
// escape sequence
|
// escape sequence
|
||||||
c = nextRaw();
|
c = nextRaw();
|
||||||
if(c == '[') { // CSI, ends on anything >= 'A'
|
if(c == '[') { // CSI, ends on anything >= 'A'
|
||||||
|
@ -2815,6 +2826,9 @@ struct RealTimeConsoleInput {
|
||||||
} else {
|
} else {
|
||||||
return translateTermcapName(cap);
|
return translateTermcapName(cap);
|
||||||
}
|
}
|
||||||
|
} else if(c == '\033') {
|
||||||
|
// could be escape followed by an escape sequence!
|
||||||
|
return keyPressAndRelease(NonCharacterKeyEvent.Key.escape) ~ readNextEventsHelper(c);
|
||||||
} else {
|
} else {
|
||||||
// I don't know, probably unsupported terminal or just quick user input or something
|
// I don't know, probably unsupported terminal or just quick user input or something
|
||||||
return keyPressAndRelease(NonCharacterKeyEvent.Key.escape) ~ charPressAndRelease(nextChar(c));
|
return keyPressAndRelease(NonCharacterKeyEvent.Key.escape) ~ charPressAndRelease(nextChar(c));
|
||||||
|
|
Loading…
Reference in New Issue