I3 locks battery script using awesome font doesn't work with some unicode

I am using font-awesome 4.4.0 and have expanded the default i3blocks battery script with new battery icons. Everything seems to work correctly, but fa-battery-half Unicode: f242 , which makes the script useless. Unicode also seems to refer to the symbol .

In the terminal, it crashes:

 $ 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 

script by default, with the exception of the following 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 this:

enter image description here

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

+6
source share
1 answer

You have two problems.


Your first problem is a mistake that leads to warnings of a "broad nature" and possibly other problems. To solve this error, encode your output correctly. In particular, add the following to the script:

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

It says Perl

  • 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.

Warnings indicate that Perl was able to notice your error and tried to fix it by encoding the output using UTF-8. This is a correct fix, so the output of your program will not change, which will lead us to the second problem.


The second problem is that your terminal font does not have a glyph for U + F242. If you want to display this character, you will need to use a different font.

+5
source

All Articles