Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i3blocks battery script, using font awesome doesn't work with some unicodes

I use font-awesome 4.4.0 and have extended the default i3blocks battery script with the new battery icons. All seem to work correctly but the fa-battery-half Unicode: f242, which renders the script useless. The unicode also seems to refer to the character .

In the terminal it crashes with:

$ perl /usr/share/i3blocks/battery
Wide character in print at /usr/share/i3blocks/battery line 65.
28%  (01:02)
Wide character in print at /usr/share/i3blocks/battery line 66.
28%  
#000000

The script is default, except of the following few lines:

if ($status eq 'Discharging') {

if ($percent < 10) {
    $full_text .= '  ';
} elsif ($percent < 25) {
    $full_text .= '  ';
} elsif ($percent < 50) {
    $full_text .= '  ';
} elsif ($percent < 75) {
    $full_text .= '  ';
} elsif ($percent < 100) {
    $full_text .= '  ';
}

} elsif ($status eq 'Charging') {
    $full_text .= '  ';
}

and

if ($status eq 'Discharging') {

if ($percent < 25) {
    print "#FF003C\n";
} else {
    print "#000000\n";
}

if ($percent < 5) {
    exit(33);
}
}

In the editor the script looks like:

enter image description here

How may I get the script to work, with the fa-battery-half Unicode: f242 icon.

like image 253
apoc Avatar asked Aug 24 '15 11:08

apoc


1 Answers

You have two problems.


Your first problem is a bug that's resulting in the "wide character" warnings and possibly other problems. To solve the error, properly encode your output. Specifically, add the following to your script:

use open ':std', ':encoding(UTF-8)';

This tells Perl to

  • Encode text sent to STDOUT using UTF-8.
  • Encode text sent to STDERR using UTF-8.
  • Decode text read from STDIN using UTF-8.
  • Use UTF-8 as the default encoding for files.

The warnings indicate that Perl was able to notice your bug, and that it attempted to fix it by encoding the output using UTF-8. That's the correct fix, so your program's output won't change, which brings us to the second problem.


Your second problem is that your terminal's font doesn't have a glyph for U+F242. If you wish to display that character, you'll need to use a different font.

like image 84
ikegami Avatar answered Sep 28 '22 08:09

ikegami