Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a default buffer value in the buffer with readLine() #177

Closed
bdw429s opened this issue Feb 9, 2015 · 5 comments
Closed

Allow a default buffer value in the buffer with readLine() #177

bdw429s opened this issue Feb 9, 2015 · 5 comments

Comments

@bdw429s
Copy link
Contributor

bdw429s commented Feb 9, 2015

In CommandBox, our Jline2-based CLI and package manager tool for CFML, we will often have the need to ask the user for additional input when running a "installer wizard" style command.

CommandBox > addSite
Enter webroot path: _

We'd like to be able to pre-populate the buffer with default text the user can edit if they wish, or just hit enter to submit it as is:

CommandBox > addSite
Enter webroot path: C:\path\to\wwwroot_

readLine() lets me set the prompt, but not anything else. There is putString() but it's a catch 22 because you can't call putString() before readLine() because it will get output before the prompt and you can't call it after because readLine blocks until it receives your input.

For what it's worth I'm able to trick it by threading the readline() call, waiting 100ms, then outputting the default value and flushing the buffer, then joining back to the thread to await your input. Of course, this is pretty hacky so it would be nice to see this be core. Here's an example of my hack described above (in CFML):

reader = shell.getReader();

var threadname = createUUID();
variables.char = '';
thread name="#threadname#" action="run" { 
  variables.char = reader.readLine( 'What is your quest? > ' );
}

sleep(100);
reader.putString( 'To seek the Holy Grail.' );
reader.flush();

thread action="join" name="#threadname#"; 

print.boldRedLine( variables.char ).toConsole();
shell.setPrompt();

That outputs the following, with everything after the ">" as editable:

What is your quest? > To seek the Holy Grail._
@gnodet gnodet closed this as completed in 92c6ce5 Jul 22, 2015
@bdw429s
Copy link
Contributor Author

bdw429s commented Jul 22, 2015

Thanks @gnodet !

@bdw429s
Copy link
Contributor Author

bdw429s commented May 9, 2016

@gnodet I got a chance to test this out today and I'm afraid it's not quite working for me. The buffer text is appended to the buffer, but it's not flushed to the screen so you can't actually see it. Furthermore, if i hit the backspace key, it just erases that many characters out of my prompt.

@mvmn
Copy link

mvmn commented May 25, 2016

It's 2016 and JLine still doesn't support default value in input buffer? For shame.
I see that issue is fixed, but there's no release - supposed to be in 2.14.2, right? Please make the release happen soon! Can't wait for this thing to finally work.

@bdw429s
Copy link
Contributor Author

bdw429s commented Dec 8, 2016

@mvmn I'm not sure what release that fix made it into, but I can confirm it works in the 2.15-SNAPSHOT on sonatype.
https://oss.sonatype.org/content/repositories/snapshots/jline/jline/2.15-SNAPSHOT/

@mvmn
Copy link

mvmn commented Dec 8, 2016

Looks like they've released 2.14.2 on 31-st of May. 6 days after my comment. It was supposed to be in 2.14.2 already.
Good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants