// Part of the Carbon Language project, under the Apache License v2.0 with LLVM // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #ifndef CARBON_COMMON_TERMINAL_STYLE_H_ #define CARBON_COMMON_TERMINAL_STYLE_H_ #include #include #include #include "common/ostream.h" #include "common/terminal/color.h" #include "common/terminal/output_buffer_ref.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" namespace Carbon::Terminal { // The shapes an underline can take. // // Only `Single` is universally understood. The rest are selected with // colon-separated subparameters of the Select Graphic Rendition (SGR) // underline code, which terminals limited to 16 colors mishandle, so in that // mode they degrade to `Single` rather than disappearing. enum class UnderlineShape : int8_t { None, Single, Double, Curly, Dotted, Dashed, }; // A set of colors and text attributes to render with. // // Styles are values, and are composed by chaining, which keeps a named style // readable at its definition: // // ```cpp // const Style Error = Style().Bold().Foreground(AnsiColor::BrightRed); // const Style ErrorSquiggle = Error.Underline(UnderlineShape::Curly); // ``` // // A style authored for a rich terminal stays meaningful on a poor one. Colors // the active `ColorMode` can't express are downsampled, an underline shape it // can't express becomes a plain underline, and an underline color it can't // express is left to the terminal. `NoColor` drops everything. class Style : public Printable