Permalink
Browse files

Expose prompt_char as a java function

  • Loading branch information...
LadyCailin committed Feb 2, 2019
1 parent bb99573 commit b24666ba5f61b74cfc3945108ff90206b17db5cb
Showing with 18 additions and 11 deletions.
  1. +18 −11 src/main/java/com/laytonsmith/core/functions/Cmdline.java
@@ -712,25 +712,32 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
requireCmdlineMode(environment, this, t);

String prompt = args[0].val();
StreamUtils.GetSystemOut().print(Static.MCToANSIColors(prompt));
StreamUtils.GetSystemOut().flush();
jline.console.ConsoleReader reader = null;
try {
reader = new jline.console.ConsoleReader();
reader.setExpandEvents(false);
char c = (char) reader.readCharacter();
StreamUtils.GetSystemOut().println(c);
char c = promptChar(Static.MCToANSIColors(prompt));
return new CString(c, t);
} catch (IOException ex) {
throw new CREIOException(ex.getMessage(), t);
} finally {
if(reader != null) {
reader.close();
}
}

}

/**
* Prompts for a single char from the console. The character typed is returned.
* @param prompt
* @return
* @throws IOException
*/
public static char promptChar(String prompt) throws IOException {
StreamUtils.GetSystemOut().print(prompt);
StreamUtils.GetSystemOut().flush();
try(jline.console.ConsoleReader reader = new jline.console.ConsoleReader()) {
reader.setExpandEvents(false);
char c = (char) reader.readCharacter();
StreamUtils.GetSystemOut().println(c);
return c;
}
}

@Override
public String getName() {
return "prompt_char";

0 comments on commit b24666b

Please sign in to comment.