Reporter rename

David Bennett committed Aug 7, 2026 at 14:07 UTC 701f993d307958bc90e650ece49db3e19e4f5554
48 files changed +448 -448
src/windows/wslc/commands/ContainerCommand.cpp
+1 -1
@@ -57,6 +57,6 @@ std::wstring ContainerCommand::LongDescription() const
57
58 void ContainerCommand::ExecuteInternal(CLIExecutionContext& context) const
59 {
60 - OutputHelp(context.Reporter);
60 + OutputHelp(context.Terminal);
61 }
62 } // namespace wsl::windows::wslc
src/windows/wslc/commands/ImageCommand.cpp
+1 -1
@@ -53,6 +53,6 @@ std::wstring ImageCommand::LongDescription() const
53
54 void ImageCommand::ExecuteInternal(CLIExecutionContext& context) const
55 {
56 - OutputHelp(context.Reporter);
56 + OutputHelp(context.Terminal);
57 }
58 } // namespace wsl::windows::wslc
src/windows/wslc/commands/NetworkCommand.cpp
+1 -1
@@ -49,6 +49,6 @@ std::wstring NetworkCommand::LongDescription() const
49
50 void NetworkCommand::ExecuteInternal(CLIExecutionContext& context) const
51 {
52 - OutputHelp(context.Reporter);
52 + OutputHelp(context.Terminal);
53 }
54 } // namespace wsl::windows::wslc
src/windows/wslc/commands/RegistryCommand.cpp
+4 -4
@@ -50,7 +50,7 @@ std::wstring RegistryCommand::LongDescription() const
50
51 void RegistryCommand::ExecuteInternal(CLIExecutionContext& context) const
52 {
53 - OutputHelp(context.Reporter);
53 + OutputHelp(context.Terminal);
54 }
55
56 // Registry Login Command
@@ -91,7 +91,7 @@ void RegistryLoginCommand::ExecuteInternal(CLIExecutionContext& context) const
91 {
92 if (!context.Args.Contains(ArgType::Username))
93 {
94 - auto username = context.Reporter.PromptForLine(Localization::WSLCCLI_LoginUsernamePrompt());
94 + auto username = context.Terminal.PromptForLine(Localization::WSLCCLI_LoginUsernamePrompt());
95 context.Args.Add(ArgType::Username, std::move(username));
96 }
97
@@ -100,11 +100,11 @@ void RegistryLoginCommand::ExecuteInternal(CLIExecutionContext& context) const
100 {
101 if (context.Args.GetFlag<ArgType::PasswordStdin>())
102 {
103 - context.Args.Add(ArgType::Password, context.Reporter.ReadLine().value_or(std::wstring{}));
103 + context.Args.Add(ArgType::Password, context.Terminal.ReadLine().value_or(std::wstring{}));
104 }
105 else
106 {
107 - auto password = context.Reporter.PromptForLine(Localization::WSLCCLI_LoginPasswordPrompt(), true);
107 + auto password = context.Terminal.PromptForLine(Localization::WSLCCLI_LoginPasswordPrompt(), true);
108 context.Args.Add(ArgType::Password, std::move(password));
109 }
110 }
src/windows/wslc/commands/RootCommand.cpp
+2 -2
@@ -105,10 +105,10 @@ void RootCommand::ExecuteInternal(CLIExecutionContext& context) const
105 {
106 if (context.Args.GetFlag<ArgType::Version>())
107 {
108 - VersionCommand::PrintVersion(context.Reporter);
108 + VersionCommand::PrintVersion(context.Terminal);
109 return;
110 }
111
112 - OutputHelp(context.Reporter);
112 + OutputHelp(context.Terminal);
113 }
114 } // namespace wsl::windows::wslc
src/windows/wslc/commands/SessionCommand.cpp
+1 -1
@@ -48,6 +48,6 @@ std::wstring SessionCommand::LongDescription() const
48
49 void SessionCommand::ExecuteInternal(CLIExecutionContext& context) const
50 {
51 - OutputHelp(context.Reporter);
51 + OutputHelp(context.Terminal);
52 }
53 } // namespace wsl::windows::wslc
src/windows/wslc/commands/SettingsCommand.cpp
+1 -1
@@ -83,7 +83,7 @@ std::wstring SettingsResetCommand::LongDescription() const
83 void SettingsResetCommand::ExecuteInternal(CLIExecutionContext& context) const
84 {
85 settings::User().Reset();
86 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_SettingsResetConfirm());
86 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_SettingsResetConfirm());
87 }
88
89 } // namespace wsl::windows::wslc
src/windows/wslc/commands/SystemCommand.cpp
+1 -1
@@ -43,6 +43,6 @@ std::wstring SystemCommand::LongDescription() const
43
44 void SystemCommand::ExecuteInternal(CLIExecutionContext& context) const
45 {
46 - OutputHelp(context.Reporter);
46 + OutputHelp(context.Terminal);
47 }
48 } // namespace wsl::windows::wslc
src/windows/wslc/commands/VersionCommand.cpp
+4 -4
@@ -40,9 +40,9 @@ std::wstring VersionCommand::LongDescription() const
40 return Localization::WSLCCLI_VersionLongDesc();
41 }
42
43 -void VersionCommand::PrintVersion(Reporter& reporter)
43 +void VersionCommand::PrintVersion(Terminal& terminal)
44 {
45 - reporter.Output(L"{} {}\n", s_ExecutableName, WSL_PACKAGE_VERSION);
45 + terminal.Output(L"{} {}\n", s_ExecutableName, WSL_PACKAGE_VERSION);
46 }
47
48 void VersionCommand::ExecuteInternal(CLIExecutionContext& context) const
@@ -55,11 +55,11 @@ void VersionCommand::ExecuteInternal(CLIExecutionContext& context) const
55 {
56 nlohmann::json root;
57 root["Client"]["Version"] = std::string{WSL_PACKAGE_VERSION};
58 - context.Reporter.Output(L"{}\n", MultiByteToWide(root.dump(c_jsonCompactIndent)));
58 + context.Terminal.Output(L"{}\n", MultiByteToWide(root.dump(c_jsonCompactIndent)));
59 break;
60 }
61 case FormatType::Table:
62 - PrintVersion(context.Reporter);
62 + PrintVersion(context.Terminal);
63 break;
64 default:
65 THROW_HR(E_UNEXPECTED);
src/windows/wslc/commands/VersionCommand.h
+2 -2
@@ -15,7 +15,7 @@ Abstract:
15 #include "Command.h"
16
17 namespace wsl::windows::wslc {
18 -struct Reporter;
18 +struct Terminal;
19 struct VersionCommand final : public Command
20 {
21 constexpr static std::wstring_view CommandName = L"version";
@@ -23,7 +23,7 @@ struct VersionCommand final : public Command
23 {
24 }
25
26 - static void PrintVersion(Reporter& reporter);
26 + static void PrintVersion(Terminal& terminal);
27 std::vector<Argument> GetArguments() const override;
28 std::wstring ShortDescription() const override;
29 std::wstring LongDescription() const override;
src/windows/wslc/commands/VolumeCommand.cpp
+1 -1
@@ -47,6 +47,6 @@ std::wstring VolumeCommand::LongDescription() const
47
48 void VolumeCommand::ExecuteInternal(CLIExecutionContext& context) const
49 {
50 - OutputHelp(context.Reporter);
50 + OutputHelp(context.Terminal);
51 }
52 } // namespace wsl::windows::wslc
src/windows/wslc/core/CLIExecutionContext.cpp
+1 -1
@@ -21,7 +21,7 @@ void CLIExecutionContext::ApplyGlobalOptions()
21 {
22 if (GlobalArgs.GetFlag<ArgType::NoColor>())
23 {
24 - Reporter.SetNoColor(true);
24 + Terminal.SetNoColor(true);
25 }
26 }
27
src/windows/wslc/core/CLIExecutionContext.h
+3 -3
@@ -14,7 +14,7 @@ Abstract:
14 #pragma once
15 #include "ArgumentTypes.h"
16 #include "ExecutionContextData.h"
17 -#include "Reporter.h"
17 +#include "Terminal.h"
18 #include <optional>
19
20 namespace wsl::windows::wslc::execution {
@@ -39,8 +39,8 @@ struct CLIExecutionContext : public wsl::windows::common::ExecutionContext
39 // Map of data stored in the context.
40 DataMap Data;
41
42 - // Central output reporter for all user-facing status messages.
43 - Reporter Reporter;
42 + // Central output terminal for all user-facing status messages.
43 + Terminal Terminal;
44
45 // Process exit code set by tasks like Run/Exec.
46 std::optional<int> ExitCode;
src/windows/wslc/core/Command.cpp
+31 -31
@@ -43,11 +43,11 @@ Command::Command(std::wstring_view name, std::vector<std::wstring_view>&& aliase
43 }
44 }
45
46 -void Command::OutputHelp(Reporter& reporter, const CommandException* exception) const
46 +void Command::OutputHelp(Terminal& terminal, const CommandException* exception) const
47 {
48 constexpr size_t c_helpRowIndent = 2;
49 constexpr size_t c_helpColumnPadding = 2;
50 - const auto helpLevel = exception ? Reporter::Level::Info : Reporter::Level::Output;
50 + const auto helpLevel = exception ? Terminal::Level::Info : Terminal::Level::Output;
51
52 // Emphasis sequences for help output.
53 static const auto& HelpHeadingEmphasis = Format::Bright;
@@ -57,16 +57,16 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
57 static const auto& HelpPlaceholderEmphasis = Format::Fg::BrightCyan;
58
59 // Copyright header (dimmed)
60 - reporter.Write(helpLevel, L"{}{}{}\n\n", HelpMetaEmphasis, Localization::WSLCCLI_CopyrightHeader(), Format::Default);
60 + terminal.Write(helpLevel, L"{}{}{}\n\n", HelpMetaEmphasis, Localization::WSLCCLI_CopyrightHeader(), Format::Default);
61
62 // Error if given
63 if (exception)
64 {
65 - reporter.Error(L"{}\n\n", exception->Message());
65 + terminal.Error(L"{}\n\n", exception->Message());
66 }
67
68 // Description
69 - reporter.Write(helpLevel, L"{}\n\n", LongDescription());
69 + terminal.Write(helpLevel, L"{}\n\n", LongDescription());
70
71 // Build command chain from full name (replace ParentSplitChar with spaces, strip root).
72 std::wstring commandChain = FullName();
@@ -127,20 +127,20 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
127 usageText.pop_back();
128 }
129
130 - reporter.Write(helpLevel, L"{}{}{}", HelpHeadingEmphasis, usageText, Format::Default);
130 + terminal.Write(helpLevel, L"{}{}{}", HelpHeadingEmphasis, usageText, Format::Default);
131
132 if (!commands.empty())
133 {
134 if (!arguments.empty())
135 {
136 - reporter.Write(helpLevel, L" {}[{}", HelpMetaEmphasis, Format::Default);
136 + terminal.Write(helpLevel, L" {}[{}", HelpMetaEmphasis, Format::Default);
137 }
138 else
139 {
140 - reporter.Write(helpLevel, L" ");
140 + terminal.Write(helpLevel, L" ");
141 }
142
143 - reporter.Write(
143 + terminal.Write(
144 helpLevel,
145 L"{}<{}{}{}{}{}>{}",
146 HelpMetaEmphasis,
@@ -152,13 +152,13 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
152 Format::Default);
153 if (!arguments.empty())
154 {
155 - reporter.Write(helpLevel, L"{}]{}", HelpMetaEmphasis, Format::Default);
155 + terminal.Write(helpLevel, L"{}]{}", HelpMetaEmphasis, Format::Default);
156 }
157 }
158
159 if (hasOptions)
160 {
161 - reporter.Write(
161 + terminal.Write(
162 helpLevel,
163 L" {}[<{}{}{}{}{}>]{}",
164 HelpMetaEmphasis,
@@ -172,28 +172,28 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
172
173 for (const auto& arg : positionalArgs)
174 {
175 - reporter.Write(helpLevel, L" ");
175 + terminal.Write(helpLevel, L" ");
176 if (!arg.Required())
177 {
178 - reporter.Write(helpLevel, L"{}[{}", HelpMetaEmphasis, Format::Default);
178 + terminal.Write(helpLevel, L"{}[{}", HelpMetaEmphasis, Format::Default);
179 }
180
181 - reporter.Write(
181 + terminal.Write(
182 helpLevel, L"{}<{}{}{}{}{}>{}", HelpMetaEmphasis, Format::Default, HelpPlaceholderEmphasis, arg.Name(), Format::Default, HelpMetaEmphasis, Format::Default);
183 if (arg.IsUnlimited())
184 {
185 - reporter.Write(helpLevel, L"{}...{}", HelpMetaEmphasis, Format::Default);
185 + terminal.Write(helpLevel, L"{}...{}", HelpMetaEmphasis, Format::Default);
186 }
187
188 if (!arg.Required())
189 {
190 - reporter.Write(helpLevel, L"{}]{}", HelpMetaEmphasis, Format::Default);
190 + terminal.Write(helpLevel, L"{}]{}", HelpMetaEmphasis, Format::Default);
191 }
192 }
193
194 if (hasForwardArgs)
195 {
196 - reporter.Write(
196 + terminal.Write(
197 helpLevel,
198 L" {}[<{}{}{}{}{}>...]{}",
199 HelpMetaEmphasis,
@@ -205,12 +205,12 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
205 Format::Default);
206 }
207
208 - reporter.Write(helpLevel, L"\n\n");
208 + terminal.Write(helpLevel, L"\n\n");
209 }
210
211 if (!commandAliases.empty())
212 {
213 - reporter.Write(helpLevel, L"{}{}{}\n", HelpHeadingEmphasis, Localization::WSLCCLI_HeadingAliases(), Format::Default);
213 + terminal.Write(helpLevel, L"{}{}{}\n", HelpHeadingEmphasis, Localization::WSLCCLI_HeadingAliases(), Format::Default);
214
215 std::wstring aliasLine;
216 for (size_t i = 0; i < commandAliases.size(); ++i)
@@ -222,13 +222,13 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
222 aliasLine += commandAliases[i];
223 }
224
225 - reporter.Write(helpLevel, L"{}{}\n\n", std::wstring(c_helpRowIndent, L' '), aliasLine);
225 + terminal.Write(helpLevel, L"{}{}\n\n", std::wstring(c_helpRowIndent, L' '), aliasLine);
226 }
227
228 // Col0: name/command
229 // Col1: description (word-wraps at computed column width)
230 - const auto MakeHelpTable = [&reporter, helpLevel]() -> TableOutput<2> {
231 - TableOutput<2> table{reporter, {L"", L""}, 50, c_helpColumnPadding, helpLevel};
230 + const auto MakeHelpTable = [&terminal, helpLevel]() -> TableOutput<2> {
231 + TableOutput<2> table{terminal, {L"", L""}, 50, c_helpColumnPadding, helpLevel};
232 table.SetShowHeader(false);
233 table.SetRowIndent(c_helpRowIndent);
234 table.SetColumnConfig(
@@ -243,7 +243,7 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
243
244 if (!commands.empty())
245 {
246 - reporter.Write(helpLevel, L"{}{}{}\n", HelpHeadingEmphasis, Localization::WSLCCLI_HeadingCommands(), Format::Default);
246 + terminal.Write(helpLevel, L"{}{}{}\n", HelpHeadingEmphasis, Localization::WSLCCLI_HeadingCommands(), Format::Default);
247
248 auto table = MakeHelpTable();
249 for (const auto& command : commands)
@@ -255,20 +255,20 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
255 }
256 table.Complete();
257
258 - reporter.Write(helpLevel, L"\n{} [{}]\n", Localization::WSLCCLI_HelpForDetails(), WSLC_CLI_HELP_ARG_STRING);
258 + terminal.Write(helpLevel, L"\n{} [{}]\n", Localization::WSLCCLI_HelpForDetails(), WSLC_CLI_HELP_ARG_STRING);
259 }
260
261 if (!arguments.empty())
262 {
263 if (!commands.empty())
264 {
265 - reporter.Write(helpLevel, L"\n");
265 + terminal.Write(helpLevel, L"\n");
266 }
267
268 // Arguments table: positional and forward args, name (emphasized) | description
269 if (hasArguments || hasForwardArgs)
270 {
271 - reporter.Write(helpLevel, L"{}{}{}\n", HelpHeadingEmphasis, Localization::WSLCCLI_HeadingArguments(), Format::Default);
271 + terminal.Write(helpLevel, L"{}{}{}\n", HelpHeadingEmphasis, Localization::WSLCCLI_HeadingArguments(), Format::Default);
272
273 auto table = MakeHelpTable();
274
@@ -295,8 +295,8 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
295 // Col0: short alias (e.g. "-f")
296 // Col1: long name (e.g. "--force")
297 // Col2: description (word-wraps at computed column width)
298 - const auto MakeOptionsTable = [&reporter, helpLevel]() -> TableOutput<3> {
299 - TableOutput<3> table{reporter, {L"", L"", L""}, {}, 50, c_helpColumnPadding, helpLevel};
298 + const auto MakeOptionsTable = [&terminal, helpLevel]() -> TableOutput<3> {
299 + TableOutput<3> table{terminal, {L"", L"", L""}, {}, 50, c_helpColumnPadding, helpLevel};
300 table.SetShowHeader(false);
301 table.SetRowIndent(c_helpRowIndent);
302 table.SetColumnConfig(
@@ -315,11 +315,11 @@ void Command::OutputHelp(Reporter& reporter, const CommandException* exception)
315 {
316 if (hasArguments || hasForwardArgs)
317 {
318 - reporter.Write(helpLevel, L"\n");
318 + terminal.Write(helpLevel, L"\n");
319 }
320 else if (!commands.empty() && arguments.empty())
321 {
322 - reporter.Write(helpLevel, L"\n");
322 + terminal.Write(helpLevel, L"\n");
323 }
324
325 auto table = MakeOptionsTable();
@@ -461,7 +461,7 @@ void Command::Execute(CLIExecutionContext& context) const
461 // If Help was part of the validated argument set, we will output help instead of executing.
462 if (context.Args.GetFlag<ArgType::Help>())
463 {
464 - OutputHelp(context.Reporter);
464 + OutputHelp(context.Terminal);
465 }
466 else
467 {
src/windows/wslc/core/Command.h
+2 -2
@@ -18,7 +18,7 @@ Abstract:
18 #include "CLIExecutionContext.h"
19 #include "Invocation.h"
20 #include "ArgumentParser.h"
21 -#include "Reporter.h"
21 +#include "Terminal.h"
22
23 #include <memory>
24 #include <optional>
@@ -101,7 +101,7 @@ struct Command
101 virtual std::wstring ShortDescription() const = 0;
102 virtual std::wstring LongDescription() const = 0;
103
104 - void OutputHelp(Reporter& reporter, const CommandException* exception = nullptr) const;
104 + void OutputHelp(Terminal& terminal, const CommandException* exception = nullptr) const;
105
106 std::unique_ptr<Command> FindSubCommand(Invocation& inv) const;
107
src/windows/wslc/core/InputChannel.h
+1 -1
@@ -8,7 +8,7 @@ Module Name:
8
9 Abstract:
10
11 - Byte source used by Reporter for user input. Reads a line at a time from the
11 + Byte source used by Terminal for user input. Reads a line at a time from the
12 console (or a redirected file/pipe). For console sources the channel can mask
13 echo while reading (password entry) and reports whether input is interactive.
14
src/windows/wslc/core/Main.cpp
+4 -4
@@ -138,7 +138,7 @@ try
138 catch (const CommandException& ce)
139 {
140 // Input failure: show help alongside the error so the user can correct it.
141 - command->OutputHelp(context.Reporter, &ce);
141 + command->OutputHelp(context.Terminal, &ce);
142 return 1;
143 }
144 catch (...)
@@ -151,7 +151,7 @@ try
151 // Cancel events are often considered warnings rather than errors, as the user
152 // intentionally triggered it.
153 const auto strings = wslutil::ErrorToString({.Code = HRESULT_FROM_WIN32(ERROR_CANCELLED)});
154 - context.Reporter.Warn(L"\n{}\n", strings.Message);
154 + context.Terminal.Warn(L"\n{}\n", strings.Message);
155
156 // Exit with code 1 is consistent with Docker build and pull, but the POSIX-convention
157 // for cancellation is exit code 130, which is used by Docker compose and most shells.
@@ -170,12 +170,12 @@ try
170 {
171 auto strings = wslutil::ErrorToString(*reported);
172 auto errorMessage = strings.Message.empty() ? strings.Code : strings.Message;
173 - context.Reporter.Error(L"{}\n", Localization::MessageErrorCode(errorMessage, wslutil::ErrorCodeToString(result)));
173 + context.Terminal.Error(L"{}\n", Localization::MessageErrorCode(errorMessage, wslutil::ErrorCodeToString(result)));
174 }
175 else
176 {
177 // Fallback for errors without context
178 - context.Reporter.Error(L"{}\n", Localization::MessageErrorCode(L"", wslutil::ErrorCodeToString(result)));
178 + context.Terminal.Error(L"{}\n", Localization::MessageErrorCode(L"", wslutil::ErrorCodeToString(result)));
179 }
180 }
181 }
src/windows/wslc/core/OutputChannel.h
+1 -1
@@ -8,7 +8,7 @@ Module Name:
8
9 Abstract:
10
11 - Byte sink used by Reporter. Each WriteString call is a single WriteConsoleW
11 + Byte sink used by Terminal. Each WriteString call is a single WriteConsoleW
12 or fwprintf. For console destinations the channel owns VT enablement (RAII).
13
14 --*/
src/windows/wslc/core/TableOutput.h
+22 -22
@@ -11,7 +11,7 @@ Abstract:
11 Structured table output for the WSLC CLI. Cells are either plain text or
12 format-string + Sequence args. Sequences are zero display width; the table
13 measures visible width by counting non-placeholder characters. At render
14 - time, sequences are emitted or stripped based on Reporter color state.
14 + time, sequences are emitted or stripped based on Terminal color state.
15
16 --*/
17 #pragma once
@@ -25,7 +25,7 @@ Abstract:
25 #include <variant>
26 #include <vector>
27 #include <wil/result_macros.h>
28 -#include "Reporter.h"
28 +#include "Terminal.h"
29 #include "VTSupport.h"
30
31 namespace wsl::windows::wslc {
@@ -139,11 +139,11 @@ struct TableOutput
139 // The wrap pass is skipped in that case so the receiver controls its own width.
140 static constexpr size_t DefaultRedirectedConsoleWidth = 2000;
141
142 - TableOutput(Reporter& reporter, header_t&& header, size_t sizingBuffer = 50, size_t columnPadding = DefaultColumnPadding, Reporter::Level level = Reporter::Level::Output) :
143 - m_reporter(reporter),
142 + TableOutput(Terminal& terminal, header_t&& header, size_t sizingBuffer = 50, size_t columnPadding = DefaultColumnPadding, Terminal::Level level = Terminal::Level::Output) :
143 + m_terminal(terminal),
144 m_outputLevel(level),
145 - m_vtEnabled(reporter.IsVTEnabled(level)),
146 - m_colorEnabled(reporter.IsColorEnabled(level)),
145 + m_vtEnabled(terminal.IsVTEnabled(level)),
146 + m_colorEnabled(terminal.IsColorEnabled(level)),
147 m_sizingBuffer(sizingBuffer),
148 m_columnPadding(columnPadding)
149 {
@@ -151,16 +151,16 @@ struct TableOutput
151 }
152
153 TableOutput(
154 - Reporter& reporter,
154 + Terminal& terminal,
155 header_t&& header,
156 column_config_t&& config,
157 size_t sizingBuffer = 50,
158 size_t columnPadding = DefaultColumnPadding,
159 - Reporter::Level level = Reporter::Level::Output) :
160 - m_reporter(reporter),
159 + Terminal::Level level = Terminal::Level::Output) :
160 + m_terminal(terminal),
161 m_outputLevel(level),
162 - m_vtEnabled(reporter.IsVTEnabled(level)),
163 - m_colorEnabled(reporter.IsColorEnabled(level)),
162 + m_vtEnabled(terminal.IsVTEnabled(level)),
163 + m_colorEnabled(terminal.IsColorEnabled(level)),
164 m_sizingBuffer(sizingBuffer),
165 m_columnPadding(columnPadding),
166 m_columnConfigs(std::move(config))
@@ -169,15 +169,15 @@ struct TableOutput
169 }
170
171 TableOutput(
172 - Reporter& reporter,
172 + Terminal& terminal,
173 column_def_t&& columns,
174 size_t sizingBuffer = 50,
175 size_t columnPadding = DefaultColumnPadding,
176 - Reporter::Level level = Reporter::Level::Output) :
177 - m_reporter(reporter),
176 + Terminal::Level level = Terminal::Level::Output) :
177 + m_terminal(terminal),
178 m_outputLevel(level),
179 - m_vtEnabled(reporter.IsVTEnabled(level)),
180 - m_colorEnabled(reporter.IsColorEnabled(level)),
179 + m_vtEnabled(terminal.IsVTEnabled(level)),
180 + m_colorEnabled(terminal.IsColorEnabled(level)),
181 m_sizingBuffer(sizingBuffer),
182 m_columnPadding(columnPadding)
183 {
@@ -214,7 +214,7 @@ struct TableOutput
214 m_rowIndent = spaces;
215 }
216
217 - // Overrides console width for column shrinking; pass 0 to restore default (Reporter-derived).
217 + // Overrides console width for column shrinking; pass 0 to restore default (Terminal-derived).
218 // When set, the wrap pass also runs as if a real console were attached.
219 void SetConsoleWidthOverride(size_t width)
220 {
@@ -288,8 +288,8 @@ private:
288 ColumnOverflow Overflow = ColumnOverflow::Truncate;
289 };
290
291 - Reporter& m_reporter;
292 - Reporter::Level m_outputLevel;
291 + Terminal& m_terminal;
292 + Terminal::Level m_outputLevel;
293 const bool m_vtEnabled;
294 const bool m_colorEnabled;
295 std::array<Column, FieldCount> m_columns;
@@ -359,7 +359,7 @@ private:
359 return m_consoleWidthOverride;
360 }
361
362 - if (const auto width = m_reporter.GetConsoleWidth(m_outputLevel); width.has_value())
362 + if (const auto width = m_terminal.GetConsoleWidth(m_outputLevel); width.has_value())
363 {
364 return static_cast<size_t>(*width);
365 }
@@ -609,7 +609,7 @@ private:
609
610 void OutputCellLineToStream(const FormattedCell& cell)
611 {
612 - m_reporter.Write(m_outputLevel, L"{}\n", cell.Render(m_vtEnabled, m_colorEnabled));
612 + m_terminal.Write(m_outputLevel, L"{}\n", cell.Render(m_vtEnabled, m_colorEnabled));
613 }
614
615 // Renders a logical row, emitting multiple physical rows for word-wrapping columns.
@@ -666,7 +666,7 @@ private:
666 }
667 }
668
669 - m_reporter.Write(m_outputLevel, L"{}\n", rowStr);
669 + m_terminal.Write(m_outputLevel, L"{}\n", rowStr);
670 }
671 }
672 };
src/windows/wslc/core/Terminal.cpp renamed
+10 -10
@@ -4,31 +4,31 @@ Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 - Reporter.cpp
7 + Terminal.cpp
8
9 Abstract:
10
11 - Implementation of Reporter.
11 + Implementation of Terminal.
12
13 --*/
14 #include "precomp.h"
15 -#include "Reporter.h"
15 +#include "Terminal.h"
16
17 namespace wsl::windows::wslc {
18
19 using namespace wsl::windows::common::vt;
20
21 -Reporter::Reporter() :
21 +Terminal::Terminal() :
22 m_out(GetStdHandle(STD_OUTPUT_HANDLE), stdout), m_err(GetStdHandle(STD_ERROR_HANDLE), stderr), m_in(GetStdHandle(STD_INPUT_HANDLE), stdin)
23 {
24 }
25
26 -Reporter::Reporter(FILE* outFile, bool outVtEnabled, FILE* errFile, bool errVtEnabled, FILE* inFile, bool inInteractive) :
26 +Terminal::Terminal(FILE* outFile, bool outVtEnabled, FILE* errFile, bool errVtEnabled, FILE* inFile, bool inInteractive) :
27 m_out(outFile, outVtEnabled), m_err(errFile, errVtEnabled), m_in(inFile, inInteractive)
28 {
29 }
30
31 -std::wstring_view Reporter::LevelPrefix(Level level) const noexcept
31 +std::wstring_view Terminal::LevelPrefix(Level level) const noexcept
32 {
33 if (!IsColorEnabled(level))
34 {
@@ -46,22 +46,22 @@ std::wstring_view Reporter::LevelPrefix(Level level) const noexcept
46 }
47 }
48
49 -bool Reporter::IsVTEnabled(Level level) const noexcept
49 +bool Terminal::IsVTEnabled(Level level) const noexcept
50 {
51 return ChannelFor(level).IsVTEnabled();
52 }
53
54 -bool Reporter::IsColorEnabled(Level level) const noexcept
54 +bool Terminal::IsColorEnabled(Level level) const noexcept
55 {
56 return ChannelFor(level).IsVTEnabled() && !m_noColor;
57 }
58
59 -std::optional<int> Reporter::GetConsoleWidth(Level level) const
59 +std::optional<int> Terminal::GetConsoleWidth(Level level) const
60 {
61 return ChannelFor(level).GetConsoleWidth();
62 }
63
64 -std::wstring Reporter::PromptForLine(Level level, std::wstring_view label, bool mask)
64 +std::wstring Terminal::PromptForLine(Level level, std::wstring_view label, bool mask)
65 {
66 // Write the label without a trailing newline so the cursor stays inline (matching
67 // Docker's prompt behavior), then flush so it reaches the user before the blocking read.
src/windows/wslc/core/Terminal.h renamed
+10 -10
@@ -4,7 +4,7 @@ Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 - Reporter.h
7 + Terminal.h
8
9 Abstract:
10
@@ -31,7 +31,7 @@ Abstract:
31
32 namespace wsl::windows::wslc {
33
34 -namespace reporter_detail {
34 +namespace terminal_detail {
35
36 // SFINAE: excludes Sequence-derived types so the overload below wins for them.
37 template <typename T, typename = std::enable_if_t<!std::is_base_of_v<wsl::windows::common::vt::Sequence, std::remove_cvref_t<T>>>>
@@ -55,9 +55,9 @@ namespace reporter_detail {
55 return sequence.Get();
56 }
57
58 -} // namespace reporter_detail
58 +} // namespace terminal_detail
59
60 -struct Reporter
60 +struct Terminal
61 {
62 enum class Level
63 {
@@ -67,13 +67,13 @@ struct Reporter
67 Error,
68 };
69
70 - Reporter();
71 - Reporter(FILE* outFile, bool outVtEnabled, FILE* errFile, bool errVtEnabled, FILE* inFile = nullptr, bool inInteractive = false);
70 + Terminal();
71 + Terminal(FILE* outFile, bool outVtEnabled, FILE* errFile, bool errVtEnabled, FILE* inFile = nullptr, bool inInteractive = false);
72
73 - NON_COPYABLE(Reporter);
74 - NON_MOVABLE(Reporter);
73 + NON_COPYABLE(Terminal);
74 + NON_MOVABLE(Terminal);
75
76 - ~Reporter() = default;
76 + ~Terminal() = default;
77
78 // std::format-style write API.
79 template <typename... Args>
@@ -168,7 +168,7 @@ private:
168 const bool colorEnabled = vtEnabled && !m_noColor;
169
170 // Materialize stripped args into stable storage for vformat.
171 - auto stripped = std::tuple{reporter_detail::StripIfDisabled(std::forward<Args>(args), vtEnabled, colorEnabled)...};
171 + auto stripped = std::tuple{terminal_detail::StripIfDisabled(std::forward<Args>(args), vtEnabled, colorEnabled)...};
172
173 std::wstring body = std::apply(
174 [&fmt](auto&... values) { return std::vformat(std::wstring_view{fmt.get()}, std::make_wformat_args(values...)); }, stripped);
src/windows/wslc/services/BuildImageCallback.cpp
+9 -9
@@ -41,7 +41,7 @@ try
41 {
42 for (const auto& line : m_allLines)
43 {
44 - m_reporter.Info(L"{}", line);
44 + m_terminal.Info(L"{}", line);
45 }
46 }
47 }
@@ -57,7 +57,7 @@ void BuildImageCallback::CollapseWindow()
57 if (m_displayedLines > 0)
58 {
59 // Move cursor up to the start of the display area, then erase to end of screen.
60 - m_reporter.Info(L"{}{}", Cursor::Up(m_displayedLines), Erase::ScreenForward);
60 + m_terminal.Info(L"{}{}", Cursor::Up(m_displayedLines), Erase::ScreenForward);
61 m_displayedLines = 0;
62 }
63
@@ -100,7 +100,7 @@ try
100 // Skip pull progress updates when output is redirected, show only major steps
101 if (!isPullProgress)
102 {
103 - m_reporter.Info(L"{}", status);
103 + m_terminal.Info(L"{}", status);
104 }
105 return S_OK;
106 }
@@ -174,16 +174,16 @@ try
174 const auto newlines = wide.substr(bodyLength);
175 wide.resize(bodyLength);
176
177 - // Pass the color sequences as arguments (not baked into the string) so Reporter strips
177 + // Pass the color sequences as arguments (not baked into the string) so Terminal strips
178 // them when --no-color is set. The trailing newlines are emitted after the reset.
179 - m_reporter.Info(L"{}{}{}{}", Format::Fg::BrightGreen, wide, Format::Default, newlines);
179 + m_terminal.Info(L"{}{}{}{}", Format::Fg::BrightGreen, wide, Format::Default, newlines);
180 return S_OK;
181 }
182 CATCH_RETURN();
183
184 void BuildImageCallback::Redraw()
185 {
186 - const int consoleWidth = m_reporter.GetConsoleWidth(Reporter::Level::Info).value_or(c_fallbackConsoleWidth);
186 + const int consoleWidth = m_terminal.GetConsoleWidth(Terminal::Level::Info).value_or(c_fallbackConsoleWidth);
187
188 const bool showPending = !m_pendingLine.empty();
189 const int pullCount = static_cast<int>(m_pullLines.size());
@@ -198,7 +198,7 @@ void BuildImageCallback::Redraw()
198 // Build the frame body in one buffer to minimize console writes. The cursor moves,
199 // erases, and text lines it holds are non-color VT that only runs when a VT console is
200 // attached. The cursor hide/show wrapper and the dim intensity attribute are passed as
201 - // Sequence arguments to Reporter (below) so it strips the color ones (Dim/Normal) when
201 + // Sequence arguments to Terminal (below) so it strips the color ones (Dim/Normal) when
202 // --no-color is set, while leaving the non-color cursor moves intact.
203 //
204 // m_frameBuffer is a member so its backing allocation is reused across frames -
@@ -249,9 +249,9 @@ void BuildImageCallback::Redraw()
249 }
250
251 // Emit the frame as a single atomic write. Cursor Hide/Show are non-color and always
252 - // rendered here (VT is on); Format::Dim/Normal are color sequences that Reporter strips
252 + // rendered here (VT is on); Format::Dim/Normal are color sequences that Terminal strips
253 // under --no-color. The buffered body carries the cursor moves, erases, and text lines.
254 - m_reporter.Info(L"{}{}{}{}{}", Cursor::Hide, Format::Dim, std::wstring_view{m_frameBuffer}, Format::Normal, Cursor::Show);
254 + m_terminal.Info(L"{}{}{}{}{}", Cursor::Hide, Format::Dim, std::wstring_view{m_frameBuffer}, Format::Normal, Cursor::Show);
255 m_displayedLines = displayCount;
256 }
257
src/windows/wslc/services/BuildImageCallback.h
+5 -5
@@ -12,7 +12,7 @@ Abstract:
12
13 --*/
14 #pragma once
15 -#include "Reporter.h"
15 +#include "Terminal.h"
16 #include "SessionService.h"
17 #include "VTSupport.h"
18 #include <deque>
@@ -24,8 +24,8 @@ class DECLSPEC_UUID("3EDD5DBF-CA6C-4CF7-923A-AD94B6A732E5") BuildImageCallback
24 {
25 public:
26 // The cancel event handle must remain valid for the lifetime of this callback.
27 - BuildImageCallback(Reporter& reporter, HANDLE cancelEvent, bool verbose) :
28 - m_reporter(reporter), m_verbose(verbose), m_cancelEvent(cancelEvent)
27 + BuildImageCallback(Terminal& terminal, HANDLE cancelEvent, bool verbose) :
28 + m_terminal(terminal), m_verbose(verbose), m_cancelEvent(cancelEvent)
29 {
30 }
31 ~BuildImageCallback();
@@ -41,10 +41,10 @@ private:
41 void RedrawIfNeeded();
42 bool IsCancelled() const;
43
44 - Reporter& m_reporter;
44 + Terminal& m_terminal;
45 const bool m_verbose;
46 const HANDLE m_cancelEvent;
47 - bool m_isConsole = m_reporter.IsVTEnabled(Reporter::Level::Info);
47 + bool m_isConsole = m_terminal.IsVTEnabled(Terminal::Level::Info);
48 std::deque<std::string> m_lines;
49 // Each entry already contains the trailing newline so the bytes match what's replayed.
50 // TODO: Track logs per step so the destructor can replay only the failing step's
src/windows/wslc/services/ConsoleService.cpp
+2 -2
@@ -178,13 +178,13 @@ void ConsoleService::RelayNonTtyProcess(wil::unique_handle&& Stdin, wil::unique_
178 }
179
180 int ConsoleService::AttachToCurrentConsole(
181 - Reporter& reporter, wsl::windows::common::ConsoleState& console, wsl::windows::common::ClientRunningWSLCProcess&& process, bool triggerRefresh)
181 + Terminal& terminal, wsl::windows::common::ConsoleState& console, wsl::windows::common::ClientRunningWSLCProcess&& process, bool triggerRefresh)
182 {
183 if (WI_IsFlagSet(process.Flags(), WSLCProcessFlagsTty))
184 {
185 if (!RelayInteractiveTty(console, process, process.GetStdHandle(WSLCFDTty).get(), triggerRefresh))
186 {
187 - reporter.Info(L"[detached]\n");
187 + terminal.Info(L"[detached]\n");
188 return 0;
189 }
190 }
src/windows/wslc/services/ConsoleService.h
+2 -2
@@ -16,14 +16,14 @@ Abstract:
16 #include <wslc.h>
17 #include <WSLCContainerLauncher.h>
18 #include <ConsoleState.h>
19 -#include "Reporter.h"
19 +#include "Terminal.h"
20
21 namespace wsl::windows::wslc::services {
22 class ConsoleService
23 {
24 public:
25 static int AttachToCurrentConsole(
26 - Reporter& reporter, wsl::windows::common::ConsoleState& console, wsl::windows::common::ClientRunningWSLCProcess&& process, bool triggerRefresh = false);
26 + Terminal& terminal, wsl::windows::common::ConsoleState& console, wsl::windows::common::ClientRunningWSLCProcess&& process, bool triggerRefresh = false);
27 static bool RelayInteractiveTty(
28 wsl::windows::common::ConsoleState& console, wsl::windows::common::ClientRunningWSLCProcess& process, HANDLE tty, bool triggerRefresh = false);
29 static void RelayNonTtyProcess(wil::unique_handle&& Stdin, wil::unique_handle&& Stdout, wil::unique_handle&& Stderr);
src/windows/wslc/services/ContainerService.cpp
+19 -19
@@ -41,9 +41,9 @@ static void SetContainerArguments(WSLCProcessOptions& options, std::vector<const
41 options.CommandLine = {.Values = argsStorage.data(), .Count = static_cast<ULONG>(argsStorage.size())};
42 }
43
44 -static wsl::windows::common::RunningWSLCContainer CreateInternal(Reporter& reporter, Session& session, const std::string& image, const ContainerOptions& options)
44 +static wsl::windows::common::RunningWSLCContainer CreateInternal(Terminal& terminal, Session& session, const std::string& image, const ContainerOptions& options)
45 {
46 - WarningCallback warningCallback(reporter);
46 + WarningCallback warningCallback(terminal);
47
48 auto processFlags = WSLCProcessFlagsNone;
49 WI_SetFlagIf(processFlags, WSLCProcessFlagsStdin, options.Interactive);
@@ -250,10 +250,10 @@ static wsl::windows::common::RunningWSLCContainer CreateInternal(Reporter& repor
250 {
251 // Implicit pull for run/create: progress goes to Info (stderr), keeping stdout for the
252 // container id/output.
253 - ImageProgressCallback callback(reporter, Reporter::Level::Info);
254 - reporter.Info(L"{}\n", Localization::WSLCCLI_ImageNotFoundPulling(wsl::shared::string::MultiByteToWide(image)));
253 + ImageProgressCallback callback(terminal, Terminal::Level::Info);
254 + terminal.Info(L"{}\n", Localization::WSLCCLI_ImageNotFoundPulling(wsl::shared::string::MultiByteToWide(image)));
255 ImageService imageService;
256 - imageService.Pull(reporter, session, image, &callback);
256 + imageService.Pull(terminal, session, image, &callback);
257 }
258 return containerLauncher.Create(*session.Get(), &warningCallback);
259 }
@@ -325,7 +325,7 @@ std::wstring ContainerService::FormatRelativeTime(ULONGLONG timestamp)
325 return pluralize(elapsed / SecondsPerYear, L"year", L"years");
326 }
327
328 -int ContainerService::Attach(Reporter& reporter, Session& session, const std::string& id)
328 +int ContainerService::Attach(Terminal& terminal, Session& session, const std::string& id)
329 {
330 [[maybe_unused]] auto operation = session.BeginContainerOperation();
331 wil::com_ptr<IWSLCContainer> container;
@@ -357,7 +357,7 @@ int ContainerService::Attach(Reporter& reporter, Session& session, const std::st
357 wsl::windows::common::ConsoleState console;
358 if (!ConsoleService::RelayInteractiveTty(console, runningProcess, stdinLogs.Release().get(), true))
359 {
360 - reporter.Info(L"[detached]\n");
360 + terminal.Info(L"[detached]\n");
361 return 0; // Exit early if user detached
362 }
363 }
@@ -427,7 +427,7 @@ std::wstring ContainerService::FormatPorts(WSLCContainerState state, const std::
427 return result;
428 }
429
430 -int ContainerService::Run(Reporter& reporter, Session& session, const std::string& image, ContainerOptions runOptions)
430 +int ContainerService::Run(Terminal& terminal, Session& session, const std::string& image, ContainerOptions runOptions)
431 {
432 // Reserve the CID file (fails if it already exists) before creating the container so a
433 // container isn't created when the caller-requested path can't be written. The file is
@@ -435,7 +435,7 @@ int ContainerService::Run(Reporter& reporter, Session& session, const std::strin
435 CidFile cidFile(runOptions.CidFile);
436
437 // Create the container
438 - auto runningContainer = CreateInternal(reporter, session, image, runOptions);
438 + auto runningContainer = CreateInternal(terminal, session, image, runOptions);
439 auto& container = runningContainer.Get();
440
441 WSLCContainerId containerId{};
@@ -457,7 +457,7 @@ int ContainerService::Run(Reporter& reporter, Session& session, const std::strin
457 startOptions.TtyColumns = size.X;
458 }
459
460 - WarningCallback warningCallback(reporter);
460 + WarningCallback warningCallback(terminal);
461 THROW_IF_FAILED(container.Start(startFlags, &startOptions, &warningCallback)); // TODO: detach keys
462
463 // Disable auto-delete only after successful start
@@ -467,17 +467,17 @@ int ContainerService::Run(Reporter& reporter, Session& session, const std::strin
467 // Handle attach if requested
468 if (attach)
469 {
470 - return ConsoleService::AttachToCurrentConsole(reporter, console, runningContainer.GetInitProcess());
470 + return ConsoleService::AttachToCurrentConsole(terminal, console, runningContainer.GetInitProcess());
471 }
472
473 - reporter.Output(L"{}\n", wsl::shared::string::MultiByteToWide(containerId));
473 + terminal.Output(L"{}\n", wsl::shared::string::MultiByteToWide(containerId));
474 return 0;
475 }
476
477 -CreateContainerResult ContainerService::Create(Reporter& reporter, Session& session, const std::string& image, ContainerOptions runOptions)
477 +CreateContainerResult ContainerService::Create(Terminal& terminal, Session& session, const std::string& image, ContainerOptions runOptions)
478 {
479 CidFile cidFile(runOptions.CidFile);
480 - auto runningContainer = CreateInternal(reporter, session, image, runOptions);
480 + auto runningContainer = CreateInternal(terminal, session, image, runOptions);
481 runningContainer.SetDeleteOnClose(false);
482 auto& container = runningContainer.Get();
483 WSLCContainerId id{};
@@ -486,7 +486,7 @@ CreateContainerResult ContainerService::Create(Reporter& reporter, Session& sess
486 return {.Id = id};
487 }
488
489 -int ContainerService::Start(Reporter& reporter, Session& session, const std::string& id, bool attach)
489 +int ContainerService::Start(Terminal& terminal, Session& session, const std::string& id, bool attach)
490 {
491 [[maybe_unused]] auto operation = session.BeginContainerOperation();
492 wil::com_ptr<IWSLCContainer> container;
@@ -499,7 +499,7 @@ int ContainerService::Start(Reporter& reporter, Session& session, const std::str
499 startOptions.TtyRows = size.Y;
500 startOptions.TtyColumns = size.X;
501
502 - WarningCallback warningCallback(reporter);
502 + WarningCallback warningCallback(terminal);
503 THROW_IF_FAILED_EXCEPT(container->Start(flags, &startOptions, &warningCallback), WSLC_E_CONTAINER_IS_RUNNING);
504
505 if (!attach)
@@ -514,7 +514,7 @@ int ContainerService::Start(Reporter& reporter, Session& session, const std::str
514 THROW_IF_FAILED(process->GetFlags(&processFlags));
515 ClientRunningWSLCProcess runningProcess(std::move(process), processFlags);
516
517 - return ConsoleService::AttachToCurrentConsole(reporter, console, std::move(runningProcess), true);
517 + return ConsoleService::AttachToCurrentConsole(terminal, console, std::move(runningProcess), true);
518 }
519
520 void ContainerService::Stop(Session& session, const std::string& id, StopContainerOptions options)
@@ -592,7 +592,7 @@ std::vector<ContainerInformation> ContainerService::List(
592 return result;
593 }
594
595 -int ContainerService::Exec(Reporter& reporter, Session& session, const std::string& id, ContainerOptions options)
595 +int ContainerService::Exec(Terminal& terminal, Session& session, const std::string& id, ContainerOptions options)
596 {
597 [[maybe_unused]] auto operation = session.BeginContainerOperation();
598 wil::com_ptr<IWSLCContainer> container;
@@ -621,7 +621,7 @@ int ContainerService::Exec(Reporter& reporter, Session& session, const std::stri
621 processLauncher.SetWorkingDirectory(std::move(options.WorkingDirectory));
622 }
623
624 - return ConsoleService::AttachToCurrentConsole(reporter, console, processLauncher.Launch(*container));
624 + return ConsoleService::AttachToCurrentConsole(terminal, console, processLauncher.Launch(*container));
625 }
626
627 InspectContainer ContainerService::Inspect(Session& session, const std::string& id)
src/windows/wslc/services/ContainerService.h
+6 -6
@@ -14,7 +14,7 @@ Abstract:
14 #pragma once
15 #include "SessionModel.h"
16 #include "ContainerModel.h"
17 -#include "Reporter.h"
17 +#include "Terminal.h"
18 #include <docker_schema.h>
19 #include <wslc.h>
20 #include <wslc_schema.h>
@@ -25,17 +25,17 @@ struct ContainerService
25 static std::wstring ContainerStateToString(WSLCContainerState state, ULONGLONG stateChangedAt = 0);
26 static std::wstring FormatRelativeTime(ULONGLONG timestamp);
27 static std::wstring FormatPorts(WSLCContainerState state, const std::vector<models::PortInformation>& ports);
28 - static int Attach(Reporter& reporter, models::Session& session, const std::string& id);
29 - static int Run(Reporter& reporter, models::Session& session, const std::string& image, models::ContainerOptions options);
30 - static models::CreateContainerResult Create(Reporter& reporter, models::Session& session, const std::string& image, models::ContainerOptions options);
31 - static int Start(Reporter& reporter, models::Session& session, const std::string& id, bool attach = false);
28 + static int Attach(Terminal& terminal, models::Session& session, const std::string& id);
29 + static int Run(Terminal& terminal, models::Session& session, const std::string& image, models::ContainerOptions options);
30 + static models::CreateContainerResult Create(Terminal& terminal, models::Session& session, const std::string& image, models::ContainerOptions options);
31 + static int Start(Terminal& terminal, models::Session& session, const std::string& id, bool attach = false);
32 static void Stop(models::Session& session, const std::string& id, models::StopContainerOptions options);
33 static void Kill(models::Session& session, const std::string& id, WSLCSignal signal = WSLCSignalSIGKILL);
34 static void Delete(models::Session& session, const std::string& id, bool force, bool deleteVolumes = false);
35 static std::vector<models::ContainerInformation> List(
36 models::Session& session, bool all = false, int limit = -1, const std::vector<std::pair<std::string, std::string>>& filters = {});
37
38 - static int Exec(Reporter& reporter, models::Session& session, const std::string& id, models::ContainerOptions options);
38 + static int Exec(Terminal& terminal, models::Session& session, const std::string& id, models::ContainerOptions options);
39 static void Export(models::Session& session, const std::string& id, const std::wstring& outputPath);
40 static void Export(models::Session& session, const std::string& id, HANDLE outputHandle);
41 static void CopyToContainer(models::Session& session, const std::string& id, const std::string& destPath, HANDLE inputHandle, ULONGLONG contentSize);
src/windows/wslc/services/ImageProgressCallback.cpp
+10 -10
@@ -30,7 +30,7 @@ auto ImageProgressCallback::MoveToLine(int line)
30 {
31 if (line > 0)
32 {
33 - m_reporter.Write(m_level, L"{}", Cursor::Up(line));
33 + m_terminal.Write(m_level, L"{}", Cursor::Up(line));
34 }
35
36 // scope_exit is noexcept and may fire during unwinding; scope_exit_log swallows output
@@ -38,7 +38,7 @@ auto ImageProgressCallback::MoveToLine(int line)
38 return wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [line = line, this]() {
39 if (line > 1)
40 {
41 - m_reporter.Write(m_level, L"{}", Cursor::Down(line - 1));
41 + m_terminal.Write(m_level, L"{}", Cursor::Down(line - 1));
42 }
43 });
44 }
@@ -57,7 +57,7 @@ HRESULT ImageProgressCallback::OnProgress(LPCSTR status, LPCSTR id, ULONGLONG cu
57 {
58 if (id == nullptr || *id == '\0')
59 {
60 - m_reporter.Write(m_level, L"{}\n", status);
60 + m_terminal.Write(m_level, L"{}\n", status);
61 }
62 else
63 {
@@ -65,7 +65,7 @@ HRESULT ImageProgressCallback::OnProgress(LPCSTR status, LPCSTR id, ULONGLONG cu
65 if (inserted || it->second != status)
66 {
67 it->second = status;
68 - m_reporter.Write(m_level, L"{}: {}\n", id, status);
68 + m_terminal.Write(m_level, L"{}: {}\n", id, status);
69 }
70 }
71
@@ -74,30 +74,30 @@ HRESULT ImageProgressCallback::OnProgress(LPCSTR status, LPCSTR id, ULONGLONG cu
74
75 // Hide the cursor while rendering so it doesn't bounce through the movements; scope_exit_log
76 // restores it on every exit path and can't call std::terminate during unwinding.
77 - m_reporter.Write(m_level, L"{}", Cursor::Hide);
78 - auto showCursor = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [this]() { m_reporter.Write(m_level, L"{}", Cursor::Show); });
77 + m_terminal.Write(m_level, L"{}", Cursor::Hide);
78 + auto showCursor = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [this]() { m_terminal.Write(m_level, L"{}", Cursor::Show); });
79
80 if (id == nullptr || *id == '\0') // Print all 'global' statuses on their own line
81 {
82 - m_reporter.Write(m_level, L"{}\n", status);
82 + m_terminal.Write(m_level, L"{}\n", status);
83 m_currentLine++;
84 return S_OK;
85 }
86
87 - const int visibleWidth = m_reporter.GetConsoleWidth(m_level).value_or(c_fallbackConsoleWidth);
87 + const int visibleWidth = m_terminal.GetConsoleWidth(m_level).value_or(c_fallbackConsoleWidth);
88
89 auto it = m_statuses.find(id);
90 if (it == m_statuses.end())
91 {
92 // If this is the first time we see this ID, create a new line for it.
93 m_statuses.emplace(id, m_currentLine);
94 - m_reporter.Write(m_level, L"{}\n", GenerateStatusLine(status, id, current, total, visibleWidth));
94 + m_terminal.Write(m_level, L"{}\n", GenerateStatusLine(status, id, current, total, visibleWidth));
95 m_currentLine++;
96 }
97 else
98 {
99 auto revert = MoveToLine(m_currentLine - it->second);
100 - m_reporter.Write(m_level, L"{}\n", GenerateStatusLine(status, id, current, total, visibleWidth));
100 + m_terminal.Write(m_level, L"{}\n", GenerateStatusLine(status, id, current, total, visibleWidth));
101 }
102
103 return S_OK;
src/windows/wslc/services/ImageProgressCallback.h
+5 -5
@@ -12,7 +12,7 @@ Abstract:
12
13 --*/
14 #pragma once
15 -#include "Reporter.h"
15 +#include "Terminal.h"
16 #include "SessionService.h"
17 #include "VTSupport.h"
18 #include <map>
@@ -27,7 +27,7 @@ class DECLSPEC_UUID("7A1D3376-835A-471A-8DC9-23653D9962D0") ImageProgressCallbac
27 public:
28 // level selects the target stream: Output (stdout) for standalone pull/push, Info (stderr) for
29 // the implicit pull during run/create, matching Docker.
30 - ImageProgressCallback(Reporter& reporter, Reporter::Level level) : m_reporter(reporter), m_level(level)
30 + ImageProgressCallback(Terminal& terminal, Terminal::Level level) : m_terminal(terminal), m_level(level)
31 {
32 }
33 HRESULT OnProgress(LPCSTR status, LPCSTR id, ULONGLONG current, ULONGLONG total) override;
@@ -35,14 +35,14 @@ public:
35 private:
36 auto MoveToLine(int line);
37 std::wstring GenerateStatusLine(LPCSTR status, LPCSTR id, ULONGLONG current, ULONGLONG total, int visibleWidth);
38 - Reporter& m_reporter;
38 + Terminal& m_terminal;
39 // Declared before m_vtEnabled, whose initializer reads it.
40 - const Reporter::Level m_level;
40 + const Terminal::Level m_level;
41 std::map<std::string, int> m_statuses;
42 // Last status text per id; used only when redirected to dedupe repeated byte-progress callbacks.
43 std::map<std::string, std::string> m_lastStatusById;
44 int m_currentLine = 0;
45 // The progress display only renders on a VT console.
46 - bool m_vtEnabled = m_reporter.IsVTEnabled(m_level);
46 + bool m_vtEnabled = m_terminal.IsVTEnabled(m_level);
47 };
48 } // namespace wsl::windows::wslc::services
src/windows/wslc/services/ImageService.cpp
+8 -8
@@ -331,16 +331,16 @@ std::vector<ImageInformation> ImageService::List(
331 return result;
332 }
333
334 -void ImageService::Load(Reporter& reporter, wsl::windows::wslc::models::Session& session, const std::wstring& input, IImageLoadCallback* callback)
334 +void ImageService::Load(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::wstring& input, IImageLoadCallback* callback)
335 {
336 - WarningCallback warningCallback(reporter);
336 + WarningCallback warningCallback(terminal);
337 auto source = OpenImageInput(input);
338 THROW_IF_FAILED(session.Get()->LoadImage(ToCOMInputHandle(source.Handle.Get()), source.ContentLength, &warningCallback, callback));
339 }
340
341 -std::string ImageService::Import(Reporter& reporter, wsl::windows::wslc::models::Session& session, const std::wstring& input, const std::string& imageName)
341 +std::string ImageService::Import(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::wstring& input, const std::string& imageName)
342 {
343 - WarningCallback warningCallback(reporter);
343 + WarningCallback warningCallback(terminal);
344 auto source = OpenImageInput(input);
345 wil::unique_cotaskmem_ansistring imageId;
346 THROW_IF_FAILED(session.Get()->ImportImage(
@@ -367,9 +367,9 @@ void ImageService::Delete(wsl::windows::wslc::models::Session& session, const st
367 THROW_IF_FAILED(session.Get()->DeleteImage(&options, &deletedImages, deletedImages.size_address<ULONG>()));
368 }
369
370 -void ImageService::Pull(Reporter& reporter, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback)
370 +void ImageService::Pull(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback)
371 {
372 - WarningCallback warningCallback(reporter);
372 + WarningCallback warningCallback(terminal);
373 auto server = GetServerFromImage(image);
374 auto auth = RegistryService::Get(server);
375 THROW_IF_FAILED(session.Get()->PullImage(image.c_str(), auth.c_str(), callback, &warningCallback));
@@ -398,9 +398,9 @@ InspectImage ImageService::Inspect(wsl::windows::wslc::models::Session& session,
398 return wsl::shared::FromJson<InspectImage>(inspectData.get());
399 }
400
401 -void ImageService::Push(Reporter& reporter, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback)
401 +void ImageService::Push(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback)
402 {
403 - WarningCallback warningCallback(reporter);
403 + WarningCallback warningCallback(terminal);
404 auto server = GetServerFromImage(image);
405 auto auth = RegistryService::Get(server);
406 THROW_IF_FAILED(session.Get()->PushImage(image.c_str(), auth.c_str(), callback, &warningCallback));
src/windows/wslc/services/ImageService.h
+5 -5
@@ -15,7 +15,7 @@ Abstract:
15
16 #include "SessionModel.h"
17 #include "ImageModel.h"
18 -#include "Reporter.h"
18 +#include "Terminal.h"
19 #include <map>
20 #include <optional>
21 #include <vector>
@@ -64,12 +64,12 @@ public:
64
65 static std::vector<wsl::windows::wslc::models::ImageInformation> List(
66 wsl::windows::wslc::models::Session& session, const std::vector<std::pair<std::string, std::string>>& filters = {});
67 - static void Load(Reporter& reporter, wsl::windows::wslc::models::Session& session, const std::wstring& input, IImageLoadCallback* callback = nullptr);
68 - static std::string Import(Reporter& reporter, wsl::windows::wslc::models::Session& session, const std::wstring& input, const std::string& imageName);
67 + static void Load(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::wstring& input, IImageLoadCallback* callback = nullptr);
68 + static std::string Import(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::wstring& input, const std::string& imageName);
69 static void Delete(wsl::windows::wslc::models::Session& session, const std::string& image, bool force, bool noPrune);
70 static wsl::windows::common::wslc_schema::InspectImage Inspect(wsl::windows::wslc::models::Session& session, const std::string& image);
71 - static void Pull(Reporter& reporter, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback);
72 - static void Push(Reporter& reporter, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback);
71 + static void Pull(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback);
72 + static void Push(Terminal& terminal, wsl::windows::wslc::models::Session& session, const std::string& image, IProgressCallback* callback);
73 static void Save(wsl::windows::wslc::models::Session& session, const std::vector<std::string>& images, const std::wstring& output, HANDLE cancelEvent = nullptr);
74 static void Save(wsl::windows::wslc::models::Session& session, const std::vector<std::string>& images, HANDLE outputHandle, HANDLE cancelEvent = nullptr);
75 static void Tag(wsl::windows::wslc::models::Session& session, const std::string& sourceImage, const std::string& targetImage);
src/windows/wslc/services/NetworkService.cpp
+2 -2
@@ -22,9 +22,9 @@ using namespace wsl::windows::common::wslutil;
22
23 namespace wsl::windows::wslc::services {
24
25 -void NetworkService::Create(Reporter& reporter, models::Session& session, const models::CreateNetworkOptions& createOptions)
25 +void NetworkService::Create(Terminal& terminal, models::Session& session, const models::CreateNetworkOptions& createOptions)
26 {
27 - WarningCallback warningCallback(reporter);
27 + WarningCallback warningCallback(terminal);
28 WSLCNetworkOptions options{};
29 options.Name = createOptions.Name.c_str();
30 if (createOptions.Driver.has_value())
src/windows/wslc/services/NetworkService.h
+2 -2
@@ -15,14 +15,14 @@ Abstract:
15
16 #include "SessionModel.h"
17 #include "NetworkModel.h"
18 -#include "Reporter.h"
18 +#include "Terminal.h"
19 #include <wslc.h>
20 #include <wslc_schema.h>
21
22 namespace wsl::windows::wslc::services {
23 struct NetworkService
24 {
25 - static void Create(Reporter& reporter, models::Session& session, const models::CreateNetworkOptions& createOptions);
25 + static void Create(Terminal& terminal, models::Session& session, const models::CreateNetworkOptions& createOptions);
26 static void Delete(models::Session& session, const std::string& name);
27 static std::vector<WSLCNetworkInformation> List(models::Session& session);
28 static wsl::windows::common::wslc_schema::Network Inspect(models::Session& session, const std::string& name);
src/windows/wslc/services/SessionService.cpp
+13 -13
@@ -52,9 +52,9 @@ Session SessionService::OpenDefaultSession()
52 return OpenSessionByName(CreateSessionManager(), nullptr);
53 }
54
55 -Session SessionService::OpenOrCreateDefaultSession(Reporter& reporter)
55 +Session SessionService::OpenOrCreateDefaultSession(Terminal& terminal)
56 {
57 - WarningCallback warningCallback(reporter);
57 + WarningCallback warningCallback(terminal);
58 auto manager = CreateSessionManager();
59
60 // Null Settings = default session with server-determined name and settings. The warning callback
@@ -66,7 +66,7 @@ Session SessionService::OpenOrCreateDefaultSession(Reporter& reporter)
66 return Session(std::move(session));
67 }
68
69 -int SessionService::Attach(Reporter& reporter, const Session& session)
69 +int SessionService::Attach(Terminal& terminal, const Session& session)
70 {
71 // Configure console for interactive usage.
72 wsl::windows::common::ConsoleState console{};
@@ -115,23 +115,23 @@ int SessionService::Attach(Reporter& reporter, const Session& session)
115
116 auto exitCode = process.GetExitCode();
117
118 - reporter.Output(L"{}\n", wsl::shared::Localization::MessageWslcShellExited(string::MultiByteToWide(shell), static_cast<int>(exitCode)));
118 + terminal.Output(L"{}\n", wsl::shared::Localization::MessageWslcShellExited(string::MultiByteToWide(shell), static_cast<int>(exitCode)));
119
120 return static_cast<int>(exitCode);
121 }
122
123 -int SessionService::Enter(Reporter& reporter, const std::wstring& storagePath, const std::wstring& displayName)
123 +int SessionService::Enter(Terminal& terminal, const std::wstring& storagePath, const std::wstring& displayName)
124 {
125 THROW_HR_IF(E_INVALIDARG, storagePath.empty());
126 THROW_HR_IF(E_INVALIDARG, displayName.empty());
127
128 - WarningCallback warningCallback(reporter);
128 + WarningCallback warningCallback(terminal);
129 auto sessionManager = CreateSessionManager();
130
131 wil::com_ptr<IWSLCSession> session;
132 THROW_IF_FAILED(sessionManager->EnterSession(displayName.c_str(), storagePath.c_str(), &warningCallback, &session));
133 wsl::windows::common::security::ConfigureForCOMImpersonation(session.get());
134 - reporter.Info(L"{}\n", Localization::MessageWslcCreatedSession(displayName));
134 + terminal.Info(L"{}\n", Localization::MessageWslcCreatedSession(displayName));
135
136 const std::string shell = "/bin/sh";
137 wsl::windows::common::WSLCProcessLauncher launcher{shell, {shell, "--login"}, {"TERM=xterm-256color"}, WSLCProcessFlagsTty | WSLCProcessFlagsStdin};
@@ -140,7 +140,7 @@ int SessionService::Enter(Reporter& reporter, const std::wstring& storagePath, c
140 const auto windowSize = console.GetWindowSize();
141 launcher.SetTtySize(windowSize.Y, windowSize.X);
142
143 - return ConsoleService::AttachToCurrentConsole(reporter, console, launcher.Launch(*session.get()));
143 + return ConsoleService::AttachToCurrentConsole(terminal, console, launcher.Launch(*session.get()));
144 }
145
146 std::vector<SessionInformation> SessionService::List()
@@ -163,7 +163,7 @@ std::vector<SessionInformation> SessionService::List()
163 return result;
164 }
165
166 -int SessionService::Run(Reporter& reporter, const Session& session, const std::vector<std::string>& arguments)
166 +int SessionService::Run(Terminal& terminal, const Session& session, const std::vector<std::string>& arguments)
167 {
168 WI_ASSERT(!arguments.empty());
169
@@ -177,10 +177,10 @@ int SessionService::Run(Reporter& reporter, const Session& session, const std::v
177 THROW_IF_FAILED(result);
178
179 wsl::windows::common::ConsoleState console{};
180 - return ConsoleService::AttachToCurrentConsole(reporter, console, std::move(process.value()));
180 + return ConsoleService::AttachToCurrentConsole(terminal, console, std::move(process.value()));
181 }
182
183 -int SessionService::TerminateSession(Reporter& reporter, const Session& session)
183 +int SessionService::TerminateSession(Terminal& terminal, const Session& session)
184 {
185 HRESULT hr = session.Get()->Terminate();
186 if (FAILED(hr))
@@ -190,11 +190,11 @@ int SessionService::TerminateSession(Reporter& reporter, const Session& session)
190 wil::unique_cotaskmem_string displayName;
191 if (SUCCEEDED(session.Get()->GetDisplayName(&displayName)) && displayName)
192 {
193 - reporter.Error(L"{}\n", Localization::MessageErrorCode(Localization::MessageWslcTerminateSessionFailed(displayName.get()), errorString));
193 + terminal.Error(L"{}\n", Localization::MessageErrorCode(Localization::MessageWslcTerminateSessionFailed(displayName.get()), errorString));
194 }
195 else
196 {
197 - reporter.Error(L"{}\n", Localization::MessageErrorCode(Localization::MessageWslcTerminateDefaultSessionFailed(), errorString));
197 + terminal.Error(L"{}\n", Localization::MessageErrorCode(Localization::MessageWslcTerminateDefaultSessionFailed(), errorString));
198 }
199 return 1;
200 }
src/windows/wslc/services/SessionService.h
+6 -6
@@ -14,7 +14,7 @@ Abstract:
14 #pragma once
15
16 #include "SessionModel.h"
17 -#include "Reporter.h"
17 +#include "Terminal.h"
18 #include <wslc.h>
19
20 namespace wsl::windows::wslc::services {
@@ -27,18 +27,18 @@ struct SessionInformation
27
28 struct SessionService
29 {
30 - static int Attach(Reporter& reporter, const wsl::windows::wslc::models::Session& session);
31 - static int Enter(Reporter& reporter, const std::wstring& storagePath, const std::wstring& displayName);
30 + static int Attach(Terminal& terminal, const wsl::windows::wslc::models::Session& session);
31 + static int Enter(Terminal& terminal, const std::wstring& storagePath, const std::wstring& displayName);
32 static std::vector<SessionInformation> List();
33 // Opens an existing session by name. Throws if not found.
34 static wsl::windows::wslc::models::Session OpenSession(const std::wstring& name);
35 // Opens the default session. Throws WSLC_E_SESSION_NOT_FOUND if no default session exists.
36 static wsl::windows::wslc::models::Session OpenDefaultSession();
37 // Opens or creates the default session.
38 - static wsl::windows::wslc::models::Session OpenOrCreateDefaultSession(Reporter& reporter);
38 + static wsl::windows::wslc::models::Session OpenOrCreateDefaultSession(Terminal& terminal);
39 // Runs the given command and arguments in a session without a TTY, resolving the executable from PATH.
40 - static int Run(Reporter& reporter, const wsl::windows::wslc::models::Session& session, const std::vector<std::string>& arguments);
41 - static int TerminateSession(Reporter& reporter, const wsl::windows::wslc::models::Session& session);
40 + static int Run(Terminal& terminal, const wsl::windows::wslc::models::Session& session, const std::vector<std::string>& arguments);
41 + static int TerminateSession(Terminal& terminal, const wsl::windows::wslc::models::Session& session);
42
43 private:
44 // Common open-only session lookup with unified error handling.
src/windows/wslc/services/VolumeService.cpp
+2 -2
@@ -84,9 +84,9 @@ wsl::windows::common::wslc_schema::InspectVolume VolumeService::Inspect(models::
84 }
85
86 models::PruneVolumesResult VolumeService::Prune(
87 - Reporter& reporter, models::Session& session, bool all, const std::vector<std::pair<std::string, std::string>>& filters)
87 + Terminal& terminal, models::Session& session, bool all, const std::vector<std::pair<std::string, std::string>>& filters)
88 {
89 - WarningCallback warningCallback(reporter);
89 + WarningCallback warningCallback(terminal);
90 const bool hasExplicitAll = std::any_of(filters.begin(), filters.end(), [](const auto& f) { return f.first == "all"; });
91
92 std::vector<WSLCFilter> filterEntries;
src/windows/wslc/services/VolumeService.h
+2 -2
@@ -15,7 +15,7 @@ Abstract:
15
16 #include "SessionModel.h"
17 #include "VolumeModel.h"
18 -#include "Reporter.h"
18 +#include "Terminal.h"
19 #include <wslc.h>
20 #include <wslc_schema.h>
21
@@ -27,6 +27,6 @@ struct VolumeService
27 static std::vector<WSLCVolumeInformation> List(models::Session& session);
28 static wsl::windows::common::wslc_schema::InspectVolume Inspect(models::Session& session, const std::string& name);
29 static models::PruneVolumesResult Prune(
30 - Reporter& reporter, models::Session& session, bool all, const std::vector<std::pair<std::string, std::string>>& filters = {});
30 + Terminal& terminal, models::Session& session, bool all, const std::vector<std::pair<std::string, std::string>>& filters = {});
31 };
32 } // namespace wsl::windows::wslc::services
src/windows/wslc/services/WarningCallback.h
+5 -5
@@ -2,19 +2,19 @@
2
3 #pragma once
4
5 -#include "Reporter.h"
5 +#include "Terminal.h"
6 #include <wslc.h>
7 #include <wslutil.h>
8
9 namespace wsl::windows::wslc::services {
10
11 -// Adapts the service IWarningCallback COM sink onto the CLI Reporter so the CLI, not the
11 +// Adapts the service IWarningCallback COM sink onto the CLI Terminal so the CLI, not the
12 // service, decides how warnings are presented (mirrors ImageProgressCallback).
13 class DECLSPEC_UUID("A7E3F8B2-4D19-4C6A-9E5B-8F2A1D3C7E90") WarningCallback
14 : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWarningCallback, IFastRundown>
15 {
16 public:
17 - explicit WarningCallback(Reporter& reporter) : m_reporter(reporter)
17 + explicit WarningCallback(Terminal& terminal) : m_terminal(terminal)
18 {
19 }
20
@@ -27,7 +27,7 @@ public:
27 {
28 // Message already carries the "wsl: " prefix and trailing newline from EmitUserWarning;
29 // Warn writes it verbatim, adding color only on a VT console.
30 - m_reporter.Warn(L"{}", Message);
30 + m_terminal.Warn(L"{}", Message);
31 }
32
33 return S_OK;
@@ -36,7 +36,7 @@ public:
36 }
37
38 private:
39 - Reporter& m_reporter;
39 + Terminal& m_terminal;
40 };
41
42 } // namespace wsl::windows::wslc::services
src/windows/wslc/tasks/ContainerTasks.cpp
+24 -24
@@ -136,7 +136,7 @@ nlohmann::json ComputeContainerStatsJson(const wsl::windows::common::docker_sche
136
137 namespace wsl::windows::wslc::task {
138
139 -static bool TryInspectContainer(Reporter& reporter, Session& session, const std::string& containerId, std::optional<wslc_schema::InspectContainer>& inspectData)
139 +static bool TryInspectContainer(Terminal& terminal, Session& session, const std::string& containerId, std::optional<wslc_schema::InspectContainer>& inspectData)
140 {
141 try
142 {
@@ -147,7 +147,7 @@ static bool TryInspectContainer(Reporter& reporter, Session& session, const std:
147 {
148 if (ex.GetErrorCode() == WSLC_E_CONTAINER_NOT_FOUND)
149 {
150 - reporter.Error(L"{}\n", Localization::MessageWslcContainerNotFound(containerId.c_str()));
150 + terminal.Error(L"{}\n", Localization::MessageWslcContainerNotFound(containerId.c_str()));
151 return false;
152 }
153
@@ -158,7 +158,7 @@ static bool TryInspectContainer(Reporter& reporter, Session& session, const std:
158 void AttachContainer::operator()(CLIExecutionContext& context) const
159 {
160 WI_ASSERT(context.Data.Contains(Data::Session));
161 - context.ExitCode = ContainerService::Attach(context.Reporter, context.Data.Get<Data::Session>(), WideToMultiByte(m_containerId));
161 + context.ExitCode = ContainerService::Attach(context.Terminal, context.Data.Get<Data::Session>(), WideToMultiByte(m_containerId));
162 }
163
164 void CreateContainer(CLIExecutionContext& context)
@@ -167,11 +167,11 @@ void CreateContainer(CLIExecutionContext& context)
167 WI_ASSERT(context.Args.Contains(ArgType::ImageId));
168 WI_ASSERT(context.Data.Contains(Data::ContainerOptions));
169 auto result = ContainerService::Create(
170 - context.Reporter,
170 + context.Terminal,
171 context.Data.Get<Data::Session>(),
172 WideToMultiByte(context.Args.Get<ArgType::ImageId>()),
173 context.Data.Get<Data::ContainerOptions>());
174 - context.Reporter.Output(L"{}\n", MultiByteToWide(result.Id));
174 + context.Terminal.Output(L"{}\n", MultiByteToWide(result.Id));
175 }
176
177 void ExecContainer(CLIExecutionContext& context)
@@ -180,7 +180,7 @@ void ExecContainer(CLIExecutionContext& context)
180 WI_ASSERT(context.Args.Contains(ArgType::ContainerId));
181 WI_ASSERT(context.Data.Contains(Data::ContainerOptions));
182 context.ExitCode = ContainerService::Exec(
183 - context.Reporter,
183 + context.Terminal,
184 context.Data.Get<Data::Session>(),
185 WideToMultiByte(context.Args.Get<ArgType::ContainerId>()),
186 context.Data.Get<Data::ContainerOptions>());
@@ -228,7 +228,7 @@ void InspectContainers(CLIExecutionContext& context)
228 for (const auto& id : containerIds)
229 {
230 std::optional<wslc_schema::InspectContainer> inspectData;
231 - if (TryInspectContainer(context.Reporter, session, WideToMultiByte(id), inspectData))
231 + if (TryInspectContainer(context.Terminal, session, WideToMultiByte(id), inspectData))
232 {
233 result.push_back(*inspectData);
234 }
@@ -239,7 +239,7 @@ void InspectContainers(CLIExecutionContext& context)
239 }
240
241 auto json = ToJson(result, validation::GetInspectJsonIndent(context.Args));
242 - context.Reporter.Output(L"{}\n", MultiByteToWide(json));
242 + context.Terminal.Output(L"{}\n", MultiByteToWide(json));
243 }
244
245 void KillContainers(CLIExecutionContext& context)
@@ -256,7 +256,7 @@ void KillContainers(CLIExecutionContext& context)
256 for (const auto& id : containerIds)
257 {
258 ContainerService::Kill(session, WideToMultiByte(id), signal);
259 - context.Reporter.Output(L"{}\n", id);
259 + context.Terminal.Output(L"{}\n", id);
260 }
261 }
262
@@ -559,7 +559,7 @@ void ListContainers(CLIExecutionContext& context)
559 // Print only the container ids
560 for (const auto& container : containers)
561 {
562 - context.Reporter.Output(L"{}\n", MultiByteToWide(container.Id));
562 + context.Terminal.Output(L"{}\n", MultiByteToWide(container.Id));
563 }
564
565 return;
@@ -572,7 +572,7 @@ void ListContainers(CLIExecutionContext& context)
572 case FormatType::Json:
573 {
574 auto json = ToJson(containers, c_jsonCompactIndent);
575 - context.Reporter.Output(L"{}\n", MultiByteToWide(json));
575 + context.Terminal.Output(L"{}\n", MultiByteToWide(json));
576 break;
577 }
578 case FormatType::Table:
@@ -582,7 +582,7 @@ void ListContainers(CLIExecutionContext& context)
582
583 // Create table with or without column limits based on --no-trunc flag
584 auto table = trunc ? wsl::windows::wslc::TableOutput<6>(
585 - context.Reporter,
585 + context.Terminal,
586 {{{Localization::WSLCCLI_TableHeaderContainerId(), {.MaxWidth = 12, .Overflow = Shrink}},
587 {Localization::WSLCCLI_TableHeaderName(), {.MaxWidth = 20, .Overflow = Shrink}},
588 {Localization::WSLCCLI_TableHeaderImage(), {.MaxWidth = 20, .Overflow = Shrink}},
@@ -591,7 +591,7 @@ void ListContainers(CLIExecutionContext& context)
591 {Localization::WSLCCLI_TableHeaderPorts(), {.Overflow = Shrink}}}},
592 containers.size())
593 : wsl::windows::wslc::TableOutput<6>(
594 - context.Reporter,
594 + context.Terminal,
595 {Localization::WSLCCLI_TableHeaderContainerId(),
596 Localization::WSLCCLI_TableHeaderName(),
597 Localization::WSLCCLI_TableHeaderImage(),
@@ -630,7 +630,7 @@ void RemoveContainers(CLIExecutionContext& context)
630 for (const auto& id : containerIds)
631 {
632 ContainerService::Delete(session, WideToMultiByte(id), force, deleteVolumes);
633 - context.Reporter.Output(L"{}\n", id);
633 + context.Terminal.Output(L"{}\n", id);
634 }
635 }
636
@@ -640,7 +640,7 @@ void RunContainer(CLIExecutionContext& context)
640 WI_ASSERT(context.Args.Contains(ArgType::ImageId));
641 WI_ASSERT(context.Data.Contains(Data::ContainerOptions));
642 context.ExitCode = ContainerService::Run(
643 - context.Reporter,
643 + context.Terminal,
644 context.Data.Get<Data::Session>(),
645 WideToMultiByte(context.Args.Get<ArgType::ImageId>()),
646 context.Data.Get<Data::ContainerOptions>());
@@ -978,7 +978,7 @@ void ShowContainerStats(CLIExecutionContext& context)
978 {
979 case FormatType::Json:
980 {
981 - context.Reporter.Output(L"{}\n", MultiByteToWide(statsJson.dump(c_jsonCompactIndent)));
981 + context.Terminal.Output(L"{}\n", MultiByteToWide(statsJson.dump(c_jsonCompactIndent)));
982 break;
983 }
984 case FormatType::Table:
@@ -987,7 +987,7 @@ void ShowContainerStats(CLIExecutionContext& context)
987 using enum ColumnOverflow;
988
989 auto table = trunc ? wsl::windows::wslc::TableOutput<8>(
990 - context.Reporter,
990 + context.Terminal,
991 {{{Localization::WSLCCLI_TableHeaderContainerId(), {.MaxWidth = 12, .Overflow = Shrink}},
992 {Localization::WSLCCLI_TableHeaderName(), {.MaxWidth = 20, .Overflow = Shrink}},
993 {Localization::WSLCCLI_TableHeaderCpuPercent(), {.Overflow = Shrink}},
@@ -998,7 +998,7 @@ void ShowContainerStats(CLIExecutionContext& context)
998 {Localization::WSLCCLI_TableHeaderPids(), {.Overflow = Shrink}}}},
999 statsJson.size())
1000 : wsl::windows::wslc::TableOutput<8>(
1001 - context.Reporter,
1001 + context.Terminal,
1002 {Localization::WSLCCLI_TableHeaderContainerId(),
1003 Localization::WSLCCLI_TableHeaderName(),
1004 Localization::WSLCCLI_TableHeaderCpuPercent(),
@@ -1037,11 +1037,11 @@ void StartContainer(CLIExecutionContext& context)
1037 WI_ASSERT(context.Args.Contains(ArgType::ContainerId));
1038 const auto& containerId = context.Args.Get<ArgType::ContainerId>();
1039 const bool attach = context.Args.GetFlag<ArgType::Attach>();
1040 - context.ExitCode = ContainerService::Start(context.Reporter, context.Data.Get<Data::Session>(), WideToMultiByte(containerId), attach);
1040 + context.ExitCode = ContainerService::Start(context.Terminal, context.Data.Get<Data::Session>(), WideToMultiByte(containerId), attach);
1041
1042 if (!attach)
1043 {
1044 - context.Reporter.Output(L"{}\n", containerId);
1044 + context.Terminal.Output(L"{}\n", containerId);
1045 }
1046 }
1047
@@ -1064,7 +1064,7 @@ void StopContainers(CLIExecutionContext& context)
1064 for (const auto& id : containersToStop)
1065 {
1066 ContainerService::Stop(context.Data.Get<Data::Session>(), WideToMultiByte(id), options);
1067 - context.Reporter.Output(L"{}\n", id);
1067 + context.Terminal.Output(L"{}\n", id);
1068 }
1069 }
1070
@@ -1109,11 +1109,11 @@ void PruneContainers(CLIExecutionContext& context)
1109
1110 for (const auto& containerId : result.PrunedContainers)
1111 {
1112 - context.Reporter.Output(L"{}\n", MultiByteToWide(containerId));
1112 + context.Terminal.Output(L"{}\n", MultiByteToWide(containerId));
1113 }
1114
1115 - context.Reporter.Output(L"\n");
1116 - context.Reporter.Output(
1115 + context.Terminal.Output(L"\n");
1116 + context.Terminal.Output(
1117 L"{}\n", Localization::WSLCCLI_ContainerPruneSpaceReclaimedBytes(wsl::shared::string::FormatBytes(result.SpaceReclaimed)));
1118 }
1119 } // namespace wsl::windows::wslc::task
src/windows/wslc/tasks/ImageTasks.cpp
+28 -28
@@ -41,7 +41,7 @@ namespace {
41 : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IImageLoadCallback, IFastRundown>
42 {
43 public:
44 - explicit WSLCImageLoadCallback(Reporter& reporter) : m_reporter(reporter)
44 + explicit WSLCImageLoadCallback(Terminal& terminal) : m_terminal(terminal)
45 {
46 }
47
@@ -50,11 +50,11 @@ namespace {
50 {
51 if (Format == EnumReferenceFormatDigest)
52 {
53 - m_reporter.Output(L"{}\n", Localization::WSLCCLI_ImageLoadedId(Reference));
53 + m_terminal.Output(L"{}\n", Localization::WSLCCLI_ImageLoadedId(Reference));
54 }
55 else if (Format == EnumReferenceFormatTag)
56 {
57 - m_reporter.Output(L"{}\n", Localization::WSLCCLI_ImageLoaded(Reference));
57 + m_terminal.Output(L"{}\n", Localization::WSLCCLI_ImageLoaded(Reference));
58 }
59 else
60 {
@@ -66,12 +66,12 @@ namespace {
66 CATCH_RETURN();
67
68 private:
69 - Reporter& m_reporter;
69 + Terminal& m_terminal;
70 };
71
72 } // namespace
73
74 -static bool TryInspectImage(Reporter& reporter, Session& session, const std::string& imageId, std::optional<wslc_schema::InspectImage>& inspectData)
74 +static bool TryInspectImage(Terminal& terminal, Session& session, const std::string& imageId, std::optional<wslc_schema::InspectImage>& inspectData)
75 {
76 try
77 {
@@ -82,7 +82,7 @@ static bool TryInspectImage(Reporter& reporter, Session& session, const std::str
82 {
83 if (ex.GetErrorCode() == WSLC_E_IMAGE_NOT_FOUND)
84 {
85 - reporter.Error(L"{}\n", Localization::MessageWslcImageNotFound(imageId.c_str()));
85 + terminal.Error(L"{}\n", Localization::MessageWslcImageNotFound(imageId.c_str()));
86 return false;
87 }
88
@@ -146,7 +146,7 @@ void BuildImage(CLIExecutionContext& context)
146 WI_SetFlagIf(flags, WSLCBuildImageFlagsPull, context.Args.GetFlag<ArgType::BuildPull>());
147
148 auto cancelEvent = context.CreateCancelEvent();
149 - BuildImageCallback callback(context.Reporter, cancelEvent, context.Args.GetFlag<ArgType::Verbose>());
149 + BuildImageCallback callback(context.Terminal, cancelEvent, context.Args.GetFlag<ArgType::Verbose>());
150 services::ImageService::Build(
151 session, contextPath, tags, buildArgs, labels, secrets, dockerfilePath, target, output, iidFilePath, flags, &callback, cancelEvent);
152 }
@@ -184,7 +184,7 @@ void ListImages(CLIExecutionContext& context)
184 bool trunc = !context.Args.GetFlag<ArgType::NoTrunc>();
185 for (const auto& image : images)
186 {
187 - context.Reporter.Output(L"{}\n", trunc ? TruncateId(image.Id, true) : image.Id);
187 + context.Terminal.Output(L"{}\n", trunc ? TruncateId(image.Id, true) : image.Id);
188 }
189
190 return;
@@ -197,7 +197,7 @@ void ListImages(CLIExecutionContext& context)
197 case FormatType::Json:
198 {
199 auto json = ToJson(images, c_jsonCompactIndent);
200 - context.Reporter.Output(L"{}\n", MultiByteToWide(json));
200 + context.Terminal.Output(L"{}\n", MultiByteToWide(json));
201 break;
202 }
203 case FormatType::Table:
@@ -210,14 +210,14 @@ void ListImages(CLIExecutionContext& context)
210 auto table =
211 trunc
212 ? wsl::windows::wslc::TableOutput<5>(
213 - context.Reporter,
213 + context.Terminal,
214 {{{L"REPOSITORY", {.Overflow = Shrink}},
215 {L"TAG", {.Overflow = Shrink}},
216 {L"IMAGE ID", {.MinWidth = 12, .MaxWidth = 12, .Overflow = Shrink}},
217 {L"CREATED", {.Overflow = Shrink}},
218 {L"SIZE", {.Overflow = Shrink}}}},
219 images.size())
220 - : wsl::windows::wslc::TableOutput<5>(context.Reporter, {L"REPOSITORY", L"TAG", L"IMAGE ID", L"CREATED", L"SIZE"});
220 + : wsl::windows::wslc::TableOutput<5>(context.Terminal, {L"REPOSITORY", L"TAG", L"IMAGE ID", L"CREATED", L"SIZE"});
221
222 for (const auto& image : images)
223 {
@@ -251,22 +251,22 @@ void PullImage(CLIExecutionContext& context)
251 const auto reference = ImageReference::Parse(image);
252 if (!quiet && reference.Format == EnumReferenceFormatNone)
253 {
254 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_PullUsingDefaultTag(L"latest"));
254 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_PullUsingDefaultTag(L"latest"));
255 }
256
257 // Match `docker pull`: in quiet mode, suppress progress output by passing no progress callback. Warnings are
258 - // unaffected because the warning callback is built internally by ImageService::Pull from the Reporter.
258 + // unaffected because the warning callback is built internally by ImageService::Pull from the Terminal.
259 std::optional<ImageProgressCallback> callback;
260 if (!quiet)
261 {
262 - callback.emplace(context.Reporter, Reporter::Level::Output);
262 + callback.emplace(context.Terminal, Terminal::Level::Output);
263 }
264
265 IProgressCallback* progress = callback ? &*callback : nullptr;
266 - services::ImageService::Pull(context.Reporter, session, image, progress);
266 + services::ImageService::Pull(context.Terminal, session, image, progress);
267
268 // Match `docker pull`: always print the resolved canonical image reference as the final line.
269 - context.Reporter.Output(L"{}\n", MultiByteToWide(reference.GetCanonical()));
269 + context.Terminal.Output(L"{}\n", MultiByteToWide(reference.GetCanonical()));
270 }
271
272 void PushImage(CLIExecutionContext& context)
@@ -276,8 +276,8 @@ void PushImage(CLIExecutionContext& context)
276 auto& session = context.Data.Get<Data::Session>();
277 auto& imageId = context.Args.Get<ArgType::ImageId>();
278
279 - ImageProgressCallback callback(context.Reporter, Reporter::Level::Output);
280 - services::ImageService::Push(context.Reporter, session, WideToMultiByte(imageId), &callback);
279 + ImageProgressCallback callback(context.Terminal, Terminal::Level::Output);
280 + services::ImageService::Push(context.Terminal, session, WideToMultiByte(imageId), &callback);
281 }
282
283 void DeleteImage(CLIExecutionContext& context)
@@ -301,8 +301,8 @@ void LoadImage(CLIExecutionContext& context)
301 if (context.Args.Contains(ArgType::Input))
302 {
303 auto& input = context.Args.Get<ArgType::Input>();
304 - auto callback = wil::MakeOrThrow<WSLCImageLoadCallback>(context.Reporter);
305 - services::ImageService::Load(context.Reporter, session, input, callback.Get());
304 + auto callback = wil::MakeOrThrow<WSLCImageLoadCallback>(context.Terminal);
305 + services::ImageService::Load(context.Terminal, session, input, callback.Get());
306 return;
307 }
308
@@ -323,11 +323,11 @@ void ImportImage(CLIExecutionContext& context)
323 }
324
325 auto& input = context.Args.Get<ArgType::ImportFile>();
326 - auto imageId = services::ImageService::Import(context.Reporter, session, input, imageName);
326 + auto imageId = services::ImageService::Import(context.Terminal, session, input, imageName);
327 if (!imageId.empty())
328 {
329 bool trunc = !context.Args.GetFlag<ArgType::NoTrunc>();
330 - context.Reporter.Output(L"{}\n", MultiByteToWide(TruncateId(imageId, trunc)));
330 + context.Terminal.Output(L"{}\n", MultiByteToWide(TruncateId(imageId, trunc)));
331 }
332 }
333
@@ -342,7 +342,7 @@ void InspectImages(CLIExecutionContext& context)
342 for (const auto& id : imageIds)
343 {
344 std::optional<wslc_schema::InspectImage> inspectData;
345 - if (TryInspectImage(context.Reporter, session, WideToMultiByte(id), inspectData))
345 + if (TryInspectImage(context.Terminal, session, WideToMultiByte(id), inspectData))
346 {
347 result.push_back(*inspectData);
348 }
@@ -353,7 +353,7 @@ void InspectImages(CLIExecutionContext& context)
353 }
354
355 auto json = ToJson(result, validation::GetInspectJsonIndent(context.Args));
356 - context.Reporter.Output(L"{}\n", MultiByteToWide(json));
356 + context.Terminal.Output(L"{}\n", MultiByteToWide(json));
357 }
358
359 void SaveImage(CLIExecutionContext& context)
@@ -421,16 +421,16 @@ void PruneImages(CLIExecutionContext& context)
421
422 for (const auto& image : result.UntaggedImages)
423 {
424 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_ImagePruneUntagged(image));
424 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_ImagePruneUntagged(image));
425 }
426
427 for (const auto& image : result.DeletedImages)
428 {
429 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_ImagePruneDeleted(image));
429 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_ImagePruneDeleted(image));
430 }
431
432 - context.Reporter.Output(L"\n");
433 - context.Reporter.Output(
432 + context.Terminal.Output(L"\n");
433 + context.Terminal.Output(
434 L"{}\n", Localization::WSLCCLI_ImagePruneSpaceReclaimedBytes(wsl::shared::string::FormatBytes(result.SpaceReclaimed)));
435 }
436 } // namespace wsl::windows::wslc::task
src/windows/wslc/tasks/InspectTasks.cpp
+2 -2
@@ -107,12 +107,12 @@ void Inspect(CLIExecutionContext& context)
107 }
108 else
109 {
110 - context.Reporter.Error(L"{}\n", Localization::WSLCCLI_ObjectNotFoundError(objectId));
110 + context.Terminal.Error(L"{}\n", Localization::WSLCCLI_ObjectNotFoundError(objectId));
111 context.ExitCode = 1;
112 }
113 }
114
115 // Always print the array, even if it's empty or an error was encountered
116 - context.Reporter.Output(L"{}\n", MultiByteToWide(array.dump(validation::GetInspectJsonIndent(context.Args))));
116 + context.Terminal.Output(L"{}\n", MultiByteToWide(array.dump(validation::GetInspectJsonIndent(context.Args))));
117 }
118 } // namespace wsl::windows::wslc::task
src/windows/wslc/tasks/NetworkTasks.cpp
+14 -14
@@ -30,7 +30,7 @@ using namespace wsl::windows::wslc::services;
30
31 namespace wsl::windows::wslc::task {
32
33 -static bool TryInspectNetwork(Reporter& reporter, Session& session, const std::string& networkName, std::optional<wslc_schema::Network>& inspectData)
33 +static bool TryInspectNetwork(Terminal& terminal, Session& session, const std::string& networkName, std::optional<wslc_schema::Network>& inspectData)
34 {
35 try
36 {
@@ -41,7 +41,7 @@ static bool TryInspectNetwork(Reporter& reporter, Session& session, const std::s
41 {
42 if (ex.GetErrorCode() == WSLC_E_NETWORK_NOT_FOUND)
43 {
44 - reporter.Error(L"{}\n", Localization::MessageWslcNetworkNotFound(networkName.c_str()));
44 + terminal.Error(L"{}\n", Localization::MessageWslcNetworkNotFound(networkName.c_str()));
45 return false;
46 }
47
@@ -49,7 +49,7 @@ static bool TryInspectNetwork(Reporter& reporter, Session& session, const std::s
49 }
50 }
51
52 -static bool TryDeleteNetwork(Reporter& reporter, Session& session, const std::string& networkName, bool force)
52 +static bool TryDeleteNetwork(Terminal& terminal, Session& session, const std::string& networkName, bool force)
53 {
54 try
55 {
@@ -62,7 +62,7 @@ static bool TryDeleteNetwork(Reporter& reporter, Session& session, const std::st
62 {
63 if (!force)
64 {
65 - reporter.Error(L"{}\n", Localization::MessageWslcNetworkNotFound(networkName.c_str()));
65 + terminal.Error(L"{}\n", Localization::MessageWslcNetworkNotFound(networkName.c_str()));
66 }
67
68 return false;
@@ -112,8 +112,8 @@ void CreateNetwork(CLIExecutionContext& context)
112 options.IpRange = WideToMultiByte(context.Args.Get<ArgType::IpRange>());
113 }
114
115 - NetworkService::Create(context.Reporter, context.Data.Get<Data::Session>(), options);
116 - context.Reporter.Output(L"{}\n", MultiByteToWide(options.Name));
115 + NetworkService::Create(context.Terminal, context.Data.Get<Data::Session>(), options);
116 + context.Terminal.Output(L"{}\n", MultiByteToWide(options.Name));
117 }
118
119 void DeleteNetworks(CLIExecutionContext& context)
@@ -124,9 +124,9 @@ void DeleteNetworks(CLIExecutionContext& context)
124 const bool force = context.Args.GetFlag<ArgType::Force>();
125 for (const auto& name : networkNames)
126 {
127 - if (TryDeleteNetwork(context.Reporter, session, WideToMultiByte(name), force))
127 + if (TryDeleteNetwork(context.Terminal, session, WideToMultiByte(name), force))
128 {
129 - context.Reporter.Output(L"{}\n", name);
129 + context.Terminal.Output(L"{}\n", name);
130 }
131 else if (!force)
132 {
@@ -151,7 +151,7 @@ void InspectNetworks(CLIExecutionContext& context)
151 for (const auto& name : networkNames)
152 {
153 std::optional<wslc_schema::Network> inspectData;
154 - if (TryInspectNetwork(context.Reporter, session, WideToMultiByte(name), inspectData))
154 + if (TryInspectNetwork(context.Terminal, session, WideToMultiByte(name), inspectData))
155 {
156 result.push_back(*inspectData);
157 }
@@ -162,7 +162,7 @@ void InspectNetworks(CLIExecutionContext& context)
162 }
163
164 auto json = ToJson(result, validation::GetInspectJsonIndent(context.Args));
165 - context.Reporter.Output(L"{}\n", MultiByteToWide(json));
165 + context.Terminal.Output(L"{}\n", MultiByteToWide(json));
166 }
167
168 void ListNetworks(CLIExecutionContext& context)
@@ -174,7 +174,7 @@ void ListNetworks(CLIExecutionContext& context)
174 {
175 for (const auto& network : networks)
176 {
177 - context.Reporter.Output(L"{}\n", MultiByteToWide(network.Name));
177 + context.Terminal.Output(L"{}\n", MultiByteToWide(network.Name));
178 }
179
180 return;
@@ -187,12 +187,12 @@ void ListNetworks(CLIExecutionContext& context)
187 case FormatType::Json:
188 {
189 auto json = ToJson(networks, c_jsonCompactIndent);
190 - context.Reporter.Output(L"{}\n", MultiByteToWide(json));
190 + context.Terminal.Output(L"{}\n", MultiByteToWide(json));
191 break;
192 }
193 case FormatType::Table:
194 {
195 - auto table = wsl::windows::wslc::TableOutput<3>(context.Reporter, {L"NETWORK ID", L"NAME", L"DRIVER"});
195 + auto table = wsl::windows::wslc::TableOutput<3>(context.Terminal, {L"NETWORK ID", L"NAME", L"DRIVER"});
196 for (const auto& network : networks)
197 {
198 table.WriteRow({
@@ -225,7 +225,7 @@ void PruneNetworks(CLIExecutionContext& context)
225
226 for (const auto& networkName : result.PrunedNetworks)
227 {
228 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_NetworkPruneDeleted(MultiByteToWide(networkName)));
228 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_NetworkPruneDeleted(MultiByteToWide(networkName)));
229 }
230 }
231
src/windows/wslc/tasks/RegistryTasks.cpp
+2 -2
@@ -46,7 +46,7 @@ void Login(CLIExecutionContext& context)
46 auto [credUsername, credSecret] = RegistryService::Authenticate(session, serverAddress, username, password);
47 RegistryService::Store(serverAddress, credUsername, credSecret);
48
49 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_LoginSucceeded());
49 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_LoginSucceeded());
50 }
51
52 void Logout(CLIExecutionContext& context)
@@ -60,7 +60,7 @@ void Logout(CLIExecutionContext& context)
60
61 RegistryService::Erase(serverAddress);
62
63 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_LogoutSucceeded(MultiByteToWide(serverAddress)));
63 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_LogoutSucceeded(MultiByteToWide(serverAddress)));
64 }
65
66 } // namespace wsl::windows::wslc::task
src/windows/wslc/tasks/SessionTasks.cpp
+7 -7
@@ -30,7 +30,7 @@ namespace wsl::windows::wslc::task {
30 void AttachToSession(CLIExecutionContext& context)
31 {
32 auto& session = context.Data.Get<Data::Session>();
33 - context.ExitCode = SessionService::Attach(context.Reporter, session);
33 + context.ExitCode = SessionService::Attach(context.Terminal, session);
34 }
35
36 void OpenSessionIfSpecified(CLIExecutionContext& context)
@@ -46,7 +46,7 @@ void OpenOrCreateDefaultSession(CLIExecutionContext& context)
46 {
47 if (!context.Data.Contains(Data::Session))
48 {
49 - context.Data.Add<Data::Session>(SessionService::OpenOrCreateDefaultSession(context.Reporter));
49 + context.Data.Add<Data::Session>(SessionService::OpenOrCreateDefaultSession(context.Terminal));
50 }
51 }
52
@@ -70,11 +70,11 @@ void ListSessions(CLIExecutionContext& context)
70 if (context.Args.GetFlag<ArgType::Verbose>())
71 {
72 const wchar_t* plural = sessions.size() == 1 ? L"" : L"s";
73 - context.Reporter.Output(L"[wslc] Found {} session{}\n", sessions.size(), plural);
73 + context.Terminal.Output(L"[wslc] Found {} session{}\n", sessions.size(), plural);
74 }
75
76 TableOutput<3> table(
77 - context.Reporter,
77 + context.Terminal,
78 {Localization::MessageWslcHeaderId(), Localization::MessageWslcHeaderCreatorPid(), Localization::MessageWslcHeaderDisplayName()});
79
80 for (const auto& session : sessions)
@@ -92,7 +92,7 @@ void ListSessions(CLIExecutionContext& context)
92 void TerminateSession(CLIExecutionContext& context)
93 {
94 auto& session = context.Data.Get<Data::Session>();
95 - context.ExitCode = SessionService::TerminateSession(context.Reporter, session);
95 + context.ExitCode = SessionService::TerminateSession(context.Terminal, session);
96 }
97
98 void RunInSession(CLIExecutionContext& context)
@@ -109,7 +109,7 @@ void RunInSession(CLIExecutionContext& context)
109 }
110 }
111
112 - context.ExitCode = SessionService::Run(context.Reporter, session, arguments);
112 + context.ExitCode = SessionService::Run(context.Terminal, session, arguments);
113 }
114
115 void EnterSession(CLIExecutionContext& context)
@@ -128,7 +128,7 @@ void EnterSession(CLIExecutionContext& context)
128 sessionName = wsl::shared::string::GuidToString<wchar_t>(guid, wsl::shared::string::GuidToStringFlags::None);
129 }
130
131 - context.ExitCode = SessionService::Enter(context.Reporter, storagePath.wstring(), sessionName);
131 + context.ExitCode = SessionService::Enter(context.Terminal, storagePath.wstring(), sessionName);
132 }
133
134 } // namespace wsl::windows::wslc::task
src/windows/wslc/tasks/VolumeTasks.cpp
+16 -16
@@ -30,7 +30,7 @@ using namespace wsl::windows::wslc::services;
30
31 namespace wsl::windows::wslc::task {
32
33 -static bool TryInspectVolume(Reporter& reporter, Session& session, const std::string& volumeName, std::optional<wslc_schema::InspectVolume>& inspectData)
33 +static bool TryInspectVolume(Terminal& terminal, Session& session, const std::string& volumeName, std::optional<wslc_schema::InspectVolume>& inspectData)
34 {
35 try
36 {
@@ -41,7 +41,7 @@ static bool TryInspectVolume(Reporter& reporter, Session& session, const std::st
41 {
42 if (ex.GetErrorCode() == WSLC_E_VOLUME_NOT_FOUND)
43 {
44 - reporter.Error(L"{}\n", Localization::MessageWslcVolumeNotFound(volumeName.c_str()));
44 + terminal.Error(L"{}\n", Localization::MessageWslcVolumeNotFound(volumeName.c_str()));
45 return false;
46 }
47
@@ -49,7 +49,7 @@ static bool TryInspectVolume(Reporter& reporter, Session& session, const std::st
49 }
50 }
51
52 -static bool TryDeleteVolume(Reporter& reporter, Session& session, const std::string& volumeName, bool force)
52 +static bool TryDeleteVolume(Terminal& terminal, Session& session, const std::string& volumeName, bool force)
53 {
54 try
55 {
@@ -62,7 +62,7 @@ static bool TryDeleteVolume(Reporter& reporter, Session& session, const std::str
62 {
63 if (!force)
64 {
65 - reporter.Error(L"{}\n", Localization::MessageWslcVolumeNotFound(volumeName.c_str()));
65 + terminal.Error(L"{}\n", Localization::MessageWslcVolumeNotFound(volumeName.c_str()));
66 }
67
68 return false;
@@ -100,7 +100,7 @@ void CreateVolume(CLIExecutionContext& context)
100 }
101
102 auto result = VolumeService::Create(context.Data.Get<Data::Session>(), options);
103 - context.Reporter.Output(L"{}\n", MultiByteToWide(result.Name));
103 + context.Terminal.Output(L"{}\n", MultiByteToWide(result.Name));
104 }
105
106 void DeleteVolumes(CLIExecutionContext& context)
@@ -111,9 +111,9 @@ void DeleteVolumes(CLIExecutionContext& context)
111 const bool force = context.Args.GetFlag<ArgType::Force>();
112 for (const auto& name : volumeNames)
113 {
114 - if (TryDeleteVolume(context.Reporter, session, WideToMultiByte(name), force))
114 + if (TryDeleteVolume(context.Terminal, session, WideToMultiByte(name), force))
115 {
116 - context.Reporter.Output(L"{}\n", name);
116 + context.Terminal.Output(L"{}\n", name);
117 }
118 else if (!force)
119 {
@@ -138,7 +138,7 @@ void InspectVolumes(CLIExecutionContext& context)
138 for (const auto& name : volumeNames)
139 {
140 std::optional<wslc_schema::InspectVolume> inspectData;
141 - if (TryInspectVolume(context.Reporter, session, WideToMultiByte(name), inspectData))
141 + if (TryInspectVolume(context.Terminal, session, WideToMultiByte(name), inspectData))
142 {
143 result.push_back(*inspectData);
144 }
@@ -149,7 +149,7 @@ void InspectVolumes(CLIExecutionContext& context)
149 }
150
151 auto json = ToJson(result, validation::GetInspectJsonIndent(context.Args));
152 - context.Reporter.Output(L"{}\n", MultiByteToWide(json));
152 + context.Terminal.Output(L"{}\n", MultiByteToWide(json));
153 }
154
155 void ListVolumes(CLIExecutionContext& context)
@@ -161,7 +161,7 @@ void ListVolumes(CLIExecutionContext& context)
161 {
162 for (const auto& volume : volumes)
163 {
164 - context.Reporter.Output(L"{}\n", MultiByteToWide(volume.Name));
164 + context.Terminal.Output(L"{}\n", MultiByteToWide(volume.Name));
165 }
166
167 return;
@@ -174,12 +174,12 @@ void ListVolumes(CLIExecutionContext& context)
174 case FormatType::Json:
175 {
176 auto json = ToJson(volumes, c_jsonCompactIndent);
177 - context.Reporter.Output(L"{}\n", MultiByteToWide(json));
177 + context.Terminal.Output(L"{}\n", MultiByteToWide(json));
178 break;
179 }
180 case FormatType::Table:
181 {
182 - auto table = wsl::windows::wslc::TableOutput<2>(context.Reporter, {L"DRIVER", L"VOLUME NAME"});
182 + auto table = wsl::windows::wslc::TableOutput<2>(context.Terminal, {L"DRIVER", L"VOLUME NAME"});
183 for (const auto& volume : volumes)
184 {
185 table.WriteRow({
@@ -209,14 +209,14 @@ void PruneVolumes(CLIExecutionContext& context)
209 filters.push_back(validation::ParseFilter(value));
210 }
211
212 - auto result = VolumeService::Prune(context.Reporter, session, all, filters);
212 + auto result = VolumeService::Prune(context.Terminal, session, all, filters);
213
214 for (const auto& volumeName : result.PrunedVolumes)
215 {
216 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_VolumePruneDeleted(MultiByteToWide(volumeName)));
216 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_VolumePruneDeleted(MultiByteToWide(volumeName)));
217 }
218
219 - context.Reporter.Output(L"\n");
220 - context.Reporter.Output(L"{}\n", Localization::WSLCCLI_VolumePruneSpaceReclaimed(wsl::shared::string::FormatBytes(result.SpaceReclaimed)));
219 + context.Terminal.Output(L"\n");
220 + context.Terminal.Output(L"{}\n", Localization::WSLCCLI_VolumePruneSpaceReclaimed(wsl::shared::string::FormatBytes(result.SpaceReclaimed)));
221 }
222 } // namespace wsl::windows::wslc::task
test/windows/wslc/WSLCCLITerminalUnitTests.cpp renamed
+135 -135
@@ -4,11 +4,11 @@ Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 - WSLCCLIReporterUnitTests.cpp
7 + WSLCCLITerminalUnitTests.cpp
8
9 Abstract:
10
11 - Unit tests for OutputChannel, InputChannel, and Reporter.
11 + Unit tests for OutputChannel, InputChannel, and Terminal.
12
13 --*/
14
@@ -18,7 +18,7 @@ Abstract:
18
19 #include "InputChannel.h"
20 #include "OutputChannel.h"
21 -#include "Reporter.h"
21 +#include "Terminal.h"
22
23 using namespace wsl::windows::wslc;
24 using namespace wsl::windows::common::vt;
@@ -27,38 +27,38 @@ using namespace WEX::Logging;
27 using namespace WEX::Common;
28 using namespace WEX::TestExecution;
29
30 -namespace WSLCCLIReporterUnitTests {
30 +namespace WSLCCLITerminalUnitTests {
31
32 -// Dual-pipe Reporter so stdout and stderr can be asserted independently.
33 -struct SplitCaptureReporter
32 +// Dual-pipe Terminal so stdout and stderr can be asserted independently.
33 +struct SplitCaptureTerminal
34 {
35 CapturePipe outPipe;
36 CapturePipe errPipe;
37 - Reporter reporter;
37 + Terminal terminal;
38
39 - explicit SplitCaptureReporter(bool vtEnabled = false) : reporter(outPipe.file(), vtEnabled, errPipe.file(), vtEnabled)
39 + explicit SplitCaptureTerminal(bool vtEnabled = false) : terminal(outPipe.file(), vtEnabled, errPipe.file(), vtEnabled)
40 {
41 }
42 };
43
44 -// Reporter wired with a preloaded input pipe plus split output capture, so prompt
44 +// Terminal wired with a preloaded input pipe plus split output capture, so prompt
45 // input and the label/newline it writes can be asserted together.
46 -struct InputCaptureReporter
46 +struct InputCaptureTerminal
47 {
48 CapturePipe outPipe;
49 CapturePipe errPipe;
50 InputPipe inPipe;
51 - Reporter reporter;
51 + Terminal terminal;
52
53 - explicit InputCaptureReporter(const std::wstring& input, bool interactive = false) :
54 - inPipe(input), reporter(outPipe.file(), false, errPipe.file(), false, inPipe.file(), interactive)
53 + explicit InputCaptureTerminal(const std::wstring& input, bool interactive = false) :
54 + inPipe(input), terminal(outPipe.file(), false, errPipe.file(), false, inPipe.file(), interactive)
55 {
56 }
57 };
58
59 -class WSLCCLIReporterUnitTests
59 +class WSLCCLITerminalUnitTests
60 {
61 - WSLC_TEST_CLASS(WSLCCLIReporterUnitTests)
61 + WSLC_TEST_CLASS(WSLCCLITerminalUnitTests)
62
63 TEST_CLASS_SETUP(TestClassSetup)
64 {
@@ -102,58 +102,58 @@ class WSLCCLIReporterUnitTests
102 VERIFY_IS_FALSE(channel.GetConsoleWidth().has_value());
103 }
104
105 - TEST_METHOD(Reporter_WriteEmitsExactText)
105 + TEST_METHOD(Terminal_WriteEmitsExactText)
106 {
107 - CaptureReporter cap;
108 - cap.reporter.Output(L"hello\n");
107 + CaptureTerminal cap;
108 + cap.terminal.Output(L"hello\n");
109 VERIFY_ARE_EQUAL(std::wstring{L"hello\n"}, cap.captured());
110 }
111
112 - TEST_METHOD(Reporter_WriteWithoutNewline)
112 + TEST_METHOD(Terminal_WriteWithoutNewline)
113 {
114 - CaptureReporter cap;
115 - cap.reporter.Write(Reporter::Level::Output, L"hello");
114 + CaptureTerminal cap;
115 + cap.terminal.Write(Terminal::Level::Output, L"hello");
116 VERIFY_ARE_EQUAL(std::wstring{L"hello"}, cap.captured());
117 }
118
119 - TEST_METHOD(Reporter_FormatStringSubstitutesArgs)
119 + TEST_METHOD(Terminal_FormatStringSubstitutesArgs)
120 {
121 - CaptureReporter cap;
122 - cap.reporter.Output(L"value={}, name={}\n", 42, L"alice");
121 + CaptureTerminal cap;
122 + cap.terminal.Output(L"value={}, name={}\n", 42, L"alice");
123 VERIFY_ARE_EQUAL(std::wstring{L"value=42, name=alice\n"}, cap.captured());
124 }
125
126 - TEST_METHOD(Reporter_PlainStringNeedsNoArgs)
126 + TEST_METHOD(Terminal_PlainStringNeedsNoArgs)
127 {
128 - CaptureReporter cap;
129 - cap.reporter.Output(L"plain literal\n");
128 + CaptureTerminal cap;
129 + cap.terminal.Output(L"plain literal\n");
130 VERIFY_ARE_EQUAL(std::wstring{L"plain literal\n"}, cap.captured());
131 }
132
133 - TEST_METHOD(Reporter_SequenceEmittedWhenVTEnabled)
133 + TEST_METHOD(Terminal_SequenceEmittedWhenVTEnabled)
134 {
135 - CaptureReporter cap{/*vtEnabled*/ true};
136 - cap.reporter.Output(L"{}highlighted{}\n", Format::Fg::BrightYellow, Format::Default);
135 + CaptureTerminal cap{/*vtEnabled*/ true};
136 + cap.terminal.Output(L"{}highlighted{}\n", Format::Fg::BrightYellow, Format::Default);
137
138 const auto result = cap.captured();
139 VERIFY_ARE_NOT_EQUAL(std::wstring::npos, result.find(L"highlighted"));
140 VERIFY_ARE_NOT_EQUAL(std::wstring::npos, result.find(Format::Fg::BrightYellow.Get()));
141 }
142
143 - TEST_METHOD(Reporter_SequenceStrippedWhenVTDisabled)
143 + TEST_METHOD(Terminal_SequenceStrippedWhenVTDisabled)
144 {
145 - CaptureReporter cap{/*vtEnabled*/ false};
146 - cap.reporter.Output(L"{}plain{}\n", Format::Fg::BrightYellow, Format::Default);
145 + CaptureTerminal cap{/*vtEnabled*/ false};
146 + cap.terminal.Output(L"{}plain{}\n", Format::Fg::BrightYellow, Format::Default);
147 VERIFY_ARE_EQUAL(std::wstring{L"plain\n"}, cap.captured());
148 }
149
150 - TEST_METHOD(Reporter_ColorSequenceStrippedWhenNoColor)
150 + TEST_METHOD(Terminal_ColorSequenceStrippedWhenNoColor)
151 {
152 - CaptureReporter cap{/*vtEnabled*/ true};
153 - cap.reporter.SetNoColor(true);
152 + CaptureTerminal cap{/*vtEnabled*/ true};
153 + cap.terminal.SetNoColor(true);
154
155 // Color sequence (SGR) stripped; cursor moves (non-color) still pass.
156 - cap.reporter.Output(L"{}{}plain{}\n", Cursor::Up(1), Format::Fg::BrightRed, Format::Default);
156 + cap.terminal.Output(L"{}{}plain{}\n", Cursor::Up(1), Format::Fg::BrightRed, Format::Default);
157
158 const auto result = cap.captured();
159 VERIFY_ARE_EQUAL(std::wstring::npos, result.find(Format::Fg::BrightRed.Get()));
@@ -161,25 +161,25 @@ class WSLCCLIReporterUnitTests
161 VERIFY_ARE_NOT_EQUAL(std::wstring::npos, result.find(L"plain"));
162 }
163
164 - TEST_METHOD(Reporter_ConstructedSequenceHandledLikeSequence)
164 + TEST_METHOD(Terminal_ConstructedSequenceHandledLikeSequence)
165 {
166 - CaptureReporter cap{/*vtEnabled*/ true};
166 + CaptureTerminal cap{/*vtEnabled*/ true};
167 const auto cursor = Cursor::Up(3);
168 - cap.reporter.Output(L"{}done\n", cursor);
168 + cap.terminal.Output(L"{}done\n", cursor);
169
170 const auto result = cap.captured();
171 VERIFY_ARE_NOT_EQUAL(std::wstring::npos, result.find(cursor.Get()));
172 VERIFY_ARE_NOT_EQUAL(std::wstring::npos, result.find(L"done"));
173 }
174
175 - TEST_METHOD(Reporter_LevelColorWrapsOutputWhenVTEnabled)
175 + TEST_METHOD(Terminal_LevelColorWrapsOutputWhenVTEnabled)
176 {
177 - CaptureReporter cap{/*vtEnabled*/ true};
177 + CaptureTerminal cap{/*vtEnabled*/ true};
178
179 - cap.reporter.Output(L"starting\n");
180 - cap.reporter.Info(L"pulling\n");
181 - cap.reporter.Warn(L"careful\n");
182 - cap.reporter.Error(L"failed\n");
179 + cap.terminal.Output(L"starting\n");
180 + cap.terminal.Info(L"pulling\n");
181 + cap.terminal.Warn(L"careful\n");
182 + cap.terminal.Error(L"failed\n");
183
184 const std::wstring def{Format::Default.Get()};
185 const std::wstring yellow{Format::Fg::BrightYellow.Get()};
@@ -190,90 +190,90 @@ class WSLCCLIReporterUnitTests
190 VERIFY_ARE_EQUAL(expected, cap.captured());
191 }
192
193 - TEST_METHOD(Reporter_LevelColorSuppressedWhenVTDisabled)
193 + TEST_METHOD(Terminal_LevelColorSuppressedWhenVTDisabled)
194 {
195 - CaptureReporter cap{/*vtEnabled*/ false};
196 - cap.reporter.Error(L"failed\n");
195 + CaptureTerminal cap{/*vtEnabled*/ false};
196 + cap.terminal.Error(L"failed\n");
197 VERIFY_ARE_EQUAL(std::wstring{L"failed\n"}, cap.captured());
198 }
199
200 - TEST_METHOD(Reporter_LevelColorSuppressedWhenNoColor)
200 + TEST_METHOD(Terminal_LevelColorSuppressedWhenNoColor)
201 {
202 - CaptureReporter cap{/*vtEnabled*/ true};
203 - cap.reporter.SetNoColor(true);
204 - cap.reporter.Warn(L"careful\n");
202 + CaptureTerminal cap{/*vtEnabled*/ true};
203 + cap.terminal.SetNoColor(true);
204 + cap.terminal.Warn(L"careful\n");
205 VERIFY_ARE_EQUAL(std::wstring{L"careful\n"}, cap.captured());
206 }
207
208 - TEST_METHOD(Reporter_RoutingByLevel)
208 + TEST_METHOD(Terminal_RoutingByLevel)
209 {
210 - SplitCaptureReporter cap;
210 + SplitCaptureTerminal cap;
211
212 - cap.reporter.Output(L"output text\n");
213 - cap.reporter.Info(L"info text\n");
214 - cap.reporter.Warn(L"warn text\n");
215 - cap.reporter.Error(L"error text\n");
212 + cap.terminal.Output(L"output text\n");
213 + cap.terminal.Info(L"info text\n");
214 + cap.terminal.Warn(L"warn text\n");
215 + cap.terminal.Error(L"error text\n");
216
217 VERIFY_ARE_EQUAL(std::wstring{L"output text\n"}, cap.outPipe.captured());
218 VERIFY_ARE_EQUAL(std::wstring{L"info text\nwarn text\nerror text\n"}, cap.errPipe.captured());
219 }
220
221 - TEST_METHOD(Reporter_SetNoColorTogglesIsNoColor)
221 + TEST_METHOD(Terminal_SetNoColorTogglesIsNoColor)
222 {
223 - CaptureReporter cap;
224 - VERIFY_IS_FALSE(cap.reporter.IsNoColor());
225 - cap.reporter.SetNoColor(true);
226 - VERIFY_IS_TRUE(cap.reporter.IsNoColor());
227 - cap.reporter.SetNoColor(false);
228 - VERIFY_IS_FALSE(cap.reporter.IsNoColor());
223 + CaptureTerminal cap;
224 + VERIFY_IS_FALSE(cap.terminal.IsNoColor());
225 + cap.terminal.SetNoColor(true);
226 + VERIFY_IS_TRUE(cap.terminal.IsNoColor());
227 + cap.terminal.SetNoColor(false);
228 + VERIFY_IS_FALSE(cap.terminal.IsNoColor());
229 }
230
231 - TEST_METHOD(Reporter_IsVTEnabledReflectsPerChannelState)
231 + TEST_METHOD(Terminal_IsVTEnabledReflectsPerChannelState)
232 {
233 {
234 - SplitCaptureReporter cap{/*vt*/ false};
235 - VERIFY_IS_FALSE(cap.reporter.IsVTEnabled(Reporter::Level::Output));
236 - VERIFY_IS_FALSE(cap.reporter.IsVTEnabled(Reporter::Level::Error));
234 + SplitCaptureTerminal cap{/*vt*/ false};
235 + VERIFY_IS_FALSE(cap.terminal.IsVTEnabled(Terminal::Level::Output));
236 + VERIFY_IS_FALSE(cap.terminal.IsVTEnabled(Terminal::Level::Error));
237 }
238 {
239 - SplitCaptureReporter cap{/*vt*/ true};
240 - VERIFY_IS_TRUE(cap.reporter.IsVTEnabled(Reporter::Level::Output));
241 - VERIFY_IS_TRUE(cap.reporter.IsVTEnabled(Reporter::Level::Error));
239 + SplitCaptureTerminal cap{/*vt*/ true};
240 + VERIFY_IS_TRUE(cap.terminal.IsVTEnabled(Terminal::Level::Output));
241 + VERIFY_IS_TRUE(cap.terminal.IsVTEnabled(Terminal::Level::Error));
242 }
243 {
244 CapturePipe outPipe;
245 CapturePipe errPipe;
246 - Reporter reporter{outPipe.file(), /*outVt*/ true, errPipe.file(), /*errVt*/ false};
247 - VERIFY_IS_TRUE(reporter.IsVTEnabled(Reporter::Level::Output));
248 - VERIFY_IS_FALSE(reporter.IsVTEnabled(Reporter::Level::Info));
249 - VERIFY_IS_FALSE(reporter.IsVTEnabled(Reporter::Level::Warning));
250 - VERIFY_IS_FALSE(reporter.IsVTEnabled(Reporter::Level::Error));
246 + Terminal terminal{outPipe.file(), /*outVt*/ true, errPipe.file(), /*errVt*/ false};
247 + VERIFY_IS_TRUE(terminal.IsVTEnabled(Terminal::Level::Output));
248 + VERIFY_IS_FALSE(terminal.IsVTEnabled(Terminal::Level::Info));
249 + VERIFY_IS_FALSE(terminal.IsVTEnabled(Terminal::Level::Warning));
250 + VERIFY_IS_FALSE(terminal.IsVTEnabled(Terminal::Level::Error));
251 }
252 }
253
254 - TEST_METHOD(Reporter_IsColorEnabledPerLevelHonorsBothVTAndNoColor)
254 + TEST_METHOD(Terminal_IsColorEnabledPerLevelHonorsBothVTAndNoColor)
255 {
256 - SplitCaptureReporter cap{/*vt*/ true};
257 - VERIFY_IS_TRUE(cap.reporter.IsColorEnabled(Reporter::Level::Output));
258 - VERIFY_IS_TRUE(cap.reporter.IsColorEnabled(Reporter::Level::Error));
256 + SplitCaptureTerminal cap{/*vt*/ true};
257 + VERIFY_IS_TRUE(cap.terminal.IsColorEnabled(Terminal::Level::Output));
258 + VERIFY_IS_TRUE(cap.terminal.IsColorEnabled(Terminal::Level::Error));
259
260 - cap.reporter.SetNoColor(true);
261 - VERIFY_IS_FALSE(cap.reporter.IsColorEnabled(Reporter::Level::Output));
262 - VERIFY_IS_FALSE(cap.reporter.IsColorEnabled(Reporter::Level::Error));
260 + cap.terminal.SetNoColor(true);
261 + VERIFY_IS_FALSE(cap.terminal.IsColorEnabled(Terminal::Level::Output));
262 + VERIFY_IS_FALSE(cap.terminal.IsColorEnabled(Terminal::Level::Error));
263 }
264
265 - TEST_METHOD(Reporter_GetConsoleWidthReturnsNulloptForFileChannels)
265 + TEST_METHOD(Terminal_GetConsoleWidthReturnsNulloptForFileChannels)
266 {
267 - SplitCaptureReporter cap;
268 - VERIFY_IS_FALSE(cap.reporter.GetConsoleWidth(Reporter::Level::Output).has_value());
269 - VERIFY_IS_FALSE(cap.reporter.GetConsoleWidth(Reporter::Level::Info).has_value());
270 - VERIFY_IS_FALSE(cap.reporter.GetConsoleWidth(Reporter::Level::Warning).has_value());
271 - VERIFY_IS_FALSE(cap.reporter.GetConsoleWidth(Reporter::Level::Error).has_value());
267 + SplitCaptureTerminal cap;
268 + VERIFY_IS_FALSE(cap.terminal.GetConsoleWidth(Terminal::Level::Output).has_value());
269 + VERIFY_IS_FALSE(cap.terminal.GetConsoleWidth(Terminal::Level::Info).has_value());
270 + VERIFY_IS_FALSE(cap.terminal.GetConsoleWidth(Terminal::Level::Warning).has_value());
271 + VERIFY_IS_FALSE(cap.terminal.GetConsoleWidth(Terminal::Level::Error).has_value());
272 }
273
274 - TEST_METHOD(Reporter_Write_MixesSequencesWithStandardFormatArgs)
274 + TEST_METHOD(Terminal_Write_MixesSequencesWithStandardFormatArgs)
275 {
276 - // Reporter.Write is std::format under the hood — any formattable type works
276 + // Terminal.Write is std::format under the hood — any formattable type works
277 // alongside Sequences. Sequences are stripped when color is off; everything
278 // else formats normally through std::format machinery.
279 //
@@ -295,8 +295,8 @@ class WSLCCLIReporterUnitTests
295
296 // VT + color enabled: equivalent to std::format with all sequence bytes.
297 {
298 - CaptureReporter cap{/*vtEnabled*/ true};
299 - cap.reporter.Output(fmt, Format::Fg::BrightRed, 42, 255u, eraseLine, linkOpen, linkClose, Format::Default);
298 + CaptureTerminal cap{/*vtEnabled*/ true};
299 + cap.terminal.Output(fmt, Format::Fg::BrightRed, 42, 255u, eraseLine, linkOpen, linkClose, Format::Default);
300
301 const auto expected = std::format(
302 fmt, Format::Fg::BrightRed.Get(), 42, 255u, eraseLine.Get(), linkOpen.Get(), linkClose.Get(), Format::Default.Get());
@@ -306,9 +306,9 @@ class WSLCCLIReporterUnitTests
306 // NoColor (VT enabled, color disabled): non-color sequences pass through,
307 // color sequences (SGR, hyperlink) replaced with empty string.
308 {
309 - CaptureReporter cap{/*vtEnabled*/ true};
310 - cap.reporter.SetNoColor(true);
311 - cap.reporter.Output(fmt, Format::Fg::BrightRed, 42, 255u, eraseLine, linkOpen, linkClose, Format::Default);
309 + CaptureTerminal cap{/*vtEnabled*/ true};
310 + cap.terminal.SetNoColor(true);
311 + cap.terminal.Output(fmt, Format::Fg::BrightRed, 42, 255u, eraseLine, linkOpen, linkClose, Format::Default);
312
313 const std::wstring_view empty;
314 const auto expected = std::format(fmt, empty, 42, 255u, eraseLine.Get(), empty, empty, empty);
@@ -317,8 +317,8 @@ class WSLCCLIReporterUnitTests
317
318 // VT disabled: all sequences replaced with empty string.
319 {
320 - CaptureReporter cap{/*vtEnabled*/ false};
321 - cap.reporter.Output(fmt, Format::Fg::BrightRed, 42, 255u, eraseLine, linkOpen, linkClose, Format::Default);
320 + CaptureTerminal cap{/*vtEnabled*/ false};
321 + cap.terminal.Output(fmt, Format::Fg::BrightRed, 42, 255u, eraseLine, linkOpen, linkClose, Format::Default);
322
323 const std::wstring_view empty;
324 const auto expected = std::format(fmt, empty, 42, 255u, empty, empty, empty, empty);
@@ -461,28 +461,28 @@ class WSLCCLIReporterUnitTests
461 VERIFY_IS_FALSE(channel.ReadLine(false).has_value());
462 }
463
464 - TEST_METHOD(Reporter_ReadLineReturnsInput)
464 + TEST_METHOD(Terminal_ReadLineReturnsInput)
465 {
466 - InputCaptureReporter cap{L"line1\nline2\n"};
467 - VERIFY_ARE_EQUAL(std::wstring{L"line1"}, cap.reporter.ReadLine().value_or(L"<eof>"));
468 - VERIFY_ARE_EQUAL(std::wstring{L"line2"}, cap.reporter.ReadLine().value_or(L"<eof>"));
469 - VERIFY_IS_FALSE(cap.reporter.ReadLine().has_value());
466 + InputCaptureTerminal cap{L"line1\nline2\n"};
467 + VERIFY_ARE_EQUAL(std::wstring{L"line1"}, cap.terminal.ReadLine().value_or(L"<eof>"));
468 + VERIFY_ARE_EQUAL(std::wstring{L"line2"}, cap.terminal.ReadLine().value_or(L"<eof>"));
469 + VERIFY_IS_FALSE(cap.terminal.ReadLine().has_value());
470 }
471
472 - TEST_METHOD(Reporter_IsInputInteractiveReflectsChannel)
472 + TEST_METHOD(Terminal_IsInputInteractiveReflectsChannel)
473 {
474 - InputCaptureReporter pipeInput{L"x\n", /*interactive*/ false};
475 - VERIFY_IS_FALSE(pipeInput.reporter.IsInputInteractive());
474 + InputCaptureTerminal pipeInput{L"x\n", /*interactive*/ false};
475 + VERIFY_IS_FALSE(pipeInput.terminal.IsInputInteractive());
476
477 - InputCaptureReporter consoleInput{L"x\n", /*interactive*/ true};
478 - VERIFY_IS_TRUE(consoleInput.reporter.IsInputInteractive());
477 + InputCaptureTerminal consoleInput{L"x\n", /*interactive*/ true};
478 + VERIFY_IS_TRUE(consoleInput.terminal.IsInputInteractive());
479 }
480
481 - TEST_METHOD(Reporter_PromptForLineWritesLabelToStdoutAndReturnsInput)
481 + TEST_METHOD(Terminal_PromptForLineWritesLabelToStdoutAndReturnsInput)
482 {
483 - InputCaptureReporter cap{L"myuser\n"};
483 + InputCaptureTerminal cap{L"myuser\n"};
484
485 - const auto result = cap.reporter.PromptForLine(Reporter::Level::Output, L"Username: ", false);
485 + const auto result = cap.terminal.PromptForLine(Terminal::Level::Output, L"Username: ", false);
486 VERIFY_ARE_EQUAL(std::wstring{L"myuser"}, result);
487
488 // Label lands on stdout (Docker convention); nothing on stderr; no trailing
@@ -491,77 +491,77 @@ class WSLCCLIReporterUnitTests
491 VERIFY_ARE_EQUAL(std::wstring{L""}, cap.errPipe.captured());
492 }
493
494 - TEST_METHOD(Reporter_PromptForLineMaskedInteractiveEmitsTrailingNewline)
494 + TEST_METHOD(Terminal_PromptForLineMaskedInteractiveEmitsTrailingNewline)
495 {
496 // Interactive override makes willMask true, so the un-echoed Enter is advanced
497 // with a trailing newline after the label.
498 - InputCaptureReporter cap{L"secret\n", /*interactive*/ true};
498 + InputCaptureTerminal cap{L"secret\n", /*interactive*/ true};
499
500 - const auto result = cap.reporter.PromptForLine(Reporter::Level::Output, L"Password: ", true);
500 + const auto result = cap.terminal.PromptForLine(Terminal::Level::Output, L"Password: ", true);
501 VERIFY_ARE_EQUAL(std::wstring{L"secret"}, result);
502 VERIFY_ARE_EQUAL(std::wstring{L"Password: \n"}, cap.outPipe.captured());
503 }
504
505 - TEST_METHOD(Reporter_PromptForLineMaskedNonInteractiveEmitsNoTrailingNewline)
505 + TEST_METHOD(Terminal_PromptForLineMaskedNonInteractiveEmitsNoTrailingNewline)
506 {
507 // Redirected input is not interactive, so no masking and no trailing newline.
508 - InputCaptureReporter cap{L"secret\n", /*interactive*/ false};
508 + InputCaptureTerminal cap{L"secret\n", /*interactive*/ false};
509
510 - const auto result = cap.reporter.PromptForLine(Reporter::Level::Output, L"Password: ", true);
510 + const auto result = cap.terminal.PromptForLine(Terminal::Level::Output, L"Password: ", true);
511 VERIFY_ARE_EQUAL(std::wstring{L"secret"}, result);
512 VERIFY_ARE_EQUAL(std::wstring{L"Password: "}, cap.outPipe.captured());
513 }
514
515 - TEST_METHOD(Reporter_PromptForLineReturnsEmptyStringAtEof)
515 + TEST_METHOD(Terminal_PromptForLineReturnsEmptyStringAtEof)
516 {
517 - InputCaptureReporter cap{L""};
518 - const auto result = cap.reporter.PromptForLine(Reporter::Level::Output, L"Username: ", false);
517 + InputCaptureTerminal cap{L""};
518 + const auto result = cap.terminal.PromptForLine(Terminal::Level::Output, L"Username: ", false);
519 VERIFY_ARE_EQUAL(std::wstring{L""}, result);
520 VERIFY_ARE_EQUAL(std::wstring{L"Username: "}, cap.outPipe.captured());
521 }
522
523 - TEST_METHOD(Reporter_PromptForLineEmitsLabelVerbatimWithFormatCharacters)
523 + TEST_METHOD(Terminal_PromptForLineEmitsLabelVerbatimWithFormatCharacters)
524 {
525 // The label is passed as a formatting argument, not a format string, so brace
526 // and percent characters in it must never be interpreted (no format injection).
527 - InputCaptureReporter cap{L"answer\n"};
527 + InputCaptureTerminal cap{L"answer\n"};
528 const std::wstring label = L"Value {} {0} {name} 100% ${var}: ";
529
530 - const auto result = cap.reporter.PromptForLine(Reporter::Level::Output, label, false);
530 + const auto result = cap.terminal.PromptForLine(Terminal::Level::Output, label, false);
531 VERIFY_ARE_EQUAL(std::wstring{L"answer"}, result);
532 VERIFY_ARE_EQUAL(label, cap.outPipe.captured());
533 }
534
535 - TEST_METHOD(Reporter_PromptForLineDoesNotTrimPasswordWhitespace)
535 + TEST_METHOD(Terminal_PromptForLineDoesNotTrimPasswordWhitespace)
536 {
537 // Secrets are opaque: interior and surrounding whitespace is preserved so a
538 // password like " a b " is returned exactly as typed.
539 - InputCaptureReporter cap{L" a b \n", /*interactive*/ true};
539 + InputCaptureTerminal cap{L" a b \n", /*interactive*/ true};
540
541 - const auto result = cap.reporter.PromptForLine(Reporter::Level::Output, L"Password: ", true);
541 + const auto result = cap.terminal.PromptForLine(Terminal::Level::Output, L"Password: ", true);
542 VERIFY_ARE_EQUAL(std::wstring{L" a b "}, result);
543 VERIFY_ARE_EQUAL(std::wstring{L"Password: \n"}, cap.outPipe.captured());
544 }
545
546 - TEST_METHOD(Reporter_PromptForLineReturnsUnicodeInput)
546 + TEST_METHOD(Terminal_PromptForLineReturnsUnicodeInput)
547 {
548 const std::wstring expected = L"\u00fcser\u00f1ame";
549 - InputCaptureReporter cap{expected + L"\n"};
549 + InputCaptureTerminal cap{expected + L"\n"};
550
551 - const auto result = cap.reporter.PromptForLine(Reporter::Level::Output, L"Username: ", false);
551 + const auto result = cap.terminal.PromptForLine(Terminal::Level::Output, L"Username: ", false);
552 VERIFY_ARE_EQUAL(expected, result);
553 }
554
555 - TEST_METHOD(Reporter_ReadLineMaskDefaultsToUnmasked)
555 + TEST_METHOD(Terminal_ReadLineMaskDefaultsToUnmasked)
556 {
557 // ReadLine(bool mask = false): the default reads without masking and returns
558 // the line, used by the --password-stdin path.
559 - InputCaptureReporter cap{L"piped-secret\n"};
560 - VERIFY_ARE_EQUAL(std::wstring{L"piped-secret"}, cap.reporter.ReadLine().value_or(L"<eof>"));
559 + InputCaptureTerminal cap{L"piped-secret\n"};
560 + VERIFY_ARE_EQUAL(std::wstring{L"piped-secret"}, cap.terminal.ReadLine().value_or(L"<eof>"));
561 // Nothing is written for a bare ReadLine (no prompt label).
562 VERIFY_ARE_EQUAL(std::wstring{L""}, cap.outPipe.captured());
563 VERIFY_ARE_EQUAL(std::wstring{L""}, cap.errPipe.captured());
564 }
565 };
566
567 -} // namespace WSLCCLIReporterUnitTests
567 +} // namespace WSLCCLITerminalUnitTests
test/windows/wslc/WSLCCLITestHelpers.h
+11 -11
@@ -28,7 +28,7 @@ Abstract:
28 #include "windows/Common.h"
29 #include "Invocation.h"
30 #include "OutputChannel.h"
31 -#include "Reporter.h"
31 +#include "Terminal.h"
32 #include "TableOutput.h"
33
34 namespace WSLCTestHelpers {
@@ -74,7 +74,7 @@ inline void LogComment(const std::wstring& message)
74 }
75
76 // RAII pipe pair for capturing FILE* output in tests.
77 -// file() is passed to OutputChannel/Reporter; captured() drains the read end after flush.
77 +// file() is passed to OutputChannel/Terminal; captured() drains the read end after flush.
78 struct CapturePipe
79 {
80 CapturePipe()
@@ -138,7 +138,7 @@ private:
138 // (OpenAnonymousPipe defaults to 4096 bytes), so the feeder runs concurrently and
139 // closes the write end when done, letting file() read the content then hit EOF. The
140 // read FILE* is configured like real stdin (_O_U8TEXT) and passed to
141 -// InputChannel/Reporter.
141 +// InputChannel/Terminal.
142 struct InputPipe
143 {
144 explicit InputPipe(const std::wstring& content)
@@ -196,14 +196,14 @@ private:
196 std::thread m_writer;
197 };
198
199 -// Reporter wired to a single capture pipe for full output capture.
199 +// Terminal wired to a single capture pipe for full output capture.
200 // VT is disabled (not a console handle), so error output stays in the same pipe.
201 -struct CaptureReporter
201 +struct CaptureTerminal
202 {
203 CapturePipe pipe;
204 - wsl::windows::wslc::Reporter reporter;
204 + wsl::windows::wslc::Terminal terminal;
205
206 - explicit CaptureReporter(bool vtEnabled = false) : reporter(pipe.file(), vtEnabled, pipe.file(), vtEnabled)
206 + explicit CaptureTerminal(bool vtEnabled = false) : terminal(pipe.file(), vtEnabled, pipe.file(), vtEnabled)
207 {
208 }
209
@@ -217,7 +217,7 @@ struct CaptureReporter
217 template <size_t N>
218 struct TableOutputCapture
219 {
220 - CaptureReporter capture;
220 + CaptureTerminal capture;
221 wsl::windows::wslc::TableOutput<N> table;
222
223 // Header + optional config + optional VT flag.
@@ -226,7 +226,7 @@ struct TableOutputCapture
226 size_t sizingBuffer = 50,
227 size_t columnPadding = wsl::windows::wslc::TableOutput<N>::DefaultColumnPadding,
228 bool vtEnabled = false) :
229 - capture(vtEnabled), table(capture.reporter, std::move(header), sizingBuffer, columnPadding)
229 + capture(vtEnabled), table(capture.terminal, std::move(header), sizingBuffer, columnPadding)
230 {
231 table.SetConsoleWidthOverride(120);
232 }
@@ -237,14 +237,14 @@ struct TableOutputCapture
237 typename wsl::windows::wslc::TableOutput<N>::column_config_t&& configs,
238 bool vtEnabled = false) :
239 capture(vtEnabled),
240 - table(capture.reporter, std::move(header), std::move(configs), 50, wsl::windows::wslc::TableOutput<N>::DefaultColumnPadding)
240 + table(capture.terminal, std::move(header), std::move(configs), 50, wsl::windows::wslc::TableOutput<N>::DefaultColumnPadding)
241 {
242 table.SetConsoleWidthOverride(120);
243 }
244
245 // Column definitions.
246 explicit TableOutputCapture(typename wsl::windows::wslc::TableOutput<N>::column_def_t&& defs, bool vtEnabled = false) :
247 - capture(vtEnabled), table(capture.reporter, std::move(defs))
247 + capture(vtEnabled), table(capture.terminal, std::move(defs))
248 {
249 table.SetConsoleWidthOverride(120);
250 }
test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp
+2 -2
@@ -89,7 +89,7 @@ class WSLCE2EGlobalTests
89
90 WSLC_TEST_METHOD(WSLCE2E_Help_NoColorWhenRedirected)
91 {
92 - // Captured via anonymous pipe; Reporter must suppress VT escape sequences.
92 + // Captured via anonymous pipe; Terminal must suppress VT escape sequences.
93 auto result = RunWslc(L"--help");
94 result.Verify({.Stderr = L"", .ExitCode = 0});
95 VERIFY_ARE_EQUAL(std::wstring::npos, result.Stdout.value().find(L'\x1b'));
@@ -97,7 +97,7 @@ class WSLCE2EGlobalTests
97
98 WSLC_TEST_METHOD(WSLCE2E_Help_ColorOnTerminal)
99 {
100 - // Pseudo console reports VT support; Reporter should emit SGR sequences.
100 + // Pseudo console reports VT support; Terminal should emit SGR sequences.
101 auto session = RunWslcInteractive(L"--help", ElevationType::Elevated, PseudoConsole{120, 30});
102 session.WaitForExit();
103 VERIFY_IS_TRUE(session.GetStdoutData().find('\x1b') != std::string::npos);