52int truth(
const std::string& value);
59 plain,
frame,
title,
heading,
dim,
label,
key,
code,
ok,
warn,
error,
accent,
80 using Check = std::function<std::string(
const std::vector<std::string>&)>;
88 std::vector<Line>
render(
int rows,
int cols)
const;
90 std::vector<std::string>
args()
const;
107 bool dirty(
Scope s)
const {
return dirty_[
static_cast<int>(s)]; }
112 bool set(
const std::string& name,
const std::string& value);
115 const std::string&
save_path()
const {
return path_[
static_cast<int>(target_)]; }
118 const std::string&
status()
const {
return status_; }
119 const std::string&
error()
const {
return error_; }
120 const std::vector<Field>&
fields()
const {
return fields_; }
123 enum class Mode { list, edit, filter,
save };
124 std::vector<std::size_t> visible()
const;
126 bool edit_key(
int k);
127 Scope home(
const Field& f)
const {
return f.save ? target_ :
Scope::run; }
128 void refresh(Field& f)
const;
129 void put(Field& f, std::string value);
130 void next_target(
int step);
132 std::string command_;
133 std::vector<Field> fields_;
135 Mode mode_ = Mode::list;
136 std::size_t sel_ = 0;
137 mutable std::size_t top_ = 0;
138 bool show_hidden_ =
false;
139 std::string filter_, buffer_, status_, error_;
141 bool enabled_[
kScopes] = {
false,
false,
false,
true};
142 bool exists_[
kScopes] = {
false,
false,
false,
false};
143 bool dirty_[
kScopes] = {
false,
false,
false,
false};
144 std::string path_[
kScopes] = {
"",
"",
"",
"tracemaker-route.toml"};
Model(std::string command, std::vector< Field > fields, Check check={})
void set_status(std::string s)
Action press(int k)
One key.
const std::string & save_path() const
The file of the target scope.
void disable_scope(Scope s)
std::vector< std::string > args() const
the chosen arguments: positionals first, then options in list order
std::string command_line() const
the command with those arguments, quoted for a shell
std::function< std::string(const std::vector< std::string > &)> Check
Says what is wrong with a list of arguments (the command line's own parser); empty if nothing is.
const std::string & status() const
Scope target() const
The scope that edits go to and that s saves; Tab moves it.
const std::vector< Field > & fields() const
const std::string & error() const
bool dirty(Scope s) const
void mark_saved()
Records that the target scope's file was written.
std::string config_text(Scope s) const
The options file of a scope: one name = value per line, as route --config reads it.
std::vector< Line > render(int rows, int cols) const
The screen as rows lines of at most cols characters.
std::vector< std::string > load_config(const std::string &text, Scope s=Scope::file)
Takes the values of such a file into a scope; returns one message per line it could not use.
void set_save_path(std::string p)
bool set(const std::string &name, const std::string &value)
Sets a field by its label or its argument spelling (e.g. "board", "--output"); false if there is none...
std::string config_text() const
void enable_scope(Scope s, std::string path, bool exists)
Makes a scope available as a place to keep options: path is its file, exists whether that file is the...
std::size_t display_width(const std::string &s)
Columns the text takes (UTF-8 characters count one each, which is right for the box-drawing character...
Action run_keys(Model &m, const std::string &keys)
The same for a scripted key sequence (tests): characters stand for themselves, and <up> <down> <pgup>...
Action run_terminal(Model &m)
Runs the model on the controlling terminal (/dev/tty, so standard output stays free for print) until ...
void save_options(Model &m)
Writes the target scope's options to its file (creating the folder) and reports the outcome in the st...
std::vector< Entry > parse_options(const std::string &text)
Style
How a piece of text is painted.
int truth(const std::string &value)
A flag's value in an options file: 1 for true/on/yes/1, 0 for false/off/no/0, -1 for anything else.
const char * scope_name(Scope s)
"this run", "global", "project", "file"
Scope
Where a value comes from, lowest precedence first.
One line of an options file: name = value.
One command-line option as the screen shows it.
bool save
false for what belongs to one run (board, output): not written to an options file
bool hidden
experimental and test options, shown on request
std::vector< std::string > spellings
a flag's spellings ("--pair-twists", "--no-pair-twists"); empty for a value option
Scope scope
the scope value comes from (meaningless while value is empty)
std::string def
the default as text; empty if not known
std::string arg
spelling written before the value; empty for a positional argument
std::string value
what is in effect: value option: its text; flag: the chosen spelling; empty: the default
std::string layer[kScopes]
the same, per scope; value is the highest scope's that is not empty
std::string key
options-file key of a value option: its long name without the dashes
std::string label
as shown: "--via-cost-mm", "-o, --output", "board"
One screen line: text is the plain text (what a test or a monochrome terminal sees),...
std::vector< Span > spans