i3blocks电池脚本,使用字体awesome不能与某些unicodes一起使用 [英] i3blocks battery script, using font awesome doesn't work with some unicodes

查看:816
本文介绍了i3blocks电池脚本,使用字体awesome不能与某些unicodes一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用font-awesome 4.4.0并使用新的电池图标扩展了默认的i3blocks电池脚本。
所有似乎都正常工作,但 fa-battery-half Unicode:f242 ,这使得脚本无效。 unicode似乎也引用了字符

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 .

在终端中它崩溃了:

$ 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 .= '  ';
}

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:

我怎样才能让脚本工作, fa-battery-half Unicode:f242 icon。

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

推荐答案

你有两个问题。

你的第一个问题是导致广泛字符警告和其他问题的错误。要解决该错误,请对输出进行正确编码。具体来说,将以下内容添加到您的脚本中:

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)';

这告诉Perl


  • 使用UTF-8编码发送到STDOUT的文本。

  • 使用UTF-8编码发送到STDERR的文本。

  • 解码文本读取来自STDIN使用UTF-8。

  • 使用UTF-8作为文件的默认编码。

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

警告表明Perl能够注意到你的bug,并试图通过使用UTF-8编码输出来修复它。这是正确的修复,所以你的程序输出不会改变,这就把我们带到了第二个问题。

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.

你的第二个问题问题是你的终端的字体没有U + F242的字形。如果您希望显示该字符,则需要使用其他字体。

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.

这篇关于i3blocks电池脚本,使用字体awesome不能与某些unicodes一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆