diff --git a/lib/src/utils/parsers/git_clone_update_printer.dart b/lib/src/utils/parsers/git_clone_update_printer.dart index f4e884ff..7940bbe2 100644 --- a/lib/src/utils/parsers/git_clone_update_printer.dart +++ b/lib/src/utils/parsers/git_clone_update_printer.dart @@ -20,30 +20,42 @@ String lastMatchedEntry = ''; final maxLabelLength = regexes.keys.map((e) => e.length).reduce((a, b) => a > b ? a : b); +var _hasFailedPrint = false; + void updateProgress(String line) { - final matchedEntry = regexes.entries.firstWhereOrNull( - (entry) => line.contains(entry.key), - ); - - if (matchedEntry != null) { - final label = matchedEntry.key.padRight(maxLabelLength); - final match = matchedEntry.value.firstMatch(line); - final percentVaue = match?.group(1); - int? percentage = int.tryParse(percentVaue ?? ''); - - if (percentage != lastPercentage) { - if (percentage == null) return; - - if (lastMatchedEntry.isNotEmpty && lastMatchedEntry != label) { - printProgressBar(lastMatchedEntry, 100); - logger.write('\n'); - } + if (_hasFailedPrint) { + logger.info('\n'); + + return; + } + try { + final matchedEntry = regexes.entries.firstWhereOrNull( + (entry) => line.contains(entry.key), + ); - printProgressBar(label, percentage); + if (matchedEntry != null) { + final label = matchedEntry.key.padRight(maxLabelLength); + final match = matchedEntry.value.firstMatch(line); + final percentVaue = match?.group(1); + int? percentage = int.tryParse(percentVaue ?? ''); - lastPercentage = percentage; - lastMatchedEntry = label; + if (percentage != lastPercentage) { + if (percentage == null) return; + + if (lastMatchedEntry.isNotEmpty && lastMatchedEntry != label) { + printProgressBar(lastMatchedEntry, 100); + logger.write('\n'); + } + + printProgressBar(label, percentage); + + lastPercentage = percentage; + lastMatchedEntry = label; + } } + } catch (e) { + logger.detail('Failed to update progress bar $e'); + _hasFailedPrint = true; } } @@ -60,7 +72,7 @@ void printProgressBar(String label, int percentage) { // Create a custom Process.start, that prints using the progress bar Future runGitCloneUpdate(List args) async { - final process = await Process.start('git', args); + final process = await Process.start('git', args, runInShell: true); // ignore: avoid-unassigned-stream-subscriptions process.stderr.transform(utf8.decoder).listen((line) {