OpenMS
Loading...
Searching...
No Matches
ConsoleUtils.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Chris Bielow $
6// $Authors: Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/DATASTRUCTURES/ListUtils.h> // for StringList definition
12
13#include <limits>
14
15namespace OpenMS
16{
17
37 class OPENMS_DLLAPI ConsoleUtils
38 {
39 private:
42
43 public:
45 ConsoleUtils(const ConsoleUtils&) = delete;
46
48 void operator=(ConsoleUtils const&) = delete;
49
51 static const ConsoleUtils& getInstance();
52
74 static StringList breakStringList(const std::string& input, const Size indentation, const Size max_lines, const Size first_line_prefill = 0);
75
77 static std::string breakString(const std::string& input, const Size indentation, const Size max_lines, const Size first_line_prefill = 0);
78
80 int getConsoleWidth() const
81 {
82 return console_width_;
83 }
84
85 friend struct ConsoleWidthTest;
86
87 private:
89 int console_width_ = std::numeric_limits<int>::max();
90
93
95 StringList breakString_(const std::string& input, const Size indentation, const Size max_lines, Size first_line_prefill) const;
96 };
97
98} // namespace OpenMS
99
Singleton helper for terminal-width-aware string wrapping in TOPP-tool console output.
Definition ConsoleUtils.h:38
void operator=(ConsoleUtils const &)=delete
Assignment operator deleted (singleton)
static std::string breakString(const std::string &input, const Size indentation, const Size max_lines, const Size first_line_prefill=0)
Convenience wrapper around breakStringList that joins the result with "\\n".
static StringList breakStringList(const std::string &input, const Size indentation, const Size max_lines, const Size first_line_prefill=0)
Wrap input to the current console width and return one element per output line.
static const ConsoleUtils & getInstance()
Return the singleton instance (constructed on first call; thread-safe per Meyers-singleton rules)
StringList breakString_(const std::string &input, const Size indentation, const Size max_lines, Size first_line_prefill) const
Non-static implementation used by the public static wrappers; receives the cached console_width_.
int getConsoleWidth() const
Cached console width (or std::numeric_limits<int>::max() when detection failed and wrapping is effect...
Definition ConsoleUtils.h:80
ConsoleUtils()
Private ctor — caches the console width once; use getInstance to access.
ConsoleUtils(const ConsoleUtils &)=delete
Copy constructor deleted (singleton)
int readConsoleSize_()
Probe the host environment / terminal to determine the console width (also honours the COLUMNS env va...
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
std::vector< std::string > StringList
Vector of String.
Definition ListUtils.h:44
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19