Announcement Announcement Module
Collapse
No announcement yet.
How to read user Input from Console with Spring Shell Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to read user Input from Console with Spring Shell

    Hi,

    i wonder how the user can enter some input from the spring shell via console, e.g. a password or login:
    Tried to use:

    login = cons.readLine("%s", "Login: ");

    But after every key pressed input is already newline terminated - whats the way to get something from spring-shell from stdin - documentation does not mention anything about this?
    JLine does have its fingers on the stream, so how to get JLine stream control from a command?

    My current "really ugly hack" is to use this:

    Code:
    @Autowired
    private Shell shell;
    
    @CliCommand("read")
    public void readSomething() {
      ConsoleReader reader = (ConsoleReader) FieldUtils.getProtectedFieldValue("reader", shell);
      reader.readline("Login: ");
    }
    And whats the correct way to print something to the shell - e.g. a progress bar (using carriage returns without new lines) - how is that done?
    The "flash" looks something like it can be used for the latter, however how can the location be customized, positioning is a problem in the right corner per default, how can the implementation be switched?
    Last edited by tkrah; May 6th, 2014, 10:48 AM.
Working...
X