termunicode 0.2.0
termunicode: ^0.2.0 copied to clipboard
Unicode library to get character properties (width, emoji, printable, etc)
example/termunicode_example.dart
import 'dart:io';
import 'package:termunicode/termunicode.dart';
void main() async {
final withEsc = 'Hola \x1bmundo\x1b'.runes
.fold(
StringBuffer(),
(sb, rune) => isNonPrintableCp(rune) ? (sb..write('')) : (sb..write(String.fromCharCode(rune))),
)
.toString();
final strs = [
'你好 世界',
'hello',
'hello 🌎',
'hello 👋🏻',
'hello 👩🔬',
withEsc,
'コンニチハ',
'🇦🇷🇰🇷🇿🇲',
];
stdout.writeln(' 123456789012345 ');
for (final str in strs) {
stdout.writeln('|${centerString(str, 15)}| => len: ${widthString(str)}');
}
stdout.writeln('\nversion: ${unicodeVersion()}');
}
String centerString(String str, int width) {
final strWidth = widthString(str);
final pad = (width - strWidth) ~/ 2;
return ' ' * pad + str + ' ' * (width - strWidth - pad);
}