Implement detection of arrow keys.

This commit is contained in:
sigonasr2, Sig, Sigo 2021-12-15 20:17:23 +00:00
parent 62e8860b43
commit 348c5cc051
3 changed files with 38 additions and 5 deletions

View File

@ -9,6 +9,8 @@ import org.jline.utils.NonBlockingReader;
public class SigTerm{ public class SigTerm{
static boolean RUNNING=true; static boolean RUNNING=true;
static String storedVal=""; static String storedVal="";
static boolean is27 = false;
static boolean is91 = false;
final static String ESC = "\u001b"; final static String ESC = "\u001b";
final static String CSI = "["; final static String CSI = "[";
final static String CSICODE = ESC+CSI; final static String CSICODE = ESC+CSI;
@ -166,6 +168,11 @@ public class SigTerm{
System.out.println(RESET); System.out.println(RESET);
} }
static void RefreshScreen() {
CursorLineDown(1);
ScrollUp(1);
}
public static void main(String[] args) { public static void main(String[] args) {
try { try {
Terminal term = org.jline.terminal.TerminalBuilder.terminal(); Terminal term = org.jline.terminal.TerminalBuilder.terminal();
@ -177,12 +184,38 @@ public class SigTerm{
while (RUNNING) { while (RUNNING) {
int ch = r.peek(250); int ch = r.peek(250);
if (ch!=NonBlockingReader.READ_EXPIRED) { if (ch!=NonBlockingReader.READ_EXPIRED) {
Text(Integer.toString(r.read())); if (!is27&&!is91&&ch==27) {
} else { is27=true;
Text("..."); } else
if (is27&&!is91&&ch==91) {
is91=true;
} else
if (is27&&is91) {
//Possible special code.
switch (ch) {
case 65:{
Text("UP");
}break;
case 66:{
Text("DOWN");
}break;
case 67:{
Text("RIGHT");
}break;
case 68:{
Text("LEFT");
}break;
} }
CursorLineDown(1); is27=false;
ScrollUp(1); is91=false;
} else
{
//Text(Integer.toString(ch));
is27=is91=false;
}
r.read();
}
RefreshScreen();
} }
r.shutdown(); r.shutdown();
term.close(); term.close();

Binary file not shown.

Binary file not shown.