Merge pull request #12888 from soapy1/terminal-coloring
Terminal coloring
This commit is contained in:
commit
d0d81d6bb0
@ -111,7 +111,7 @@ func (c *DoThing) Execute(trm terminal.UI, params *component.CommandParams) int3
|
||||
trm.Output(err.Error())
|
||||
return 1
|
||||
}
|
||||
trm.Output(msg)
|
||||
trm.Output(msg, terminal.WithColor("magenta"))
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@ -25,7 +25,7 @@ require (
|
||||
github.com/hashicorp/go-version v1.3.0
|
||||
github.com/hashicorp/hcl/v2 v2.11.1
|
||||
github.com/hashicorp/nomad/api v0.0.0-20200814140818-42de70466a9d
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220913204040-793a2626f6f9
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180525-50c632cd450d
|
||||
github.com/imdario/mergo v0.3.11
|
||||
github.com/improbable-eng/grpc-web v0.13.0
|
||||
github.com/kr/text v0.2.0
|
||||
|
||||
2
go.sum
2
go.sum
@ -361,6 +361,8 @@ github.com/hashicorp/nomad/api v0.0.0-20200814140818-42de70466a9d h1:afuZ/KNbxwU
|
||||
github.com/hashicorp/nomad/api v0.0.0-20200814140818-42de70466a9d/go.mod h1:DCi2k47yuUDzf2qWAK8E1RVmWgz/lc0jZQeEnICTxmY=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220913204040-793a2626f6f9 h1:wfdFsM/smge6K+RDgGLxWF4TcmAXZJis/IVUyT+G3JQ=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220913204040-793a2626f6f9/go.mod h1:zA5vDskG3gH306C+obL+yURiUiLMAlx52yqO8MC2r9w=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180525-50c632cd450d h1:TqCLroDhxzGMXE7LrgqDayOku2oRJ4vjROX7ghpzqsI=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180525-50c632cd450d/go.mod h1:zA5vDskG3gH306C+obL+yURiUiLMAlx52yqO8MC2r9w=
|
||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce h1:7UnVY3T/ZnHUrfviiAgIUjg2PXxsQfs5bphsG8F7Keo=
|
||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
|
||||
@ -182,6 +182,9 @@ func BaseCommand(ctx context.Context, log hclog.Logger, logOutput io.Writer, opt
|
||||
} else if !bc.flagInteractive {
|
||||
// Set non interactive if the --no-interactive flag is provided
|
||||
ui = terminal.NonInteractiveUI(ctx)
|
||||
} else if !bc.flagColor {
|
||||
// Set basic ui (with no color) if the --no-color flag is provided
|
||||
ui = terminal.BasicUI(ctx)
|
||||
} else {
|
||||
// If no ui related flags are set, create a new one
|
||||
ui = terminal.ConsoleUI(ctx)
|
||||
@ -195,13 +198,12 @@ func BaseCommand(ctx context.Context, log hclog.Logger, logOutput io.Writer, opt
|
||||
}
|
||||
}
|
||||
if outputExperimentalWarning {
|
||||
ui.Output(`
|
||||
This is an experimental version of Vagrant. Please note that some things may
|
||||
ui.Output(`This is an experimental version of Vagrant. Please note that some things may
|
||||
not work as you expect and this version of Vagrant is not compatible with the
|
||||
stable version of Vagrant. For more information about vagrant-go read the docs
|
||||
at https://www.vagrantup.com/docs/experimental/vagrant_go. To disable this
|
||||
warning set the environment variable 'VAGRANT_SUPPRESS_GO_EXPERIMENTAL_WARNING'.
|
||||
`)
|
||||
`, terminal.WithWarningStyle())
|
||||
}
|
||||
|
||||
homeConfigPath, err := paths.NamedVagrantConfig(bc.flagBasis)
|
||||
@ -332,6 +334,9 @@ func (c *baseCommand) Init(opts ...Option) (err error) {
|
||||
} else if !c.flagInteractive {
|
||||
// Set non interactive if the --no-interactive flag is provided
|
||||
ui = terminal.NonInteractiveUI(c.Ctx)
|
||||
} else if !c.flagColor {
|
||||
// Set basic ui (with no color) if the --no-color flag is provided
|
||||
ui = terminal.BasicUI(c.Ctx)
|
||||
} else {
|
||||
// If no ui related flags are set, use the base config ui
|
||||
ui = baseCfg.UI
|
||||
|
||||
@ -54,7 +54,7 @@ func (u *runnerUI) ClearLine() {
|
||||
// arguments should be interpolations for the format string. After the
|
||||
// interpolations you may add Options.
|
||||
func (u *runnerUI) Output(msg string, raw ...interface{}) {
|
||||
msg, style, disableNewline, _ := terminal.Interpret(msg, raw...)
|
||||
msg, style, disableNewline, _, color := terminal.Interpret(msg, raw...)
|
||||
|
||||
// Extreme java looking code alert!
|
||||
ev := &vagrant_server.RunnerJobStreamRequest{
|
||||
@ -67,6 +67,7 @@ func (u *runnerUI) Output(msg string, raw ...interface{}) {
|
||||
Msg: msg,
|
||||
Style: style,
|
||||
DisableNewLine: disableNewline,
|
||||
Color: color,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v3.19.4
|
||||
// source: proto/ruby_vagrant/ruby-server.proto
|
||||
|
||||
package ruby_vagrant
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -994,6 +994,7 @@ message GetJobStreamResponse {
|
||||
string msg = 1;
|
||||
string style = 2;
|
||||
bool disable_new_line = 3;
|
||||
string color = 4;
|
||||
}
|
||||
|
||||
message Raw {
|
||||
|
||||
@ -308,6 +308,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
repeated :lines, :string, 1
|
||||
optional :style, :enum, 2, "hashicorp.vagrant.sdk.TerminalUI.OutputRequest.Style"
|
||||
optional :disable_new_line, :bool, 3
|
||||
optional :color, :string, 4
|
||||
end
|
||||
add_enum "hashicorp.vagrant.sdk.TerminalUI.OutputRequest.Style" do
|
||||
value :HEADER, 0
|
||||
@ -355,6 +356,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
optional :msg, :string, 1
|
||||
optional :style, :string, 2
|
||||
optional :disable_new_line, :bool, 3
|
||||
optional :color, :string, 4
|
||||
end
|
||||
add_message "hashicorp.vagrant.sdk.TerminalUI.Event.Raw" do
|
||||
optional :data, :bytes, 1
|
||||
|
||||
@ -402,6 +402,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
optional :msg, :string, 1
|
||||
optional :style, :string, 2
|
||||
optional :disable_new_line, :bool, 3
|
||||
optional :color, :string, 4
|
||||
end
|
||||
add_message "hashicorp.vagrant.GetJobStreamResponse.Terminal.Event.Raw" do
|
||||
optional :data, :bytes, 1
|
||||
|
||||
@ -38,7 +38,8 @@ module Vagrant
|
||||
opts = {
|
||||
new_line: opts[:printer] == :puts,
|
||||
style: extra_opts[:style],
|
||||
bold: extra_opts[:bold]
|
||||
bold: extra_opts[:bold],
|
||||
color: extra_opts[:color]
|
||||
}
|
||||
|
||||
client.output(message.gsub("%", "%%"), **opts)
|
||||
|
||||
@ -33,7 +33,8 @@ module VagrantPlugins
|
||||
input: SDK::TerminalUI::Event::Input.new(
|
||||
prompt: prompt,
|
||||
style: STYLE[:info],
|
||||
secret: !opts[:echo]
|
||||
secret: !opts[:echo],
|
||||
color: opts[:color]
|
||||
)
|
||||
),
|
||||
].each
|
||||
@ -61,6 +62,7 @@ module VagrantPlugins
|
||||
msg: line,
|
||||
style: style,
|
||||
disable_new_line: !opts[:new_line],
|
||||
color: opts[:color]
|
||||
)
|
||||
)
|
||||
].each
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user