@@ -22,7 +22,9 @@ Config::Config(int argc, char *argv[])
2222 bool show_help{}, show_version{};
2323 auto cli_head = (
2424 clipp::option (" -h" , " --help" ).set (show_help).doc (" This help" ),
25- clipp::option (" -V" , " --version" ).set (show_version).doc (" Version" ),
25+ clipp::option (" -V" , " --version" ).set (show_version).doc (" Version" )
26+ );
27+ auto cli_mod = " Run modifiers:" % (
2628 clipp::option (" -v" , " --verbose" ).call ([]{
2729 spdlog::set_level (spdlog::level::debug);
2830 }).doc (" Enable verbose output" ),
@@ -35,9 +37,9 @@ Config::Config(int argc, char *argv[])
3537 .doc (" Display interval in seconds" )
3638 );
3739
38- auto cli_output = " Output:" % (
39- clipp::option (" -A" , " --ascii" ).set (m_output_type,ASCII).doc (" ASCII output" ) |
40- clipp::option (" -U" , " --unicode" ).set (m_output_type,UNICODE).doc (" Unicode output" ) |
40+ auto cli_output = " Output:" % one_of (
41+ clipp::option (" -A" , " --ascii" ).set (m_output_type,ASCII).doc (" ASCII output" ),
42+ clipp::option (" -U" , " --unicode" ).set (m_output_type,UNICODE).doc (" Unicode output" ),
4143 clipp::option (" -B" , " --braille" ).set (m_output_type,BRAILLE).doc (" Braille output" )
4244 );
4345
@@ -53,6 +55,7 @@ Config::Config(int argc, char *argv[])
5355
5456 auto cli = (
5557 cli_head | (
58+ cli_mod,
5659 cli_output,
5760 clipp::repeatable (
5861 /* select a plot type */
@@ -98,8 +101,10 @@ Config::Config(int argc, char *argv[])
98101 .doc (" Find numbers in input line, pick 1 or 2 positions for X and Y values" ),
99102 (clipp::option (" -r" , " --regex" ) & clipp::value (" regex" )
100103 .call ([&](const char *txt) { m_inputs.back ().set_regex (txt); }))
101- .doc (" Regex to match numbers from input line" )
102-
104+ .doc (" Regex to match numbers from input line" ),
105+ (clipp::option (" -l" , " --limit" ) & clipp::value (" count" )
106+ .call ([&](const char *txt) { m_inputs.back ().set_data_limit (txt); }))
107+ .doc (" How many historical values to retain for plotting" )
103108 ),
104109
105110 " Plot modifiers:" % (
@@ -169,6 +174,7 @@ Config::Config(int argc, char *argv[])
169174
170175 bool with_interval{}, no_interval{};
171176 double prev_interval = 1 ;
177+ size_t prev_data_limit = Input::g_default_data_limit;
172178 for (auto &input : m_inputs) {
173179 if (input.needs_interval ()) {
174180 if (!input.interval ()) {
@@ -177,6 +183,11 @@ Config::Config(int argc, char *argv[])
177183 prev_interval = input.interval ();
178184 }
179185 }
186+ if (!input.data_limit ()) {
187+ input.set_data_limit (prev_data_limit);
188+ } else {
189+ prev_data_limit = input.data_limit ();
190+ }
180191 if (!input) {
181192 spdlog::error (" incomplete plot definition" );
182193 std::exit (1 );
@@ -316,6 +327,19 @@ void Input::set_interval (const std::string &txt)
316327 std::exit (1 );
317328 }
318329}
330+ void Input::set_data_limit (size_t value)
331+ {
332+ m_data_limit = value;
333+ }
334+ void Input::set_data_limit (const std::string &txt)
335+ {
336+ auto [_,ec] = std::from_chars (txt.data (), txt.data ()+txt.size (), m_data_limit);
337+ if (ec != std::errc{}) {
338+ spdlog::error (" failed to parse data limit from '{}': {}" ,
339+ txt, std::make_error_code (ec).message ());
340+ std::exit (1 );
341+ }
342+ }
319343
320344Input::operator bool () const
321345{
0 commit comments