• Ubuntu12.04 安装ibusfbterm0.9.1


    Ubuntu12.04 安装ibus-fbterm-0.9.1
    有没有朋友想在真正的终端(console)下显示并输入中文,我想肯定是有的,比如我自己就研究过好一阵,结果还初见成效,这里分享一点自己的小经验。
    目前可行的方案有:
    fbterm+ucimf            (简略粗糙)
    fbterm+ibus-fbterm (通用)
    fbterm+fcitx-fbterm   (最优方案)
    fbterm+yong

    这里就介绍最通用的一种,屡试不爽噢!

    直接用ubuntu12.04的官方源安装基本组件

    sudo  apt-get  install  fbterm  ibus ibus-table-wubi ibus-pinyin ibus-1.0 im-switch(im-config)  (galternatives)   #括号内的包是可能会用到

    ibus-fbterm
    wget    http://ibus-fbterm.googlecode.com/files/ibus-fbterm-0.9.1.tar.gz

    tar   -zxvf   ibus-fbterm-0.9.1.tar.gz   -C   /usr/local/src
    ./configure 
    make  &&  make install

    64bit系统会出现一个bug,

    display.c: 在函数‘calculate_status_win’中:
    display.c:215:23: 错误: ‘IBusProperty’没有名为‘label’的成员
    display.c: 在函数‘draw_status_bar’中:
    display.c:241:43: 错误: ‘IBusProperty’没有名为‘label’的成员
    display.c:241:69: 错误: ‘IBusProperty’没有名为‘label’的成员
    display.c:242:8: 错误: ‘IBusProperty’没有名为‘label’的成员
    make[1]: *** [ibus_fbterm-ibus-fbterm.o] 错误 1
    make[1]:正在离开目录 `/usr/local/src/ibus-fbterm-0.9.1/src'


    ###############################################
    解决方法,/src/display.c
    ###############################################

    https://aur.archlinux.org/packages.php?ID=36078    #archlinux
    http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-i18n/ibus-fbterm/files/ibus-fbterm-0.9.1-ibus-1.4.1.patch?view=diff&r1=text&tr1=1.1&r2=text&tr2=1.1&diff_format=s     #gentoo linux
    上有高人朋友已经给出了解决办法。



    Thannks for your reporting. I found out it is becase ibus upgrade its API, according to https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=771115. I already infomation the author to ask him to make a upgrade. And I do my little try, you may want to test it if you are really in harry. But I am not very sure whether I make it right.

    ************************************
    Here is diff of display.c:
    215,216c215
    <
    < w += text_width(ibus_property_get_label(prop)->text);
    ---
    > w += text_width(prop->label->text);
    242,244c241,242
    < draw_text(x, y, COLOR_FG, COLOR_BG, ibus_property_get_label(prop)->text,
    < strlen(ibus_property_get_label(prop)->text));
    < x += FW(text_width(ibus_property_get_label(prop)->text));
    ---
    > draw_text(x, y, COLOR_FG, COLOR_BG, prop->label->text, strlen(prop->label->text));
    > x += FW(text_width(prop->label->text));
    ************************************

    就是display.c文件中要改几个地方,改完后再编译就可顺利通过,以下是替换后的display.c
    ----------------------------------------
    enum { AuxiliaryTextWin = 0, LookupTableWin, StatusBarWin };

    static unsigned short cursor_x, cursor_y;
    static Rectangle auxiliary_text_win, lookup_table_win, status_bar_win;

    static const Info info;

    #define FW(x) ((x) * info.fontWidth)
    #define FH(y) ((y) * info.fontHeight)
    #define SW (info.screenWidth)
    #define SH (info.screenHeight)

    #define MARGIN 5
    #define GAP 5
    #define WIN_HEIGHT (FH(1) + 2 * MARGIN)
    #define WIN_INTERVAL (WIN_HEIGHT + GAP)

    #define COLOR_BG Gray
    #define COLOR_FG Black
    #define COLOR_ACTIVE_CANDIDATE DarkBlue

    struct interval {
        unsigned first;
        unsigned last;
    };

    static char bisearch(unsigned ucs, const struct interval *table, unsigned max)
    {
        unsigned min = 0;
        unsigned mid;

        if (ucs < table[0].first || ucs > table[max].last)
            return 0;
        while (max >= min) {
            mid = (min + max) / 2;
            if (ucs > table[mid].last)
                min = mid + 1;
            else if (ucs < table[mid].first)
                max = mid - 1;
            else
                return 1;
        }
        return 0;
    }

    static char is_double_width(unsigned ucs)
    {
        static const struct interval double_width[] = {
            { 0x1100, 0x115F}, { 0x2329, 0x232A}, { 0x2E80, 0x303E},
            { 0x3040, 0xA4CF}, { 0xAC00, 0xD7A3}, { 0xF900, 0xFAFF},
            { 0xFE10, 0xFE19}, { 0xFE30, 0xFE6F}, { 0xFF00, 0xFF60},
            { 0xFFE0, 0xFFE6}, { 0x20000, 0x2FFFD}, { 0x30000, 0x3FFFD}
        };
        return bisearch(ucs, double_width, sizeof(double_width) / sizeof(struct interval) - 1);
    }

    static inline unsigned short get_cursor_y()
    {
        if (SH <= 3 * WIN_INTERVAL) return 0;

        unsigned short max_cursor_y = SH - 3 * WIN_INTERVAL;

        if (cursor_y < max_cursor_y) return cursor_y;
        if (cursor_y >= 4 * WIN_INTERVAL) return cursor_y - 4 * WIN_INTERVAL;
        return max_cursor_y;
    }

    static void utf8_to_utf16(unsigned char *utf8, unsigned short *utf16)
    {
        unsigned index = 0;
        for (; *utf8;) {
            if ((*utf8 & 0x80) == 0) {
                utf16[index++] = *utf8;
                utf8++;
            } else if ((*utf8 & 0xe0) == 0xc0) {
                utf16[index++] = ((*utf8 & 0x1f) << 6) | (utf8[1] & 0x3f);
                utf8 += 2;
            } else if ((*utf8 & 0xf0) == 0xe0) {
                utf16[index++] = ((*utf8 & 0xf) << 12) | ((utf8[1] & 0x3f) << 6) | (utf8[2] & 0x3f);
                utf8 += 3;
            } else utf8++;
        }

        utf16[index] = 0;
    }

    static unsigned text_width(char *utf8)
    {
        unsigned short utf16[strlen(utf8) + 1];
        utf8_to_utf16(utf8, utf16);

        unsigned i, w = 0;
        for (i = 0; utf16[i]; i++, w++) {
            if (is_double_width(utf16[i])) w++;
        }

        return w;
    }

    static void draw_margin(Rectangle rect, char color)
    {
        Rectangle r1 = { rect.x, rect.y, rect.w, MARGIN };
        fill_rect(r1, color);

        r1.y = rect.y + rect.h - MARGIN;
        fill_rect(r1, color);

        Rectangle r2 = { rect.x, rect.y + MARGIN, MARGIN, rect.h - 2 * MARGIN };
        fill_rect(r2, color);

        r2.x = rect.x + rect.w - MARGIN;
        fill_rect(r2, color);
    }

    static void calculate_lookup_win()
    {
        if (!lookup_table) {
            lookup_table_win.w = 0;
            return;
        }

        unsigned i, w = 0;
        for (i = 0; ; i++) {
            IBusText *text = ibus_lookup_table_get_candidate(lookup_table, i);
            if (!text) break;

            w += text_width(text->text);
        }

        lookup_table_win.x = cursor_x;
        lookup_table_win.y = get_cursor_y() + WIN_INTERVAL + GAP;
        lookup_table_win.w = FW(w + 3 * lookup_table->page_size) + 2 * MARGIN;
        lookup_table_win.h = WIN_HEIGHT;

        if (lookup_table_win.x + lookup_table_win.w > SW) {
            if (lookup_table_win.w > SW) lookup_table_win.x = 0;
            else lookup_table_win.x = SW - lookup_table_win.w;
        }
    }

    static void draw_lookup_table()
    {
        set_im_window(LookupTableWin, lookup_table_win);
        if (!lookup_table_win.w) return;

        draw_margin(lookup_table_win, COLOR_BG);

        unsigned i, x = lookup_table_win.x + MARGIN, y = lookup_table_win.y + MARGIN;
        for (i = 0; ; i++) {
            IBusText *text = ibus_lookup_table_get_candidate(lookup_table, i);
            if (!text) break;

            char buf[8];
            snprintf(buf, sizeof(buf), "%d.", i + 1);
            draw_text(x, y, COLOR_FG, COLOR_BG, buf, strlen(buf));
            x += FW(2);

            draw_text(x, y, i == lookup_table->cursor_pos ? COLOR_ACTIVE_CANDIDATE : COLOR_FG, COLOR_BG, text->text, strlen(text->text));
            x += FW(text_width(text->text));

            char space = ' ';
            draw_text(x, y, COLOR_FG, COLOR_BG, &space, 1);
            x += FW(1);
        }

        unsigned endx = lookup_table_win.x + lookup_table_win.w - MARGIN;
        if (x < endx) {
            Rectangle rect = { x, y, endx - x, FH(1) };
            fill_rect(rect, COLOR_BG);
        }
    }


    static void calculate_auxiliary_win()
    {
        if (!auxiliary_text) {
            auxiliary_text_win.w = 0;
            return;
        }

        auxiliary_text_win.x = cursor_x;
        auxiliary_text_win.y = get_cursor_y() + GAP;
        auxiliary_text_win.w = FW(text_width(auxiliary_text->text)) + 2 * MARGIN;
        auxiliary_text_win.h = WIN_HEIGHT;

        if (auxiliary_text_win.x + auxiliary_text_win.w > SW) {
            if (auxiliary_text_win.w > SW) auxiliary_text_win.x = 0;
            else auxiliary_text_win.x = SW - auxiliary_text_win.w;
        }
    }

    static void draw_auxiliary_text()
    {
        set_im_window(AuxiliaryTextWin, auxiliary_text_win);
        if (!auxiliary_text_win.w) return;

        draw_margin(auxiliary_text_win, COLOR_BG);

        unsigned x = auxiliary_text_win.x + MARGIN, y = auxiliary_text_win.y + MARGIN;
        draw_text(x, y, COLOR_FG, COLOR_BG, auxiliary_text->text, strlen(auxiliary_text->text));
    }

    static void calculate_status_win()
    {
        if (!property_list) {
            status_bar_win.w = 0;
            return;
        }

        unsigned i, w = 0;
        for (i = 0; ; i++) {
            IBusProperty *prop = ibus_prop_list_get(property_list, i);
            if (!prop) break;

            w += text_width(ibus_property_get_label(prop)->text);
        }

        status_bar_win.x = cursor_x;
        status_bar_win.y = get_cursor_y() + 2 * WIN_INTERVAL + GAP;
        status_bar_win.w = FW(w + property_list->properties->len) + 2 * MARGIN;
        status_bar_win.h = WIN_HEIGHT;

        if (status_bar_win.x + status_bar_win.w > SW) {
            if (status_bar_win.w > SW) status_bar_win.x = 0;
            else status_bar_win.x = SW - status_bar_win.w;
        }
    }

    static void draw_status_bar()
    {
        set_im_window(StatusBarWin, status_bar_win);
        if (!status_bar_win.w) return;

        draw_margin(status_bar_win, COLOR_BG);

        unsigned i, x = status_bar_win.x + MARGIN, y = status_bar_win.y + MARGIN;
        for (i = 0; ; i++) {
            IBusProperty *prop = ibus_prop_list_get(property_list, i);
            if (!prop) break;

            draw_text(x, y, COLOR_FG, COLOR_BG, ibus_property_get_label(prop)->text, strlen(ibus_property_get_label(prop)->text));
            x += FW(text_width(ibus_property_get_label(prop)->text));

            char space = ' ';
            draw_text(x, y, COLOR_FG, COLOR_BG, &space, 1);
            x += FW(1);
        }
    }
    -----------------------------------------

    好的,在console下要开启fbterm和ibus-fbterm
    Ctl+Alt+fx(x=1,2,3,4,5,6,7),如:Ctl+Alt+f2

    输入用户名,密码后,键入以下命令
    fbterm  -i   ibus-fbterm





    由于fbterm使用的默认字体mono表现比较差,所以我为Linux安装了微软雅黑用于中文显示,Consolas用于英文显示(也可以使用Moncao,二者表现都不错,但是个人认为Consolas表现柔和,很适合作为编程字体).
    (1). 安装微软雅黑:
    a. 从Windows 7或XP中复制msyh.ttf和msyhbd.ttf到Linux字体目录
    "/usr/share/fonts/truetype/msttcorefonts"中,并将两个文件权限修改为777,也可以修改为644,再创建两个软连接,如:
    ln -s msyh.ttf Msyh.ttf
    ln -s msyhbd.ttf Msyhbd.ttf
    b. 接着使用如下命令注册字体:
    mkfontscale
    mkfontdir
    fc-cache  -fv


    (2). Consolas也是Windows下的字体,其安装过程与微软雅黑一样,只是
    该字体需到网上下载,下载地址如下(这是雅黑和Consolas的结合体,字体名称为"YaHei Consolas Hybrid"):
    http://files.xiaogui.org/eclipse-indigo/YaHei.Consolas.1.12.rar


    (3). Monaco本来为Mac系统上的字体,不过现在已经有Linux下的版本了,
    故只需下载并将其放到字体目录即可,也没了上面的麻烦了.
    下载地址:http://www.gringod.com/wp-upload/software/Fonts/Monaco_Linux.ttf


    5. 修改fbterm的默认字体,编辑其配置文件"~/.fbtermrc",修改font-names的
    值为"Consolas,Monaco,微软雅黑",并将字体font-size调大至15,这就看个人爱好了.


    fbterm的更多自定义设置可以在~/.fbtemrc中指定,配置文件的意思一看便懂,这里就不絮叨了。
    以下是我个人的一个样例:
    # Configuration for FbTerm

    # Lines starting with '#' are ignored.
    # Note that end-of-line comments are NOT supported, comments must be on a line of their own.


    # font family names/pixelsize used by fbterm, multiple font family names must be seperated by ','
    # and using a fixed width font as the first is strongly recommended
    font-names=mono
    font-size=15

    # force font width (and/or height), usually for non-fixed width fonts
    # legal value format: n (fw_new = n), +n (fw_new = fw_old + n), -n (fw_new = fw_old - n)
    #font-width=
    #font-height=

    # default color of foreground/background text
    # available colors: 0 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 = cyan, 7 = white
    color-foreground=7
    color-background=0

    # max scroll-back history lines of every window, value must be [0 - 65535], 0 means disable it
    history-lines=100

    # up to 5 additional text encodings, multiple encodings must be seperated by ','
    # run 'iconv --list' to get available encodings.
    text-encodings=zh_CN.UTF-8,en_US.UTF-8,GB2312,GB18030,GBK

    # cursor shape: 0 = underline, 1 = block
    # cursor flash interval in milliseconds, 0 means disable flashing
    cursor-shape=0
    cursor-interval=500

    # additional ascii chars considered as part of a word while auto-selecting text, except ' ', 0-9, a-z, A-Z
    word-chars=._-

    # change the clockwise orientation angle of screen display
    # available values: 0 = 0 degree, 1 = 90 degrees, 2 = 180 degrees, 3 = 270 degrees
    screen-rotate=0

    # specify the favorite input method program to run
    input-method=/usr/local/bin/-fbterm

    # treat ambiguous width characters as wide
    ambiguous-wide=yes
  • 相关阅读:
    ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket
    plainless script for es
    canal 代码阅读
    elasticsearch 之编译过程
    nfs 共享目录
    canal mysql slave
    yum 运行失败
    linux 几种服务类型
    2019-04-16 SpringMVC 学习笔记
    2019-04-10 集成JasperReport
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814695.html
Copyright © 2020-2023  润新知