07-21-2023, 09:55 PM
I created the screenshots and code below in [VS Code][1], but supposedly it also works in Android Studio now too:
[![enter image description here][2]][2]
```dart
void main() {
print('This is a normal message.');
printWarning('This is a warning.');
printError('This is an error.');
}
void printWarning(String text) {
print('\x1B[33m$text\x1B[0m');
}
void printError(String text) {
print('\x1B[31m$text\x1B[0m');
}
```
## ANSI escape code explanation
The ANSI escape code string is pretty confusing if you're not familiar with the format.
[![enter image description here][3]][3]
Here is the string to turn `Hello` red:
```
\x1B[31mHello\x1B[0m
```
And here it is again with spaces added for clarity between the parts:
```
\x1B [31m Hello \x1B [0m
```
Meaning:
- `\x1B`: ANSI escape sequence starting marker
- `[31m`: Escape sequence for red
- `[0m`: Escape sequence for reset (stop making the text red)
Here are the other colors:
```
Black: \x1B[30m
Red: \x1B[31m
Green: \x1B[32m
Yellow: \x1B[33m
Blue: \x1B[34m
Magenta: \x1B[35m
Cyan: \x1B[36m
White: \x1B[37m
Reset: \x1B[0m
```
Learn more from these links:
- [Build your own Command Line with ANSI escape codes][4]
- [ANSI escape code][5]
[1]:
[3]:
[4]:
[![enter image description here][2]][2]
```dart
void main() {
print('This is a normal message.');
printWarning('This is a warning.');
printError('This is an error.');
}
void printWarning(String text) {
print('\x1B[33m$text\x1B[0m');
}
void printError(String text) {
print('\x1B[31m$text\x1B[0m');
}
```
## ANSI escape code explanation
The ANSI escape code string is pretty confusing if you're not familiar with the format.
[![enter image description here][3]][3]
Here is the string to turn `Hello` red:
```
\x1B[31mHello\x1B[0m
```
And here it is again with spaces added for clarity between the parts:
```
\x1B [31m Hello \x1B [0m
```
Meaning:
- `\x1B`: ANSI escape sequence starting marker
- `[31m`: Escape sequence for red
- `[0m`: Escape sequence for reset (stop making the text red)
Here are the other colors:
```
Black: \x1B[30m
Red: \x1B[31m
Green: \x1B[32m
Yellow: \x1B[33m
Blue: \x1B[34m
Magenta: \x1B[35m
Cyan: \x1B[36m
White: \x1B[37m
Reset: \x1B[0m
```
Learn more from these links:
- [Build your own Command Line with ANSI escape codes][4]
- [ANSI escape code][5]
[1]:
[To see links please register here]
[2]:[3]:
[4]:
[To see links please register here]
[5]:[To see links please register here]