Skip to content

Commit 27c0e53

Browse files
committed
Issue #267 - Add a "progress bar" to specs using --progress switch (#268)
* Issue #267 - Add a "progress bar" to specs using --progress switch * Issue #267 - Make the output more readable using the pretty() function
1 parent dc8b451 commit 27c0e53

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ What's New:
1818
* The unthreaded mode is now the default.
1919
* While-guard to protect against endless loops in `while` statements.
2020
* Improved @version.
21-
* Tab-completion for `specs` command (Linux only).
21+
* Tab-completion for the `specs` command (Linux only).
22+
* A new `--progress` command-line switch to allow the user to monitor progress in reading records.
2223
* Bug fixes
2324

2425
10-May-2024: Version 0.9.2 is here

manpage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,10 @@ Prints out detailed step-by-step information about the evaluation of expressions
17201720
Disables
17211721
.I while-guard,
17221722
allowing specifications to enter endless loops.
1723+
.IP "--progress" 3
1724+
While
1725+
.B specs
1726+
is running, will print once a second a message to stderr telling the user how many records have already been processed.
17231727
.IP "--config or -c" 3
17241728
Changes the configuration file from the default
17251729
.I ~/.specs

specs/docs/cliswitch.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Main Thread:
7070
* `--debug-alu-comp` -- Prints out detailed information about the parsing and compiling of expressions (_only in debug build_).
7171
* `--debug-alu-run` -- Prints out detailed step-by-step information about the evaluation of expressions (_only in debug build_).
7272
* `--no-while-guard` -- Disables **while-guard**, allowing specifications to enter endless loops.
73+
* `--progress` -- While **specs**is running, will print once a second a message to stderr telling the user how many records have already been processed.
7374
* `--timezone` **name** -- convert to and from time-formatted strings using the selected timezone. Valid values are from the TZ database and look like `Africa/Dakar`, `America/Chicago`, `Asia/Calcutta`, `Australia/Sydney`, or `Europe/Berlin`. A full list of such timezones is available on [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Note that the same timezones can also be configured in the config
7475
* `--config` **filename** or `-c` **filename** -- overrides the default configuration file which is `~/.specs` on POSIX-based operating systems (Mac OS and Linux) or `%HOME%\specs.cfg` on Windows.
7576
* `--set` **name=value** or `-s` **name=value** -- sets the named string *name* to the value *value*.

specs/docs/onepage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Switches
2727
* --inCmd or -C -- get the input records from the output of a command specified following this switch.
2828
* --debug-alu-comp -- Prints out detailed information about the parsing and compiling of expressions (_only in debug build_).
2929
* --debug-alu-run -- Prints out detailed step-by-step information about the evaluation of expressions (_only in debug build_).
30+
* --no-while-guard -- Disables **while-guard**, allowing specifications to enter endless loops.
31+
* --progress -- While **specs**is running, will print once a second a message to stderr telling the user how many records have already been processed.
3032
* --help -- prints out some help information.
3133
* --info -- prints out information about this build of **specs**.
3234

specs/src/processing/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
X(bDebugAluCompile, bool, false, 0,debug-alu-comp, true) \
2121
X(bDebugAluRun, bool, false, 0,debug-alu-run, true) \
2222
X(bNoWhileGuard, bool, false, 0,no-while-guard, true) \
23+
X(bShowProgress, bool, false, 0,progress, true) \
2324
X(configurationFile, std::string, "", c,config, NEXTARG) \
2425
X(timeZone, std::string, "", 0,timezone, NEXTARG) \
2526
X(recfm, std::string, "", 0,recfm, NEXTARG) \

specs/src/specitems/specItems.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ bool itemGroup::processDo(StringBuilder& sb, ProcessingState& pState, Reader* pR
580580

581581
void itemGroup::process(StringBuilder& sb, ProcessingState& pState, Reader& rd, classifyingTimer& tmr)
582582
{
583+
static time_t progressTick = 0;
583584
PSpecString ps;
584585
unsigned int readerCounter = 1; // we only got 1.
585586

@@ -588,6 +589,13 @@ void itemGroup::process(StringBuilder& sb, ProcessingState& pState, Reader& rd,
588589
pState.setFirst();
589590
pState.incrementCycleCounter();
590591

592+
if (g_bShowProgress && (time(nullptr)!=progressTick)) {
593+
progressTick = time(nullptr);
594+
auto pv = mkValue(pState.getRecordCount());
595+
auto pvstr = AluFunc_pretty(pv, nullptr, nullptr, nullptr);
596+
std::cerr << "\n\tspecs: Read " << pvstr->getStr() << " records.\n";
597+
}
598+
591599
if (processDo(sb,pState, &rd, tmr, readerCounter)) {
592600
bool bPrintSuppressed = pState.printSuppressed(g_printonly_rule);
593601
if (bPrintSuppressed && g_keep_suppressed_record) {

0 commit comments

Comments
 (0)