peaclock

A colourful binary clock for the terminal.


peaclock

/

src

/

peaclock

/

readline.hh

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#ifndef READLINE_HH
#define READLINE_HH

#include "ob/term.hh"
namespace aec = OB::Term::ANSI_Escape_Codes;

#include <cstddef>

#include <string>
#include <vector>

class Readline
{
public:

  Readline();
  ~Readline();

  Readline& prompt(std::string const& str, std::vector<std::string> const& style = {});
  std::string operator()(bool& is_running);
  void add_history(std::string const& str);

private:

  int ctrl_key(int const c) const;
  std::string normalize(std::string const& str) const;

  struct Prompt
  {
    std::string str {":"};
    std::vector<std::string> style;
    std::string fmt {aec::wrap(str, style)};
  } _prompt;

  struct Input
  {
    std::size_t idx {0};
    std::size_t off {0};
    std::string buf;
    std::string str;
    std::string fmt;
  } _input;

  struct History
  {
    std::vector<std::string> val;
    std::size_t idx;
  } _history;
};

#endif // READLINE_HH
Back to Top