High-precision calculations for one- and two-valence atomic systems
qip::LiveMessage

ok

Live status line for iterative loops; overwrites itself on a TTY.

Construct before the loop, call operator() each iteration with the current status message, then call done() (optionally with a trailing annotation) when the loop finishes. The destructor calls done() automatically if it has not been called explicitly, so early returns and exceptions are handled cleanly.

Behaviour depends on whether stdout is a TTY:

  • TTY: each operator() call prints \r{header}{msg} and flushes, overwriting the current line. done() prints \r{header}{last_msg}{post}\n.
  • Non-TTY: the header is printed on construction; operator() calls are silent (but the message is buffered). done() prints {last_msg}{post}\n. This gives one clean output line with no intermediate churn.

If active is false all methods are no-ops (runtime print toggle).

Typical usage:

bool print_message = true;
qip::LiveMessage status("Method iterations: ", print_message);
for (int it = 0; it < max_its; ++it) {
// ... work ...
status(fmt::format("{:2d} {:.1e} [{}]", it, eps, worst));
if (condition)
break;
}
// optional trailing annotation; destructor calls done() otherwise
status.done(" Finished");
Live status line for iterative loops; overwrites itself on a TTY.
Definition Widgets.hpp:48
Parameters
headerFixed prefix, always printed (on construction for non-TTY, or on every line for TTY).
activeIf false, all methods are no-ops. Default true.

#include <Widgets.hpp>

Public Member Functions

 LiveMessage (std::string_view header, bool active=true)
 
 LiveMessage (const LiveMessage &)=delete
 
LiveMessageoperator= (const LiveMessage &)=delete
 
void update (std::string_view msg)
 Update the status message. On TTY overwrites the current line; on non-TTY buffers silently until done() is called.
 
void operator() (std::string_view msg)
 Update the status message. see update()
 
void done (std::string_view post={})
 Finalise: print last message + optional post, then newline. Safe to call multiple times (only the first call has effect).
 

Member Function Documentation

◆ update()

void qip::LiveMessage::update ( std::string_view  msg)
inline

Update the status message. On TTY overwrites the current line; on non-TTY buffers silently until done() is called.

◆ operator()()

void qip::LiveMessage::operator() ( std::string_view  msg)
inline

Update the status message. see update()

◆ done()

void qip::LiveMessage::done ( std::string_view  post = {})
inline

Finalise: print last message + optional post, then newline. Safe to call multiple times (only the first call has effect).


The documentation for this class was generated from the following file: