forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelStreams.cpp
More file actions
103 lines (88 loc) · 2.84 KB
/
ChannelStreams.cpp
File metadata and controls
103 lines (88 loc) · 2.84 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "ChannelStreams.h"
namespace AppInstaller::CLI::Execution
{
using namespace Settings;
using namespace VirtualTerminal;
BaseStream::BaseStream(std::ostream& out, bool enabled, bool VTEnabled) :
m_out(out), m_enabled(enabled), m_VTEnabled(VTEnabled) {}
BaseStream& BaseStream::operator<<(std::ostream& (__cdecl* f)(std::ostream&))
{
if (m_enabled)
{
f(m_out);
}
return *this;
}
BaseStream& BaseStream::operator<<(const Sequence& sequence)
{
if (m_enabled && m_VTEnabled)
{
m_out << sequence;
}
return *this;
}
BaseStream& BaseStream::operator<<(const ConstructedSequence& sequence)
{
if (m_enabled && m_VTEnabled)
{
m_out << sequence;
}
return *this;
}
OutputStream::OutputStream(std::ostream& out, bool enabled, bool VTEnabled) :
m_out(out, enabled, VTEnabled) {}
void OutputStream::AddFormat(const Sequence& sequence)
{
m_format.Append(sequence);
}
void OutputStream::ApplyFormat()
{
// Only apply format if m_applyFormatAtOne == 1 coming into this function.
if (m_applyFormatAtOne)
{
if (!--m_applyFormatAtOne)
{
m_out << m_format;
}
}
}
OutputStream& OutputStream::operator<<(std::ostream& (__cdecl* f)(std::ostream&))
{
m_out << f;
return *this;
}
OutputStream& OutputStream::operator<<(const Sequence& sequence)
{
m_out << sequence;
// An incoming sequence will be valid for 1 "standard" output after this one.
// We set this to 2 to make that happen, because when it is 1, we will output
// the format for the current OutputStream.
m_applyFormatAtOne = 2;
return *this;
}
OutputStream& OutputStream::operator<<(const ConstructedSequence& sequence)
{
m_out << sequence;
// An incoming sequence will be valid for 1 "standard" output after this one.
// We set this to 2 to make that happen, because when it is 1, we will output
// the format for the current OutputStream.
m_applyFormatAtOne = 2;
return *this;
}
OutputStream& OutputStream::operator<<(const std::filesystem::path& path)
{
ApplyFormat();
m_out << path.u8string();
return *this;
}
NoVTStream::NoVTStream(std::ostream& out, bool enabled) :
m_out(out, enabled, false) {}
NoVTStream& NoVTStream::operator<<(std::ostream& (__cdecl* f)(std::ostream&))
{
m_out << f;
return *this;
}
}