确认
确认组件会提示用户进行简单的确认。本质上是一个是/否问题。
@ShellComponent
public class ComponentCommands extends AbstractShellComponent {
@ShellMethod(key = "component confirmation", value = "Confirmation input", group = "Components")
public String confirmationInput(boolean no) {
ConfirmationInput component = new ConfirmationInput(getTerminal(), "Enter value", !no);
component.setResourceLoader(getResourceLoader());
component.setTemplateExecutor(getTemplateExecutor());
ConfirmationInputContext context = component.run(ConfirmationInputContext.empty());
return "Got value " + context.getResultValue();
}
}
以下屏幕截图显示了确认组件的典型输出
上下文对象为 ConfirmationInputContext
。下表描述了其上下文变量
键 | 描述 |
---|---|
|
默认值 - |
|
父上下文变量(请参阅 TextComponentContext 模板变量)。 |