master
h 42 lines 1.18 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2
3 #pragma once
4
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 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(Terminal& terminal) : m_terminal(terminal)
18 {
19 }
20
21 HRESULT OnWarning(LPCWSTR Message) override
22 {
23 try
24 {
25 WI_ASSERT(Message);
26 if (Message != nullptr)
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_terminal.Warn(L"{}", Message);
31 }
32
33 return S_OK;
34 }
35 CATCH_RETURN();
36 }
37
38 private:
39 Terminal& m_terminal;
40 };
41
42 } // namespace wsl::windows::wslc::services