Add #input to terminal client and use event stream
This commit is contained in:
parent
2ec4bb1a13
commit
71fb214d95
@ -2,30 +2,51 @@ module VagrantPlugins
|
||||
module CommandServe
|
||||
class Client
|
||||
class Terminal < Client
|
||||
|
||||
STYLE = {
|
||||
detail: "info",
|
||||
info: "info",
|
||||
output: "output",
|
||||
warn: "warning",
|
||||
error: "error",
|
||||
success: "success",
|
||||
header: "header"
|
||||
}
|
||||
|
||||
# @return [String] name of proto class
|
||||
def self.sdk_alias
|
||||
"TerminalUI"
|
||||
end
|
||||
|
||||
# @param [Array] lines Lines to print
|
||||
def output(lines, **opts)
|
||||
args = {
|
||||
lines: lines,
|
||||
disable_new_line: !opts[:new_line],
|
||||
style: :error,
|
||||
}
|
||||
case opts[:style]
|
||||
when :detail, :info, :output
|
||||
args[:style] = SDK::TerminalUI::OutputRequest::Style::INFO
|
||||
when :warn
|
||||
args[:style] = SDK::TerminalUI::OutputRequest::Style::WARNING
|
||||
when :error
|
||||
args[:style] = SDK::TerminalUI::OutputRequest::Style::ERROR
|
||||
when :success
|
||||
args[:style] = SDK::TerminalUI::OutputRequest::Style::SUCCESS
|
||||
end
|
||||
def input(prompt, **opts)
|
||||
client.events(
|
||||
[
|
||||
SDK::TerminalUI::Event.new(
|
||||
input: SDK::TerminalUI::Event::Input.new(
|
||||
prompt: prompt,
|
||||
style: STYLE[:info],
|
||||
secret: !!opts[:echo]
|
||||
)
|
||||
),
|
||||
].each
|
||||
).map { |resp|
|
||||
resp.input.input
|
||||
}.first
|
||||
end
|
||||
|
||||
client.output(req = SDK::TerminalUI::OutputRequest.new(**args))
|
||||
# @param [Array] lines Lines to print
|
||||
def output(line, **opts)
|
||||
client.events(
|
||||
[
|
||||
SDK::TerminalUI::Event.new(
|
||||
line: SDK::TerminalUI::Event::Line.new(
|
||||
msg: line,
|
||||
style: STYLE[opts[:style]],
|
||||
disable_new_line: !opts[:new_line],
|
||||
)
|
||||
)
|
||||
].each
|
||||
).each {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user