Writing
当需要将内容写入控制台时,你始终可以使用 JDK 的 System.out
,然后直接进入 JDK 自身的流。另一种推荐的方法是使用 JLine 的 Terminal
并从那里获取 writer 实例。
When something needs to get written into your console you can always
use JDK’s System.out
which then goes directly into JDK’s own streams.
Other recommended way is to use JLine’s Terminal
and get writer
instance from there.
如果使用目标端点,即 consumer,则不希望返回任何内容,因为 CommandContext
包含对 Terminal
的引用,并且可以从那里访问写入器。
If using target endpoints, i.e. consumer which is not expected
to return anything given CommandContext
contains reference to
Terminal
and writer can be accessed from there.
Unresolved include directive in modules/ROOT/pages/commands/writing.adoc - include::../../../../src/test/java/org/springframework/shell/docs/WritingSnippets.java[]
如果你使用 @Command
,你可以从那里获取 CommandContext
并获取 Terminal
。
If using @Command
you can get access to CommandContext
and get
Terminal
from there.
Unresolved include directive in modules/ROOT/pages/commands/writing.adoc - include::../../../../src/test/java/org/springframework/shell/docs/WritingSnippets.java[]
可以使用 Terminal
自动连接来访问其编写者。
It’s possible to autowire Terminal
to get access to its writer.
Unresolved include directive in modules/ROOT/pages/commands/writing.adoc - include::../../../../src/test/java/org/springframework/shell/docs/WritingSnippets.java[]