forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecutionProgress.h
More file actions
89 lines (68 loc) · 2.62 KB
/
Copy pathExecutionProgress.h
File metadata and controls
89 lines (68 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include "VTSupport.h"
#include <AppInstallerProgress.h>
#include <AppInstallerStrings.h>
#include <winget/UserSettings.h>
#include <ChannelStreams.h>
#include <wil/resource.h>
#include <atomic>
#include <future>
#include <istream>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
namespace AppInstaller::CLI::Execution
{
namespace details
{
// Shared functionality for progress visualizers.
struct ProgressVisualizerBase
{
ProgressVisualizerBase(BaseStream& stream, bool enableVT) :
m_out(stream), m_enableVT(enableVT) {}
void SetStyle(AppInstaller::Settings::VisualStyle style) { m_style = style; }
void Message(std::string_view message);
std::shared_ptr<Utility::NormalizedString> Message();
protected:
BaseStream& m_out;
Settings::VisualStyle m_style = AppInstaller::Settings::VisualStyle::Accent;
bool UseVT() const { return m_enableVT && m_style != AppInstaller::Settings::VisualStyle::NoVT; }
// Applies the selected visual style.
void ApplyStyle(size_t i, size_t max, bool foregroundOnly);
void ClearLine();
private:
bool m_enableVT = false;
std::shared_ptr<Utility::NormalizedString> m_message;
};
}
// Displays an indefinite spinner.
struct IndefiniteSpinner : public details::ProgressVisualizerBase
{
IndefiniteSpinner(BaseStream& stream, bool enableVT) :
details::ProgressVisualizerBase(stream, enableVT) {}
void ShowSpinner();
void StopSpinner();
private:
std::atomic<bool> m_canceled = false;
std::atomic<bool> m_spinnerRunning = false;
std::future<void> m_spinnerJob;
void ShowSpinnerInternal();
};
// Displays progress
class ProgressBar : public details::ProgressVisualizerBase
{
public:
ProgressBar(BaseStream& stream, bool enableVT) :
details::ProgressVisualizerBase(stream, enableVT) {}
void ShowProgress(uint64_t current, uint64_t maximum, ProgressType type);
void EndProgress(bool hideProgressWhenDone);
private:
std::atomic<bool> m_isVisible = false;
uint64_t m_lastCurrent = 0;
void ShowProgressNoVT(uint64_t current, uint64_t maximum, ProgressType type);
void ShowProgressWithVT(uint64_t current, uint64_t maximum, ProgressType type);
};
}