@@ -24,15 +24,19 @@ std::string dirname(std::string path) {
24
24
25
25
class StreamProcessor {
26
26
public:
27
- StreamProcessor (){}
27
+ StreamProcessor (){
28
+ process_line (" [build start]" );
29
+ }
28
30
StreamProcessor (const std::string log_file) {
29
31
std::string dir = dirname (log_file);
30
32
if (!tea::path_exists (dir)) {
31
33
tea::mkdir_p (dir);
32
34
}
33
- FILE* fp = fopen (log_file.c_str (), " w" );
35
+ FILE* fp = nullptr ;
36
+ if (!log_file.empty ())
37
+ fp = fopen (log_file.c_str (), " w" );
34
38
if (fp == nullptr ) {
35
- log (" could not open for writing: " + log_file);
39
+ process_line (" could not open for writing: " + log_file);
36
40
} else {
37
41
m_log_file = std::make_unique<CFileOutputStream>(fp);
38
42
}
@@ -173,7 +177,7 @@ class StreamProcessor {
173
177
if (m_update_thread.joinable ())
174
178
m_update_thread.join ();
175
179
}
176
- CFileOutputStream_uptr m_log_file;
180
+ OutputStream_uptr m_log_file;
177
181
FileFilter m_file_filter;
178
182
subprocess::StopWatch m_stop_watch;
179
183
ProgressGraph m_progress;
@@ -195,6 +199,12 @@ std::vector<std::string> argv_to_vector(int argc, char** argv) {
195
199
return result;
196
200
}
197
201
202
+ struct CinStream : buildhl::InputStream {
203
+ ssize_t read (void * buffer, size_t size) override {
204
+ return fread (buffer, 1 , size, stdin);
205
+ }
206
+ };
207
+
198
208
int main (int argc, char ** argv) {
199
209
for (int i = 1 ; i < argc; ++i) {
200
210
if (strcmp (argv[i], " --version" ) == 0 ) {
@@ -205,10 +215,10 @@ int main(int argc, char** argv) {
205
215
}
206
216
207
217
if (argc == 2 && strcmp (argv[1 ], " -" ) == 0 ) {
208
- for (std::string line; std::getline (std::cin, line);) {
209
- line = color_line (line );
210
- std::cout << line << ' \n ' ;
211
- }
218
+ StreamProcessor stream_processor;
219
+ stream_processor. add_search_path ( tea::getcwd () );
220
+ CinStream cin ;
221
+ stream_processor. process (cin);
212
222
return 0 ;
213
223
}
214
224
0 commit comments