master
h 48 lines 1.61 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 ImageProgressCallback.h
8
9 Abstract:
10
11 This file contains the ImageProgressCallback definition
12
13 --*/
14 #pragma once
15 #include "Terminal.h"
16 #include "SessionService.h"
17 #include "VTSupport.h"
18 #include <map>
19 #include <string>
20
21 namespace wsl::windows::wslc::services {
22
23 // TODO: Handle terminal resizes.
24 class DECLSPEC_UUID("7A1D3376-835A-471A-8DC9-23653D9962D0") ImageProgressCallback
25 : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IProgressCallback, IFastRundown>
26 {
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(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;
34
35 private:
36 auto MoveToLine(int line);
37 std::wstring GenerateStatusLine(LPCSTR status, LPCSTR id, ULONGLONG current, ULONGLONG total, int visibleWidth);
38 Terminal& m_terminal;
39 // Declared before m_vtEnabled, whose initializer reads it.
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_terminal.IsVTEnabled(m_level);
47 };
48 } // namespace wsl::windows::wslc::services