字符串输入
The string input component asks a user for simple text input, optionally masking values
if the content contains something sensitive. The input can also be required (at least 1 char).
以下列表展示了一个示例:
public class ComponentCommands {
@Command(name = "component string", description = "String input", group = "Components")
public String stringInput(boolean mask) {
StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
ResourceLoader resourceLoader = null; // getResourceLoader();
TemplateExecutor templateExecutor = null; // getTemplateExecutor();
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);
if (mask) {
component.setMaskCharacter('*');
}
StringInputContext context = component.run(StringInputContext.empty());
return "Got value " + context.getResultValue();
}
}
以下屏幕录制展示了来自字符串输入组件的典型输出:
The context对象是StringInputContext。以下表格列出了其上下文变量:
| 键 | 描述 |
|---|---|
|
默认值,如果设置。否则,null. |
|
掩码输入值 |
|
被屏蔽的结果值 |
|
掩码字符,如果设置则为该值。否则,为空。 |
|
|
|
|
|
The parent context variables (see TextComponentContext 模板变量). |