blob: 4c4c7c6fa2fbc7268a4b375b29ff518773854eb0 [file] [log] [blame]
Elliott Hughesf5cdc1d2015-10-27 16:03:15 -07001// Copyright 2013 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef NINJA_LINE_PRINTER_H_
16#define NINJA_LINE_PRINTER_H_
17
18#include <stddef.h>
19#include <string>
20
21/// Prints lines of text, possibly overprinting previously printed lines
22/// if the terminal supports it.
23struct LinePrinter {
24 LinePrinter();
25
26 bool is_smart_terminal() const { return smart_terminal_; }
27 void set_smart_terminal(bool smart) { smart_terminal_ = smart; }
28
Elliott Hughes78a37a52015-12-08 16:01:15 -080029 enum LineType { INFO, WARNING, ERROR };
30
31 /// Outputs the given line. INFO output will be overwritten.
32 /// WARNING and ERROR appear on a line to themselves.
Elliott Hughesf5cdc1d2015-10-27 16:03:15 -070033 void Print(std::string to_print, LineType type);
34
Elliott Hughes78a37a52015-12-08 16:01:15 -080035 /// If there's an INFO line, keep it. If not, do nothing.
36 void KeepInfoLine();
Elliott Hughesf5cdc1d2015-10-27 16:03:15 -070037
38 private:
39 /// Whether we can do fancy terminal control codes.
40 bool smart_terminal_;
41
42 /// Whether the caret is at the beginning of a blank line.
43 bool have_blank_line_;
44
Josh Gao77caacf2018-08-22 15:44:17 -070045 /// The last printed info line when printing to a dumb terminal.
46 std::string info_line_;
47
Elliott Hughesf5cdc1d2015-10-27 16:03:15 -070048#ifdef _WIN32
49 void* console_;
50#endif
Elliott Hughesf5cdc1d2015-10-27 16:03:15 -070051};
52
53#endif // NINJA_LINE_PRINTER_H_