Skip to content

Commit

Permalink
Add class for ascii codes
Browse files Browse the repository at this point in the history
  • Loading branch information
pdenert committed Nov 6, 2024
1 parent baba0ad commit 41205c0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/patrol/lib/src/native/native_automator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion packages/patrol/lib/src/native/native_automator2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
20 changes: 10 additions & 10 deletions packages/patrol_finders/lib/src/custom_finders/patrol_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -440,7 +440,7 @@ class PatrolTester {
return wrapWithPatrolLog<PatrolFinder>(
action: 'waitUntilExists',
finder: finder,
color: '36m',
color: AnsiCodes.cyan,
enablePatrolLog: enablePatrolLog,
function: () => TestAsyncUtils.guard(() async {
final duration = timeout ?? config.existsTimeout;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -549,7 +549,7 @@ class PatrolTester {
return wrapWithPatrolLog<PatrolFinder>(
action: 'dragUntilExists',
finder: view,
color: '34m',
color: AnsiCodes.blue,
enablePatrolLog: enablePatrolLog,
function: () => TestAsyncUtils.guard(() async {
var viewPatrolFinder = PatrolFinder(finder: view, tester: this);
Expand Down Expand Up @@ -629,7 +629,7 @@ class PatrolTester {
return wrapWithPatrolLog<PatrolFinder>(
action: 'dragUntilVisible',
finder: view,
color: '34m',
color: AnsiCodes.blue,
enablePatrolLog: enablePatrolLog,
function: () => TestAsyncUtils.guard(() async {
var viewPatrolFinder = PatrolFinder(finder: view, tester: this);
Expand Down Expand Up @@ -687,7 +687,7 @@ class PatrolTester {
return wrapWithPatrolLog<PatrolFinder>(
action: 'scrollUntilExists',
finder: view,
color: '32m',
color: AnsiCodes.green,
enablePatrolLog: enablePatrolLog,
function: () async {
final finderView = view ?? find.byType(Scrollable);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/patrol_log/lib/patrol_log.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
21 changes: 21 additions & 0 deletions packages/patrol_log/lib/src/ansi_codes.dart
Original file line number Diff line number Diff line change
@@ -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');
}
2 changes: 1 addition & 1 deletion packages/patrol_log/lib/src/patrol_log_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/patrol_log/lib/src/test_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
Expand Down

0 comments on commit 41205c0

Please sign in to comment.