|
3 | 3 | #include "common/init.h" |
4 | 4 | #include "common/io/io.h" |
5 | 5 | #include "common/jsonconfig.h" |
| 6 | +#include "common/time.h" |
6 | 7 | #include "detection/version/version.h" |
7 | 8 | #include "logo/logo.h" |
8 | 9 | #include "util/stringUtils.h" |
@@ -670,6 +671,8 @@ static void parseCommand(FFdata* data, char* key, char* value) |
670 | 671 | {}, |
671 | 672 | })); |
672 | 673 | } |
| 674 | + else if(ffStrEqualsIgnCase(key, "--dynamic-interval")) |
| 675 | + instance.state.dynamicInterval = ffOptionParseUInt32(key, value); // seconds to milliseconds |
673 | 676 | else |
674 | 677 | return; |
675 | 678 |
|
@@ -768,15 +771,31 @@ static void run(FFdata* data) |
768 | 771 | if (!instance.config.display.noBuffer) fflush(stdout); |
769 | 772 | #endif |
770 | 773 |
|
771 | | - if (useJsonConfig) |
772 | | - ffPrintJsonConfig(false, instance.state.resultDoc); |
773 | | - else |
774 | | - ffPrintCommandOption(data, instance.state.resultDoc); |
| 774 | + while (true) |
| 775 | + { |
| 776 | + if (useJsonConfig) |
| 777 | + ffPrintJsonConfig(false, instance.state.resultDoc); |
| 778 | + else |
| 779 | + ffPrintCommandOption(data, instance.state.resultDoc); |
| 780 | + |
| 781 | + if (instance.state.dynamicInterval > 0) |
| 782 | + { |
| 783 | + fflush(stdout); |
| 784 | + ffTimeSleep(instance.state.dynamicInterval); |
| 785 | + fputs("\e[H", stdout); |
| 786 | + } |
| 787 | + else |
| 788 | + break; |
| 789 | + } |
775 | 790 |
|
776 | 791 | if (instance.state.resultDoc) |
777 | 792 | yyjson_mut_write_fp(stdout, instance.state.resultDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES | YYJSON_WRITE_NEWLINE_AT_END, NULL, NULL); |
778 | 793 | else |
| 794 | + { |
| 795 | + if (instance.config.logo.printRemaining) |
| 796 | + ffLogoPrintRemaining(); |
779 | 797 | ffFinish(); |
| 798 | + } |
780 | 799 | } |
781 | 800 |
|
782 | 801 | static void writeConfigFile(FFdata* data) |
@@ -835,6 +854,12 @@ int main(int argc, char** argv) |
835 | 854 | }; |
836 | 855 |
|
837 | 856 | parseArguments(&data, argc, argv, parseCommand); |
| 857 | + if(instance.state.dynamicInterval && instance.state.resultDoc) |
| 858 | + { |
| 859 | + fprintf(stderr, "Error: --dynamic-interval cannot be used with --json\n"); |
| 860 | + exit(400); |
| 861 | + } |
| 862 | + |
838 | 863 | if(!data.configLoaded && !getenv("NO_CONFIG")) |
839 | 864 | parseConfigFiles(); |
840 | 865 | parseArguments(&data, argc, argv, (void*) parseOption); |
|
0 commit comments