13#include <fmt/format.h>
38 template<
typename... Args>
void println(fmt::format_string<Args...> fmt_str, Args&&... args)
const {
41 fmt::print(fmt_str, std::forward<Args>(args)...);
51 template<
typename... Args>
void print(fmt::format_string<Args...> fmt_str, Args&&... args)
const {
54 fmt::print(fmt_str, std::forward<Args>(args)...);
70 void flush()
const { std::fflush(stdout); }
77 template<
typename... Args>
void errorln(fmt::format_string<Args...> fmt_str, Args&&... args)
const {
78 fmt::print(stderr, fmt_str, std::forward<Args>(args)...);
79 fmt::print(stderr,
"\n");
96 void saved(std::string
const& label, std::string
const& path)
const {
println(
"{} saved to {}", label, path); }
104 void progress(
int current,
int total,
int bar_width = 50)
const {
108 float pct =
static_cast<float>(current) / total;
109 int pos =
static_cast<int>(bar_width * pct);
112 std::string bar = std::string(pos,
'-') + std::string(bar_width - pos,
' ');
114 if (current == total) {
120 fmt::print(
"\r{:{}}" + bar_tpl +
" {}/{} ({}%) ",
126 static_cast<int>(pct * 100.0));
129 if (current == total) {
140 int try_or_fail(std::function<
void()>
const& f, std::string
const& context =
"")
const {
144 }
catch (std::exception
const& e) {
145 if (context.empty()) {
156 void print_indent()
const {
TTY-aware colored terminal output utilities.
std::string error(std::string const &s)
Format text in red (for error messages).
Definition Color.hpp:86
std::string info(std::string const &s)
Format text in cyan (for informational highlights like progress bars).
Definition Color.hpp:120
std::string emphasis(std::string const &s)
Format text in bold (for emphasis / labels).
Definition Color.hpp:103
std::string success(std::string const &s)
Format text in green (for success messages).
Definition Color.hpp:93
void flush() const
Flush stdout. For interactive output like progress bars.
Definition Output.hpp:70
void progress(int current, int total, int bar_width=50) const
Display a carriage-return progress bar.
Definition Output.hpp:104
Output(bool quiet)
Definition Output.hpp:30
void print(fmt::format_string< Args... > fmt_str, Args &&... args) const
Print indent + formatted content, no newline.
Definition Output.hpp:51
void saved(std::string const &label, std::string const &path) const
Print a file-save confirmation: "label saved to path".
Definition Output.hpp:96
int indent_level
Definition Output.hpp:28
bool quiet
Definition Output.hpp:27
void errorln(fmt::format_string< Args... > fmt_str, Args &&... args) const
Print formatted content + newline to stderr. Always prints.
Definition Output.hpp:77
void newline() const
Print a blank line. For visual separation between sections.
Definition Output.hpp:61
void println(fmt::format_string< Args... > fmt_str, Args &&... args) const
Print indent + formatted content + newline. The workhorse.
Definition Output.hpp:38
void indent()
Definition Output.hpp:84
int try_or_fail(std::function< void()> const &f, std::string const &context="") const
Run a callable, catch std::exception, print error, return 1.
Definition Output.hpp:140
void dedent()
Definition Output.hpp:86