From 19e4f5ec73865c33788a9e7432a6b12e4c6bcfd7 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 12 Apr 2021 15:51:28 +0300 Subject: [PATCH] tools: implement progres bar for `v check-md .` --- cmd/tools/vcheck-md.v | 17 +++++++++++++++++ cmd/v/help/check-md.txt | 1 + 2 files changed, 18 insertions(+) diff --git a/cmd/tools/vcheck-md.v b/cmd/tools/vcheck-md.v index 94fb5119f0..83ff77e0fe 100644 --- a/cmd/tools/vcheck-md.v +++ b/cmd/tools/vcheck-md.v @@ -14,6 +14,7 @@ const ( too_long_line_length = 100 term_colors = term.can_show_color_on_stderr() hide_warnings = '-hide-warnings' in os.args || '-w' in os.args + show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args non_option_args = cmdline.only_non_options(os.args[2..]) ) @@ -41,6 +42,10 @@ fn main() { println('´-all´ flag is deprecated. Please use ´v check-md .´ instead.') exit(1) } + if show_progress { + // this is intended to be replaced by the progress lines + println('') + } mut files_paths := non_option_args.clone() mut res := CheckResult{} if term_colors { @@ -64,6 +69,9 @@ fn main() { } res += mdfile.check() } + if res.errors == 0 && show_progress { + term.clear_previous_line() + } if res.warnings > 0 || res.errors > 0 || res.oks > 0 { println('\nWarnings: $res.warnings | Errors: $res.errors | OKs: $res.oks') } @@ -145,9 +153,17 @@ mut: state MDFileParserState = .markdown } +fn (mut f MDFile) progress(message string) { + if show_progress { + term.clear_previous_line() + println('File: ${f.path:-30s}, Lines: ${f.lines.len:5}, $message') + } +} + fn (mut f MDFile) check() CheckResult { mut res := CheckResult{} for j, line in f.lines { + // f.progress('line: $j') if line.len > too_long_line_length { if f.state == .vexample { wprintln(wline(f.path, j, line.len, 'long V example line')) @@ -265,6 +281,7 @@ fn (mut f MDFile) check_examples() CheckResult { mut acommands := e.command.split(' ') nofmt := 'nofmt' in acommands for command in acommands { + f.progress('example from $e.sline to $e.eline, command: $command') fmt_res := if nofmt { 0 } else { get_fmt_exit_code(vfile, vexe) } match command { 'compile' { diff --git a/cmd/v/help/check-md.txt b/cmd/v/help/check-md.txt index 1b0dc7f9bb..145ffeeecb 100644 --- a/cmd/v/help/check-md.txt +++ b/cmd/v/help/check-md.txt @@ -7,6 +7,7 @@ Usage: Note: You can also combine files and directories. Flags: + -silent Do not show a progress bar. -w, -hide-warnings Do not print warnings, only errors. NB: There are several special keywords, which you can put after the code fences for v.