79 lines
1.9 KiB
Ruby

module VagrantPlugins
module CommandServe
class Client
class Terminal < Client
STYLE = {
detail: "info",
info: "info",
output: "info",
warn: "warning",
error: "error",
success: "success",
header: "header"
}
# @return [String] name of proto class
def self.sdk_alias
"TerminalUI"
end
def is_interactive
client.is_interactive.interactive
end
def input(prompt, **opts)
event_resp = client.events(
[
SDK::TerminalUI::Event.new(
input: SDK::TerminalUI::Event::Input.new(
prompt: prompt,
style: STYLE[:info],
secret: !!opts[:echo]
)
),
].each
)
event_resp.map { |resp|
input = resp.input
if !input.error.nil?
raise Vagrant::Errors::VagrantRemoteError, msg: input.error.message
end
input.input
}.first
end
# @param [Array] lines Lines to print
def output(line, **opts)
style = STYLE[opts[:style]]
if opts[:bold] && style != "header"
style = "#{style}-bold"
end
client.events(
[
SDK::TerminalUI::Event.new(
line: SDK::TerminalUI::Event::Line.new(
msg: line,
style: style,
disable_new_line: !opts[:new_line],
)
)
].each
).each {}
end
def clear_line
client.events(
[
SDK::TerminalUI::Event.new(
clear_line: SDK::TerminalUI::Event::ClearLine.new
)
].each
).each {}
end
end
end
end
end