ascii_utils.hpp

Tools for working with ascii output.

This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2020 Michigan State University MIT Software license; see doc/LICENSE.md

Note

Status: ALPHA

Defines

INCLUDE_EMP_IO_ASCII_UTILS_HPP_GUARD

Functions

String IOCharName(IOChar key)
template<typename T>
void AsciiBarGraph(vector<T> data, size_t max_width = 80, bool show_scale = true, bool max_scale_1 = true, std::ostream &os = std::cout)

The following function prints an ascii bar graph on to the screen (or provided stream).

Parameters:
  • data – Data to graph

  • max_width – What’s the widest bars allowed?

  • show_scale – Should we show the scale at bottom.

  • max_scale_1 – Should we limit scaling to 1:1?

  • os – Where to output the bar graph?

template<typename T>
void AsciiHistogram(vector<T> data, size_t num_bins = 40, size_t max_width = 80, bool show_scale = true, std::ostream &os = std::cout)

Take the input data, break it into bins, and print it as a bar graph.

Parameters:
  • data – Data to graph

  • num_bins – How many bins in histogram?

  • max_width – What’s the widest bars allowed?

  • show_scale – Should we show the scale at bottom?

  • os – Where to output the bar graph?

class ANSIOptionMenu
#include <ascii_utils.hpp>

Public Functions

inline ANSIOptionMenu &SetQuestion(String in_q)
inline ANSIOptionMenu &AddOption(int key, String effect_text, std::function<bool()> trigger, bool is_add_on = false, bool is_active = true, bool is_visible = true)

Add an option to the menu.

inline ANSIOptionMenu &AddLinked(int key, String effect_text, std::function<bool()> trigger)

Add an option to the menu on the same line as the previous option, linked by an “or”.

inline ANSIOptionMenu &AddSilent(int key, String effect_text, std::function<bool()> trigger, bool is_add_on = false, bool is_active = true)

And an option that allows for a keystroke, but is not listed by default.

inline ANSIOptionMenu &AddAlias(int key)

Set up an additional key that will also trigger the most recent option.

inline ANSIOptionMenu &SetTrigger(int key, std::function<bool()> trigger)
inline void PrintOptions() const
inline void PrintHelp() const
inline void Run() const

Private Functions

inline Entry &GetEntryByKey(int key)

Private Members

String question
vector<Entry> entry_list
std::unordered_map<int, size_t> key_map
class Entry

Public Functions

inline Entry(int key, String effect_text, std::function<bool()> trigger, bool is_add_on = false, bool is_active = true, bool is_visible = true)
inline Entry(int key, String effect_text, std::function<void()> trigger, bool is_add_on = false, bool is_active = true, bool is_visible = true)
inline bool IsActive() const
inline bool IsVisible() const
inline void Print() const
inline void PrintActive() const
inline void PrintVisible() const
inline bool Trigger() const
inline void SetTrigger(std::function<bool()> new_trigger)

Private Members

IOChar key
String effect_text
std::function<bool()> trigger
bool is_add_on = false
bool is_active = true
bool is_visible = true