Skip to content

Commit

Permalink
Expose prompt_char as a java function
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Feb 2, 2019
1 parent bb99573 commit b24666b
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/main/java/com/laytonsmith/core/functions/Cmdline.java
Expand Up @@ -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";
Expand Down

0 comments on commit b24666b

Please sign in to comment.