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

Multiline prompt #154

Open
jubalh opened this issue Jun 12, 2014 · 5 comments
Open

Multiline prompt #154

jubalh opened this issue Jun 12, 2014 · 5 comments

Comments

@jubalh
Copy link

jubalh commented Jun 12, 2014

Hello,
You strip all special characters away in setPrompt however I would like to have the possibility to have multiline prompts.
Could we let /n (or do we need %n here?) pass through this or would this create problems on some operating systems?

Is there another way to add multiline prompts?

cheers

@bamcgill
Copy link

One way to do this is to manage a buffer in your main editor event loop and while 'editing' something, you can set the prompt to whatever line # is next and use a blank line or some terminator to stop editing, then have a set of commands to manage the buffer,

@jubalh
Copy link
Author

jubalh commented Sep 12, 2014

Hey @bamcgill ! Thanks for your suggestion.
However I don't quite understand the way you would solve the issue, could you elaborate more or type a quick example maybe?

@bamcgill
Copy link

Michael,
I've used this to do apseudo muliline like this.

Here is some of the output so you can see for yourself, how it works. The asterix on the numbers shows the current line, which you can choose by typeing the line number you want to go to.
I used readline to accept commands, and to edit as well, where I switch to an editing mode and accept multiple lines. however, I manage this in the main event loop, like this

    while (rawLine = reader.readLine(prompt)) != null) { 
        if(rawLine.trim().length()==0) {
            //if blank line entered, stop editting
            prompt = stopEditing(fullLine); 
        else if (!_editing && pattern.matcher(rawLine).matches()){ //if not editing and pattern is starting with a number
            // Goto line or change line
            gotoOrChangeLine(rawLine);
        } else {
            //editing=true;
            addlinetoBuffer();
            //set prompt to length of buffer, ie, line 2, line 3 etc, to you leave a 
            //blank line or whatever you choose to switch state and then switch prompt back to start prompt
        }
             }

When youre not editing you can use commands to step up and down the buffer. Heres a snap of what mine does in one implementation of the MLE

BARRY>select
2 1
3 from
4 dual
5
BARRY>/

1

     1 

BARRY>2
2* 1

BARRY>c/1/2 dom
BARRY>l
1 select
2* 2 dom
3 from
4 dual
BARRY>/

DOM

     2 

On 12 Sep 2014, at 13:34, Michael Vetter [email protected] wrote:

Hey @bamcgill ! Thanks for your suggestion.
However I don't quite understand the way you would solve the issue, could you elaborate more or type a quick example maybe?


Reply to this email directly or view it on GitHub.

@hyee
Copy link
Contributor

hyee commented Mar 19, 2015

I encountered similar problem and have following workaround for reference:

  1. If the input command is cross-line command, then:
    • call history.removeLast()
    • call reader:setHistoryEnabled(false)
    • create a buffer to store the lines
    • define the prompt for the 2+ lines
  2. After the command is completed:
    • call history.add(buffered_string)
    • call reader:setHistoryEnabled(true)
    • clear the buffer
    • reset the prompt

After that, the command history is able to correctly show this kind of command.

The new problem is, the cursor is not able to reset back to correct position if the history scrolls to this kind of command and continue scrolling to another.

@AlexPeng19
Copy link

@bamcgill could i know how could we get transfer from edit to accept or from accept to edit mode. thanks in advance.

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

4 participants