peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.05k stars 132 forks source link

Ability to edit existing text. #38

Closed KenjiTakahashi closed 9 years ago

KenjiTakahashi commented 9 years ago

I'd love to be able to do something like

text := "sometext"

line := liner.NewLiner()
line.Prompt("> ",  text)

which will make a prompt > sometext where sometext is editable. Is there any way to do this?

peterh commented 9 years ago

Sorry, no. There's no way to do that.

About the closest you can get with the current code is to seed the history buffer, so the user can find it quickly with up, tab, or Ctrl-R.

KenjiTakahashi commented 9 years ago

Yes, I have thought about this, but that's not really what I'd like to achieve.

Would you be willing to accept a PR on an additional function (PromptEdit or sth) that does it? Maybe I'll be able to get my hands on that myself :-). Or maybe you have some idea how this could be implemented?

peterh commented 9 years ago

My first thought was "No, that doesn't work when $TERM=dumb", but after thinking some more I don't think that matters much. If you're on an unsupported terminal (or reading from stdin, or whatever), a missing suggestion isn't the end of the world.

Therefore, I would be willing to consider a Pull Request that adds such a function. I'd like to see the function also take a pos int argument so you can set the cursor position to the place in the pre-filled text that you expect the user to start editing.

For the name, I was thinking PromptWithSuggestion or PromptWithHint or similar, but I'm not going to argue too much about the colour of your bikeshed.

ElPincheTopo commented 9 years ago

Now that we have many types of prompt, maybe the password prompt should be renamed to something like PromptPassword to make the prompt names more consistent.

peterh commented 9 years ago

@ElPincheTopo That's a good idea for version 2, if we ever do one.