Visualize different Unicode encodings in the terminal
Ruby library and CLI command that visualizes various Unicode and ASCII/single byte encodings in the terminal:
Each byte of the given string is highlighted using the following mechanism (characters -> codepoints):
The same colors are used in the higher-level companion tool uniscribe.
Make sure you have Ruby installed and installing gems works properly. Then do:
$ gem install unibits
Pass the string to debug to unibits:
$ unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
require 'unibits/kernel_method'
unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
unibits
takes some optional options:
true
), you can deactivate on the CLI with --no-stats
CLI: $ unibits -e utf-8 -c utf-8 "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'utf-8', convert: 'utf-8'
CLI: $ unibits -e utf-8 -c utf-16le "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'utf-8', convert: 'utf-16le'
CLI: $ unibits -e utf-8 -c utf-32be "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'utf-8', convert: 'utf-32be'
CLI: $ unibits -e binary "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'binary'
CLI: $ unibits -e utf-8 -c ascii "ascii"
Ruby: unibits "ascii", encoding: 'utf-8', convert: 'ascii'
Example in Ruby: unibits "unexpected \x80 | not enough \xF0\x9F\x8C | overlong \xE0\x81\x81 | surrogate \xED\xA0\x80 | too large \xF5\x8F\xBF\xBF"
Example in Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'ascii'
More info
Related gems
Lots of thanks to @damienklinnert for the motivation and inspiration required to build this! 馃巻
Copyright (C) 2017-2023 Jan Lelis https://janlelis.com. Released under the MIT license.