-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds text-only prompt element for console-ui
Fixes #1136
- Loading branch information
Showing
7 changed files
with
185 additions
and
19 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
console-ui/src/main/java/org/jline/consoleui/elements/Text.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024, the original author(s). | ||
* | ||
* This software is distributable under the BSD license. See the terms of the | ||
* BSD license in the documentation provided with this software. | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package org.jline.consoleui.elements; | ||
|
||
import java.util.List; | ||
|
||
import org.jline.utils.AttributedString; | ||
|
||
public class Text extends AbstractPromptableElement { | ||
private final List<AttributedString> lines; | ||
|
||
private static int num = 0; | ||
|
||
public Text(List<AttributedString> lines) { | ||
// We don't actually care about names, so we just generate a unique one | ||
super("", "_text_" + ++num); | ||
this.lines = lines; | ||
} | ||
|
||
public List<AttributedString> getLines() { | ||
return lines; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
console-ui/src/main/java/org/jline/consoleui/prompt/NoResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024, the original author(s). | ||
* | ||
* This software is distributable under the BSD license. See the terms of the | ||
* BSD license in the documentation provided with this software. | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package org.jline.consoleui.prompt; | ||
|
||
public class NoResult implements PromptResultItemIF { | ||
|
||
public static final NoResult INSTANCE = new NoResult(); | ||
|
||
private NoResult() {} | ||
|
||
public String getDisplayResult() { | ||
return ""; | ||
} | ||
|
||
public String getResult() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "NoResult{}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
console-ui/src/main/java/org/jline/consoleui/prompt/builder/TextBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2024, the original author(s). | ||
* | ||
* This software is distributable under the BSD license. See the terms of the | ||
* BSD license in the documentation provided with this software. | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package org.jline.consoleui.prompt.builder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.jline.consoleui.elements.Text; | ||
import org.jline.utils.AttributedString; | ||
import org.jline.utils.AttributedStringBuilder; | ||
import org.jline.utils.AttributedStyle; | ||
|
||
public class TextBuilder { | ||
private final PromptBuilder promptBuilder; | ||
private final List<AttributedString> lines = new ArrayList<>(); | ||
|
||
public TextBuilder(PromptBuilder promptBuilder) { | ||
this.promptBuilder = promptBuilder; | ||
} | ||
|
||
public TextBuilder addLine(AttributedString text) { | ||
lines.add(text); | ||
return this; | ||
} | ||
|
||
public TextBuilder addLine(String line) { | ||
lines.add(new AttributedString(line)); | ||
return this; | ||
} | ||
|
||
public TextBuilder addLine(AttributedStyle style, String line) { | ||
AttributedStringBuilder asb = new AttributedStringBuilder(); | ||
asb.append(line, style); | ||
lines.add(asb.toAttributedString()); | ||
return this; | ||
} | ||
|
||
public TextBuilder addLines(AttributedString... lines) { | ||
this.lines.addAll(Arrays.asList(lines)); | ||
return this; | ||
} | ||
|
||
public TextBuilder addLines(String... lines) { | ||
for (String s : lines) { | ||
this.lines.add(new AttributedString(s)); | ||
} | ||
return this; | ||
} | ||
|
||
public TextBuilder addLines(AttributedStyle style, String... lines) { | ||
for (String s : lines) { | ||
AttributedStringBuilder asb = new AttributedStringBuilder(); | ||
asb.append(s, style); | ||
this.lines.add(asb.toAttributedString()); | ||
} | ||
return this; | ||
} | ||
|
||
public PromptBuilder addPrompt() { | ||
Text text = new Text(lines); | ||
promptBuilder.addPrompt(text); | ||
return promptBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters