Java Code Examples for org.aesh.readline.util.Parser#toCodePoints()

The following examples show how to use org.aesh.readline.util.Parser#toCodePoints() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Buffer.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
public void updateMultiLineBuffer() {
    int originalSize = multiLineBuffer.length;
    // Store the size of each line.
    int cmdSize;
    if (lineEndsWithBackslash()) {
        cmdSize = size - 1;
        multiLineBuffer = Arrays.copyOf(multiLineBuffer, originalSize + size-1);
        System.arraycopy(line, 0, multiLineBuffer, originalSize, size-1);
    }
    //here we have an open quote, so we need to feed a new-line into the buffer
    else {
        cmdSize = size + Config.getLineSeparator().length();
        multiLineBuffer = Arrays.copyOf(multiLineBuffer, originalSize + cmdSize);
        System.arraycopy(line, 0, multiLineBuffer, originalSize, size);
        // add new line
        int[] lineSeparator = Parser.toCodePoints(Config.getLineSeparator());
        System.arraycopy(lineSeparator, 0, multiLineBuffer, originalSize+size, lineSeparator.length);
    }
    locator.addLine(cmdSize, prompt.getLength());
    clear();
    prompt = new Prompt("> ");
    cursor = 0;
    size = 0;
}
 
Example 2
Source File: MaskingReadlineTest.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Test
public void maskingTest() {
    TestConnection term = new TestConnection(new Prompt("", '\u0000'));

    term.read("MMyPassword");
    term.assertOutputBuffer("");
    term.read(Key.BACKSPACE);
    term.read(Key.ENTER);
    term.assertLine("MMyPasswor");

    term = new TestConnection(new Prompt(Parser.toCodePoints("[foo] "), '%'));
    term.read("MMyPassword");
    term.assertOutputBuffer("[foo] %%%%%%%%%%%");
    term.clearOutputBuffer();
    term.read(Key.BACKSPACE);
    term.read(Key.ENTER);
    term.assertLine("MMyPasswor");
}
 
Example 3
Source File: Prompt.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public Prompt(String prompt, String ansiString) {
    if(prompt != null)
        this.prompt = Parser.toCodePoints(prompt);
    else
        this.prompt = new int[]{};
    this.ansiString = Parser.toCodePoints(ansiString);
}
 
Example 4
Source File: Prompt.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public Prompt(String prompt, Character mask) {
    if(prompt != null)
        this.prompt = Parser.toCodePoints(prompt);
    else
        this.prompt = new int[]{};
    this.mask = mask;
}
 
Example 5
Source File: Prompt.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public Prompt(String prompt, String ansiString, Character mask) {
    if(prompt != null)
        this.prompt = Parser.toCodePoints(prompt);
    else
        this.prompt = new int[]{};
    this.ansiString = Parser.toCodePoints(ansiString);
    this.mask = mask;
}
 
Example 6
Source File: Prompt.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public Prompt(TerminalString terminalString) {
    if(terminalString != null) {
        ansiString = Parser.toCodePoints(terminalString.toString());
        this.prompt = Parser.toCodePoints(terminalString.getCharacters());
    }
    else
        this.prompt = new int[]{};
}
 
Example 7
Source File: Prompt.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
private void generateOutString(List<TerminalCharacter> chars) {
    StringBuilder promptBuilder = new StringBuilder();
    StringBuilder builder = new StringBuilder();
    TerminalCharacter prev = null;
    for(TerminalCharacter c : chars) {
        if(prev == null)
            builder.append(c.toString());
        else
            builder.append(c.toString(prev));
        prev = c;
        promptBuilder.append(c.getCharacter());
    }
    ansiString = Parser.toCodePoints(builder.toString());
    this.prompt = Parser.toCodePoints(promptBuilder.toString());
}
 
Example 8
Source File: Prompt.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
public Prompt(String prompt) {
    if(prompt != null)
        this.prompt = Parser.toCodePoints(prompt);
    else
        this.prompt = new int[]{};
}