String Input

字符串输入组件要求用户提供简单的文本输入,如果内容包含敏感信息,则可以选择屏蔽值。以下列表显示了一个示例:

The string input component asks a user for simple text input, optionally masking values if the content contains something sensitive. The following listing shows an example:

Unresolved include directive in modules/ROOT/pages/components/ui/stringinput.adoc - include::../../../../../src/test/java/org/springframework/shell/docs/UiComponentSnippets.java[]

以下屏幕截图显示了字符串输入组件的典型输出:

The following screencast shows typical output from a string input component:

{"version": 2, "width": 85, "height": 6, "timestamp": 1645645867, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
[1.262977, "o", "java -jar spring-shell-sample-commands.jar"]
[2.045105, "o", "\r\n"]
[3.846992, "o", "\u001b[?1h\u001b=\u001b[?2004h\u001b[33mmy-shell:>\u001b[0m"]
[4.717927, "o", "\u001b[31mc\u001b[0m"]
[4.824399, "o", "\u001b[31mo\u001b[0m"]
[5.014061, "o", "\u001b[31mm\u001b[0m"]
[5.703137, "o", "\u001b[31mp\u001b[0m"]
[5.802386, "o", "\u001b[31mo\u001b[0m"]
[6.434988, "o", "\u001b[31mn\u001b[0m"]
[6.653321, "o", "\u001b[31me\u001b[0m"]
[6.756821, "o", "\u001b[31mn\u001b[0m"]
[7.293975, "o", "\u001b[31mt\u001b[0m"]
[7.409984, "o", "\u001b[31m \u001b[0m"]
[7.604973, "o", "\u001b[31ms\u001b[0m"]
[7.775599, "o", "\u001b[31mt\u001b[0m"]
[7.928792, "o", "\u001b[31mr\u001b[0m"]
[7.979401, "o", "\u001b[31mi\u001b[0m"]
[8.051232, "o", "\u001b[31mn\u001b[0m"]
[8.15451, "o", "\u001b[15D\u001b[1mcomponent string\u001b[0m\u001b[K"]
[8.892861, "o", "\r\r\n\u001b[?1l\u001b>\u001b[?1000l\u001b[?2004l"]
[8.951185, "o", "\u001b[?1h\u001b=\u001b[?25l"]
[9.013964, "o", "\u001b[32;1m?\u001b[0m \u001b[97;1mEnter value\u001b[0m \u001b[34m[Default myvalue]\u001b[0m\r"]
[10.304694, "o", "\u001b[14Ch\u001b[K\r"]
[10.533832, "o", "\u001b[15Ci\r"]
[11.088255, "o", "\u001b[?1l\u001b>\u001b[?12;25h\u001b[K"]
[11.097044, "o", "\u001b[32;1m?\u001b[0m \u001b[97;1mEnter value\u001b[0m \u001b[34mhi\u001b[0m\r\n"]
[11.097492, "o", "Got value hi\r\n"]
[11.100226, "o", "\u001b[?1h\u001b=\u001b[?2004h\u001b[33mmy-shell:>\u001b[0m"]
[13.100226, "o", "\u001b[?1h\u001b=\u001b[?2004h\u001b[33mmy-shell:>\u001b[0m"]

context 对象是 StringInputContext。下表列出了其上下文变量:

The context object is StringInputContext. The following table lists its context variables:

Table 1. StringInputContext Template Variables
Key Description

defaultValue

The default value, if set. Otherwise, null.

maskedInput

The masked input value

maskedResultValue

The masked result value

maskCharacter

The mask character, if set. Otherwise, null.

hasMaskCharacter

true if a mask character is set. Otherwise, false.

model

The parent context variables (see TextComponentContext Template Variables).