Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hyiso/string_width
Get the visual width of a string - the number of columns required to display it
https://github.com/hyiso/string_width
Last synced: 24 days ago
JSON representation
Get the visual width of a string - the number of columns required to display it
- Host: GitHub
- URL: https://github.com/hyiso/string_width
- Owner: hyiso
- License: apache-2.0
- Created: 2023-03-18T15:59:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-22T14:26:45.000Z (10 months ago)
- Last Synced: 2024-01-22T18:25:04.393Z (10 months ago)
- Language: Dart
- Homepage: https://pub.dev/packages/string_width
- Size: 38.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# string_width
> Get the visual width of a string - the number of columns required to display it
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
Useful to be able to measure the actual width of command-line output.
## Install
```bash
$ dart pub add string_width
```## Usage
```dart
import 'package:string_width/string_width.dart';void main() {
print(stringWidth('a'));
//=> 1print(stringWidth('古'));
//=> 2print(stringWidth('\u001B[1m古\u001B[22m'));
//=> 2
}```