diff --git a/packages/patrol/lib/src/native/native_automator.dart b/packages/patrol/lib/src/native/native_automator.dart index d5ddd8b6f..f17b6e1d0 100644 --- a/packages/patrol/lib/src/native/native_automator.dart +++ b/packages/patrol/lib/src/native/native_automator.dart @@ -222,7 +222,8 @@ class NativeAutomator { bool enablePatrolLog = true, }) async { _config.logger('$name() started'); - final text = '\u001b[38;5;87m$name\u001b[0m \u001b[30m(native)\u001b[0m'; + final text = + '${AnsiCodes.lightBlue}$name${AnsiCodes.reset} ${AnsiCodes.gray}(native)${AnsiCodes.reset}'; if (enablePatrolLog) { _patrolLog.log(StepEntry(action: text, status: StepEntryStatus.start)); diff --git a/packages/patrol/lib/src/native/native_automator2.dart b/packages/patrol/lib/src/native/native_automator2.dart index bd58a6ec5..cfe9fd48f 100644 --- a/packages/patrol/lib/src/native/native_automator2.dart +++ b/packages/patrol/lib/src/native/native_automator2.dart @@ -104,7 +104,8 @@ class NativeAutomator2 { bool enablePatrolLog = true, }) async { _config.logger('$name() started'); - final text = '\u001b[38;5;87m$name\u001b[0m \u001b[30m(native)\u001b[0m'; + final text = + '${AnsiCodes.lightBlue}$name${AnsiCodes.reset} ${AnsiCodes.gray}(native)${AnsiCodes.reset}'; if (enablePatrolLog) { _patrolLog.log(StepEntry(action: text, status: StepEntryStatus.start)); diff --git a/packages/patrol_finders/lib/src/custom_finders/patrol_tester.dart b/packages/patrol_finders/lib/src/custom_finders/patrol_tester.dart index a3571880e..fa845a577 100644 --- a/packages/patrol_finders/lib/src/custom_finders/patrol_tester.dart +++ b/packages/patrol_finders/lib/src/custom_finders/patrol_tester.dart @@ -151,7 +151,7 @@ class PatrolTester { .replaceAll(' (ignoring all but first)', '') ?? ''; final valueText = value != null ? ' "$value"' : ''; - final text = '\u001b[$color$action\u001b[0m$valueText$finderText'; + final text = '$color$action${AnsiCodes.reset}$valueText$finderText'; _patrolLog.log(StepEntry(action: text, status: StepEntryStatus.start)); try { final result = await function(); @@ -290,7 +290,7 @@ class PatrolTester { return wrapWithPatrolLog( action: 'tap', finder: finder, - color: '33m', + color: AnsiCodes.yellow, enablePatrolLog: enablePatrolLog, function: () => TestAsyncUtils.guard(() async { final resolvedFinder = await waitUntilVisible( @@ -342,7 +342,7 @@ class PatrolTester { return wrapWithPatrolLog( action: 'longPress', finder: finder, - color: '33m', + color: AnsiCodes.yellow, enablePatrolLog: enablePatrolLog, function: () => TestAsyncUtils.guard(() async { final resolvedFinder = await waitUntilVisible( @@ -405,7 +405,7 @@ class PatrolTester { action: 'enterText', value: text, finder: finder, - color: '35m', + color: AnsiCodes.magenta, enablePatrolLog: enablePatrolLog, function: () => TestAsyncUtils.guard(() async { final resolvedFinder = await waitUntilVisible( @@ -440,7 +440,7 @@ class PatrolTester { return wrapWithPatrolLog( action: 'waitUntilExists', finder: finder, - color: '36m', + color: AnsiCodes.cyan, enablePatrolLog: enablePatrolLog, function: () => TestAsyncUtils.guard(() async { final duration = timeout ?? config.existsTimeout; @@ -478,7 +478,7 @@ class PatrolTester { return wrapWithPatrolLog( action: 'waitUntilVisible', finder: finder, - color: '36m', + color: AnsiCodes.cyan, enablePatrolLog: enablePatrolLog, function: () => TestAsyncUtils.guard(() async { final duration = timeout ?? config.visibleTimeout; @@ -549,7 +549,7 @@ class PatrolTester { return wrapWithPatrolLog( action: 'dragUntilExists', finder: view, - color: '34m', + color: AnsiCodes.blue, enablePatrolLog: enablePatrolLog, function: () => TestAsyncUtils.guard(() async { var viewPatrolFinder = PatrolFinder(finder: view, tester: this); @@ -629,7 +629,7 @@ class PatrolTester { return wrapWithPatrolLog( action: 'dragUntilVisible', finder: view, - color: '34m', + color: AnsiCodes.blue, enablePatrolLog: enablePatrolLog, function: () => TestAsyncUtils.guard(() async { var viewPatrolFinder = PatrolFinder(finder: view, tester: this); @@ -687,7 +687,7 @@ class PatrolTester { return wrapWithPatrolLog( action: 'scrollUntilExists', finder: view, - color: '32m', + color: AnsiCodes.green, enablePatrolLog: enablePatrolLog, function: () async { final finderView = view ?? find.byType(Scrollable); @@ -759,7 +759,7 @@ class PatrolTester { return wrapWithPatrolLog( action: 'scrollUntilVisible', finder: view, - color: '32m', + color: AnsiCodes.green, enablePatrolLog: enablePatrolLog, function: () async { final finderView = view ?? find.byType(Scrollable); diff --git a/packages/patrol_log/lib/patrol_log.dart b/packages/patrol_log/lib/patrol_log.dart index 6b028e5ea..07d127eb1 100644 --- a/packages/patrol_log/lib/patrol_log.dart +++ b/packages/patrol_log/lib/patrol_log.dart @@ -1,3 +1,4 @@ +export 'src/ansi_codes.dart'; export 'src/entry.dart'; export 'src/patrol_log_reader.dart'; export 'src/patrol_log_writer.dart'; diff --git a/packages/patrol_log/lib/src/ansi_codes.dart b/packages/patrol_log/lib/src/ansi_codes.dart new file mode 100644 index 000000000..070fcffbe --- /dev/null +++ b/packages/patrol_log/lib/src/ansi_codes.dart @@ -0,0 +1,21 @@ +class AnsiCodes { + /// This is the Unicode escape sequence for the ASCII escape character (ESC). + static const String escape = '\u001b'; + + /// `[0m` - Reset all styles. + static const String reset = '$escape[0m'; + + /// `[30m` - Set text color to gray. + static const String gray = '$escape[30m'; + + /// `[38;5;87m` - Set text color to light blue. Used for native actions. + static const String lightBlue = '$escape[38;5;87m'; + + static String custom(String color) => '$escape[${color}m'; + + static String get green => custom('32'); + static String get yellow => custom('33'); + static String get blue => custom('34'); + static String get magenta => custom('35'); + static String get cyan => custom('36'); +} diff --git a/packages/patrol_log/lib/src/patrol_log_reader.dart b/packages/patrol_log/lib/src/patrol_log_reader.dart index c897cd69b..ee1adc8f6 100644 --- a/packages/patrol_log/lib/src/patrol_log_reader.dart +++ b/packages/patrol_log/lib/src/patrol_log_reader.dart @@ -145,7 +145,7 @@ class PatrolLogReader { if (!showFlutterLogs) { _clearLines(stepsCounter + logsCounter + 1); } - log('${entry.pretty()} \u001b[30m(${executionTime}s)\u001b[0m'); + log('${entry.pretty()} ${AnsiCodes.gray}(${executionTime}s)${AnsiCodes.reset}'); stepsCounter = 0; logsCounter = 0; } else if (entry is StepEntry) { diff --git a/packages/patrol_log/lib/src/test_entry.dart b/packages/patrol_log/lib/src/test_entry.dart index a5c7de68f..1b222f408 100644 --- a/packages/patrol_log/lib/src/test_entry.dart +++ b/packages/patrol_log/lib/src/test_entry.dart @@ -30,11 +30,11 @@ class TestEntry extends Entry { if (status == TestEntryStatus.skip) { return '${status.name} $_testName'; } - return '${status.name} $_testName \u001b[30m(integration_test/$_filePath.dart)\u001b[0m'; + return '${status.name} $_testName ${AnsiCodes.gray}(integration_test/$_filePath.dart)${AnsiCodes.reset}'; } String get nameWithPath => - '$_testName \u001b[30m(integration_test/$_filePath.dart)\u001b[0m'; + '$_testName ${AnsiCodes.gray}(integration_test/$_filePath.dart)${AnsiCodes.reset}'; String get _filePath => name.split(' ').first.replaceAll('.', '/'); String get _testName => name.split(' ').skip(1).join(' ');