GithubHelp home page GithubHelp logo

fcitx5-lua's Introduction

fcitx5-lua

Lua support for fcitx.

Jenkins Build Status

Documentation

It tries to support lua in fcitx in two ways.

  1. An addon loader for lua, which supports Type=Lua addon.
  2. The googlepinyin api, which is provided by imeapi addon. You may put your lua file under $HOME/.local/share/fcitx5/lua/imeapi/extensions to make the addon find your scripts.

fcitx5-lua's People

Contributors

aloxaf avatar berberman avatar eagleoflqj avatar felixonmars avatar hosxy avatar rocka avatar wengxt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fcitx5-lua's Issues

Bug: watchEvent(InputMethodActivated) doesn't work

The script below causes fcitx5 failing to start:

local fcitx = require("fcitx")

fcitx.watchEvent(fcitx.EventType.InputMethodActivated, "handler")

function handler()
    print("deactivated")
    return false
end
$ fcitx5
I2021-01-28 08:32:46.000851 instance.cpp:1307] Override Enabled Addons: {}
I2021-01-28 08:32:46.000957 instance.cpp:1308] Override Disabled Addons: {}
I2021-01-28 08:32:46.003857 addonmanager.cpp:177] Loaded addon imselector
I2021-01-28 08:32:46.006249 addonmanager.cpp:177] Loaded addon quickphrase
I2021-01-28 08:32:46.046296 addonmanager.cpp:177] Loaded addon xcb
I2021-01-28 08:32:46.046876 addonmanager.cpp:177] Loaded addon wayland
I2021-01-28 08:32:46.047226 addonmanager.cpp:177] Loaded addon waylandim
I2021-01-28 08:32:46.085466 addonmanager.cpp:177] Loaded addon keyboard
I2021-01-28 08:32:46.086328 addonmanager.cpp:177] Loaded addon clipboard
I2021-01-28 08:32:46.339282 addonmanager.cpp:177] Loaded addon pinyinhelper
I2021-01-28 08:32:46.340049 addonmanager.cpp:177] Loaded addon luaaddonloader
I2021-01-28 08:32:46.342045 addonmanager.cpp:177] Loaded addon dbus
I2021-01-28 08:32:46.355301 addonmanager.cpp:177] Loaded addon xim
I2021-01-28 08:32:46.367945 addonmanager.cpp:177] Loaded addon ibusfrontend
=========================
Fcitx 5.0.4 -- Get Signal No.: 11
Date: try "date -d @1611793966" if you are using GNU date ***
ProcessID: 112617
fcitx5(+0xbd9e)[0x55e35d7e1d9e]
/usr/lib/libc.so.6(+0x3d6a0)[0x7f6dd660c6a0]

Changing the event type to fcitx.EventType.InputMethodDeactivated, the handler is called on both activated and deactivated. Argument the handler receives seems to be the name of current input method:

local fcitx = require("fcitx")

fcitx.watchEvent(fcitx.EventType.InputMethodDeactivated, "handler")

function handler(arg)
    print(arg)
    return false
end
I2021-01-28 09:02:09.049486 kimpanel.cpp:121] Kimpanel new owner
keyboard-us
xmodmap:  please release the following keys within 2 seconds:
I2021-01-28 09:02:10.064545 addonmanager.cpp:177] Loaded addon fullwidth
I2021-01-28 09:02:10.065257 addonmanager.cpp:177] Loaded addon chttrans
pinyin
keyboard-us
pinyin

I investigated a little bit into the code, and I think it is caused by a mismatch in the definition of EventType between fcitx5 and base.lua.

Demo input method

I'm interested in using this, but it was a little bit difficult to find any information on how to. Would it be possible to add a simple demo input method that shows how to use this API, including how to make sure it gets loaded from the user configuration?

Also, there's also a Lua module for fcitx 4, but that doesn't seem have the same API available yet, so it's not possible to add a full input method via Lua in 4, is that correct?

Is it possible to reach the Internet in a Lua IMEAPI Extension?

Discussed in fcitx/fcitx5#579

Originally posted by TheInterestingSoul August 21, 2022
我这边想做一个在快速输入 (QuickPhrase) 中查询热词的脚本,访问下面这个API,然后把返回值添加到快速输入的候选词中:

URL: https://api.jikipedia.com/go/get_hot_search
Method: POST
Content-Type: "application/json;charset=UTF-8"

Body: "{}" (就一对大括号,即一个空对象)

Response:
{
    "updated_at": "2022-08-19T14:51:46+08:00",
    "data": [
        {
            "phrase": "冈本六君子",
            "description": "卖套博主"
        },
        {
            "phrase": "回国了开始复仇",
            "description": "势必夺回自己的摊位"
        },
        ...(一共10个)
    ]
}

在arch下安装lua-socketlua-dkjson包后,编写如下脚本:

local HTTPClient = require("socket.http")
local ltn12 = require("ltn12")
local JSONParser = require("dkjson")
local fcitx = require("fcitx")

--[[ 原生Lua调试时临时换掉fcitx包
local fcitx = {}
fcitx.log = function(x) return print(x) end
]]

local function requestResult()
    fcitx.log("开始调用requestResult方法")
    local response_body = {}
    fcitx.log("开始请求:https://api.jikipedia.com/go/get_hot_search")
    local _, code = HTTPClient.request {
        url = "https://api.jikipedia.com/go/get_hot_search",
        method = "POST",
        headers = {
            ["accept"] = "application/json, text/plain, */*",
            ["content-type"] = "application/json;charset=UTF-8",
            ["user-agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.54",
            ["content-length"] = 2
        },
        source = ltn12.source.string("{}"),
        sink = ltn12.sink.table(response_body),
    }
    fcitx.log("请求结果:" .. table.concat(response_body))
    if code == 200 then
        return table.concat(response_body)
    else
        fcitx.log("请求失败 状态码:" .. code)
        return nil
    end
end

function getSearchCommand()
    fcitx.log("开始调用getSearchCommand方法")
    local originJSON = requestResult()
    local responseData, _, errorMessage = JSONParser.decode(originJSON, 1, nil)
    if responseData ~= nil then
        fcitx.log("解析成功")
        local wordsTable = {}
        for i = 1, 10 do
            wordsTable[i] = responseData.data[i].phrase
        end
        return wordsTable
    else
        fcitx.log("解析失败 原JSON:" .. originJSON .. "\n错误信息:" .. errorMessage)
        return nil
    end
end

ime.register_command("xg", "getSearchCommand", "新梗速查", "digit", "从小鸡词典获取的热搜列表")
--fcitx.log(getSearchCommand()[4])

fcitx包换掉后,用Lua直接执行它 lua xg.lua 时一切正常;将脚本复制到插件目录后重启fcitx5再执行,vxg刚打完,进程就挂了

D2022-08-21 22:47:22.822174 luaaddonstate.cpp:127] quickphrase input xg
D2022-08-21 22:47:22.822224 luaaddonstate.cpp:127] quickphrase call getSearchCommand
D2022-08-21 22:47:22.822259 luaaddonstate.cpp:127] 开始调用getSearchCommand方法
D2022-08-21 22:47:22.822291 luaaddonstate.cpp:127] 开始调用requestResult方法
D2022-08-21 22:47:22.822323 luaaddonstate.cpp:127] 开始请求:https://api.jikipedia.com/go/get_hot_search
=========================
Fcitx 5.0.19 -- Get Signal No.: 11
Date: try "date -d @1661093242" if you are using GNU date ***
ProcessID: 6276
fcitx5(+0x172bc)[0x55bdb53c72bc]
/usr/lib/libc.so.6(+0x38a40)[0x7fc75da51a40]
/usr/lib/libc.so.6(__libc_free+0x69)[0x7fc75c6eaa29]
/usr/lib/libcrypto.so.1.1(ERR_clear_error+0x85)[0x7fc74f712695]
/usr/lib/libcrypto.so.1.1(+0x136da6)[0x7fc74f736da6]
/usr/lib/libc.so.6(+0x8b717)[0x7fc75c6df717]
/usr/lib/libcrypto.so.1.1(CRYPTO_THREAD_run_once+0xe)[0x7fc74f7780ce]
/usr/lib/libcrypto.so.1.1(OPENSSL_init_crypto+0x400)[0x7fc74f737830]
/usr/lib/libcrypto.so.1.1(+0x136b45)[0x7fc74f736b45]
/usr/lib/libc.so.6(+0x8b717)[0x7fc75c6df717]
/usr/lib/libcrypto.so.1.1(CRYPTO_THREAD_run_once+0xe)[0x7fc74f7780ce]
/usr/lib/libcrypto.so.1.1(OPENSSL_init_crypto+0x36c)[0x7fc74f73779c]
/usr/lib/libssl.so.1.1(OPENSSL_init_ssl+0x36)[0x7fc74fafc5c6]
/usr/lib/libssl.so.1.1(SSL_CTX_new+0x2b)[0x7fc74fb080bb]
/usr/lib/lua/5.4/ssl.so(+0x6c8c)[0x7fc7544e8c8c]
/usr/lib/liblua.so.5.4(+0x126a2)[0x7fc75c9356a2]
/usr/lib/liblua.so.5.4(+0x2128f)[0x7fc75c94428f]
/usr/lib/liblua.so.5.4(+0x12c86)[0x7fc75c935c86]
/usr/lib/liblua.so.5.4(+0xd1f4)[0x7fc75c9301f4]
/usr/lib/liblua.so.5.4(+0xd510)[0x7fc75c930510]
/usr/lib/liblua.so.5.4(lua_pcallk+0x90)[0x7fc75c935d50]
/usr/lib/lua/5.4/socket/core.so(+0x669c)[0x7fc75c4fe69c]
/usr/lib/liblua.so.5.4(+0x126a2)[0x7fc75c9356a2]
/usr/lib/liblua.so.5.4(+0x2128f)[0x7fc75c94428f]
/usr/lib/liblua.so.5.4(+0x12c86)[0x7fc75c935c86]
/usr/lib/liblua.so.5.4(+0xd1f4)[0x7fc75c9301f4]
/usr/lib/liblua.so.5.4(+0xd510)[0x7fc75c930510]
/usr/lib/liblua.so.5.4(lua_pcallk+0x90)[0x7fc75c935d50]
/usr/lib/fcitx5/libluaaddonloader.so(+0xf12b)[0x7fc75c99612b]
/usr/lib/fcitx5/libquickphrase.so(+0x126ba)[0x7fc75d3916ba]
/usr/lib/fcitx5/libquickphrase.so(+0xfdb7)[0x7fc75d38edb7]
/usr/lib/fcitx5/libquickphrase.so(+0x10e56)[0x7fc75d38fe56]
段错误 (核心已转储)

经过多次log定位,是在request语句上出了问题

附上 `fcitx5-diagnose` ,点击展开

系统信息:

  1. uname -a:

    Linux tis 5.19.2-arch1-1 fcitx/fcitx5#1 SMP PREEMPT_DYNAMIC Wed, 17 Aug 2022 13:48:51 +0000 x86_64 GNU/Linux
    
  2. lsb_release:

    lsb_release 未找到.

  3. /etc/lsb-release:

    /etc/lsb-release 未找到.

  4. /etc/os-release:

    NAME="Arch Linux"
    PRETTY_NAME="Arch Linux"
    ID=arch
    BUILD_ID=rolling
    ANSI_COLOR="38;2;23;147;209"
    HOME_URL="https://archlinux.org/"
    DOCUMENTATION_URL="https://wiki.archlinux.org/"
    SUPPORT_URL="https://bbs.archlinux.org/"
    BUG_REPORT_URL="https://bugs.archlinux.org/"
    LOGO=archlinux-logo
    
  5. 桌面环境:

    桌面环境为 kde

  6. XDG 会话类型:

    XDG_SESSION_TYPE='wayland'
    
  7. Bash 版本:

    BASH_VERSION='5.1.16(1)-release'
    

环境:

  1. DISPLAY:

    DISPLAY=':1'
    
    
    WAYLAND_DISPLAY='wayland-0'
    
  2. 键盘布局:

    1. setxkbmap:

      WARNING: Running setxkbmap against an XWayland server
      xkb_keymap {
          xkb_keycodes  { include "evdev+aliases(qwerty)" };
          xkb_types     { include "complete"      };
          xkb_compat    { include "complete"      };
          xkb_symbols   { include "pc+us+inet(evdev)"     };
          xkb_geometry  { include "pc(pc105)"     };
      };
      
    2. xprop:

      _XKB_RULES_NAMES(STRING) = "evdev", "pc105", "us", "", ""
      
  3. Locale:

    1. 全部可用 locale:

      C
      C.UTF-8
      POSIX
      zh_CN.utf8
      
    2. 当前 locale:

      LANG=zh_CN.UTF-8
      LC_CTYPE="zh_CN.UTF-8"
      LC_NUMERIC="zh_CN.UTF-8"
      LC_TIME="zh_CN.UTF-8"
      LC_COLLATE="zh_CN.UTF-8"
      LC_MONETARY="zh_CN.UTF-8"
      LC_MESSAGES="zh_CN.UTF-8"
      LC_PAPER="zh_CN.UTF-8"
      LC_NAME="zh_CN.UTF-8"
      LC_ADDRESS="zh_CN.UTF-8"
      LC_TELEPHONE="zh_CN.UTF-8"
      LC_MEASUREMENT="zh_CN.UTF-8"
      LC_IDENTIFICATION="zh_CN.UTF-8"
      LC_ALL=
      
  4. 目录:

    1. 主目录:

      /home/tis
      
    2. ${XDG_CONFIG_HOME}:

      环境变量 XDG_CONFIG_HOME 没有设定。

      XDG_CONFIG_HOME 的当前值是 ~/.config (/home/tis/.config)。

    3. Fcitx5 设置目录:

      当前 fcitx5 设置目录是 ~/.config/fcitx5 (/home/tis/.config/fcitx5)。

  5. 当前用户:

    脚本作为 tis (1000) 运行。

Fcitx 状态:

  1. 可执行文件:

    /usr/bin/fcitx5 找到了 fcitx5。

  2. 版本:

    Fcitx 版本: 5.0.19

  3. 进程:

    找到了 2 个 fcitx5 进程:

       6322 fcitx5
       6327 fcitx5-plasma-t
    
  4. fcitx5-remote:

    fcitx5-remote 工作正常。

  5. DBus 界面:

    使用 dbus-send 来检查 dbus。

    DBus 名称 org.fcitx.Fcitx5 的所有者是 :1.268

    DBus 名称 org.fcitx.Fcitx5 的 PID 所有者是 6322

    来自 dbus 的调试信息:

       Group [x11::1] has 1 InputContext(s)
      IC [9c7f276f076f472a9bfed346efaa6b26] program:microsoft-edge frontend:dbus cap:6000000012 focus:0
    Group [wayland:] has 6 InputContext(s)
      IC [206f995d4eab42a1a9617994896cd297] program:plasmashell frontend:dbus cap:e001800072 focus:0
      IC [836502ff715d44d6a16f856f157663d5] program:plasmashell frontend:dbus cap:e001820072 focus:0
      IC [3b5d80761a4348ef9564c4959af1ef95] program:plasmashell frontend:dbus cap:e801800072 focus:0
      IC [593d7f046fdb44799b06297dec03a903] program:kate frontend:dbus cap:e001800072 focus:0
      IC [c30787b8423a49d79bd182f874e8ac30] program:konsole frontend:dbus cap:e001800072 focus:1
      IC [b1e05a645e884b45a9e9b9134d47731f] program:dolphin frontend:dbus cap:e001800072 focus:0
    Input Context without group
    

Fcitx 配置界面:

  1. 配置工具封装:

    /usr/bin/fcitx5-configtool 找到了 fcitx5-configtool。

  2. Qt 的配置界面:

    /usr/bin/fcitx5-config-qt 找到了 fcitx5-config-qt

  3. KDE 的配置界面:

    找到了 fcitx5 的 kcm 模块。

    kcm_fcitx5                     - 配置输入法
    

前端设置:

Xim:

  1. ${XMODIFIERS}:

    环境变量 XMODIFIERS 已经正确地设为了“@im=fcitx”。
    从环境变量中获取的 Xim 服务名称为 fcitx.

  2. 根窗口上的 XIM_SERVERS:

    Xim 服务的名称与环境变量中设置的相同。

Qt:

  1. qt4 - ${QT4_IM_MODULE}:

    环境变量 QT_IM_MODULE 已经正确地设为了“fcitx”。

  2. qt5 - ${QT_IM_MODULE}:

    环境变量 QT_IM_MODULE 已经正确地设为了“fcitx”。

  3. Qt 输入法模块文件:

    找到了未知的 fcitx qt 模块:/usr/lib/office6/qt/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so
    找到了 fcitx5 qt5 模块:/usr/lib/fcitx5/qt5/libfcitx-quickphrase-editor5.so
    找到了 fcitx5 的 qt6 输入法模块:/usr/lib/qt6/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so
    找到了 fcitx5 的 qt 输入法模块:/usr/lib/qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so
    找到了未知的 fcitx qt 模块:/usr/lib/qt/plugins/kcms/kcm_fcitx5.so
    无法找到 Qt4 的 fcitx5 输入法模块。

Gtk:

  1. gtk - ${GTK_IM_MODULE}:

    环境变量 GTK_IM_MODULE 已经正确地设为了“fcitx”。

  2. gtk-query-immodules:

    1. gtk 2:

      /usr/bin/gtk-query-immodules-2.0 找到了 gtk 2.24.33gtk-query-immodules
      版本行:

      # Created by /usr/bin/gtk-query-immodules-2.0 from gtk+-2.24.33
      

      已找到 gtk 2.24.33 的 fcitx5 输入法模块。

      "/usr/lib/gtk-2.0/2.10.0/immodules/im-fcitx5.so" 
      "fcitx" "Fcitx5 (Flexible Input Method Framework5)" "fcitx5" "/usr/locale" "ja:ko:zh:*" 
      "fcitx5" "Fcitx5 (Flexible Input Method Framework5)" "fcitx5" "/usr/locale" "ja:ko:zh:*" 
      
    2. gtk 3:

      /usr/bin/gtk-query-immodules-3.0 找到了 gtk 3.24.34gtk-query-immodules
      版本行:

      # Created by /usr/bin/gtk-query-immodules-3.0 from gtk+-3.24.34
      

      已找到 gtk 3.24.34 的 fcitx5 输入法模块。

      "/usr/lib/gtk-3.0/3.0.0/immodules/im-fcitx5.so" 
      "fcitx" "Fcitx5 (Flexible Input Method Framework5)" "fcitx5" "/usr/locale" "ja:ko:zh:*" 
      "fcitx5" "Fcitx5 (Flexible Input Method Framework5)" "fcitx5" "/usr/locale" "ja:ko:zh:*" 
      
  3. Gtk 输入法模块缓存:

    1. gtk 2:

      /usr/lib/gtk-2.0/2.10.0/immodules.cache 找到了 gtk 2.24.33 的输入法模块缓存。
      版本行:

      # Created by /usr/bin/gtk-query-immodules-2.0 from gtk+-2.24.33
      

      已找到 gtk 2.24.33 的 fcitx5 输入法模块。

      "/usr/lib/gtk-2.0/2.10.0/immodules/im-fcitx5.so" 
      "fcitx" "Fcitx5 (Flexible Input Method Framework5)" "fcitx5" "/usr/locale" "ja:ko:zh:*" 
      "fcitx5" "Fcitx5 (Flexible Input Method Framework5)" "fcitx5" "/usr/locale" "ja:ko:zh:*" 
      
    2. gtk 3:

      /usr/lib/gtk-3.0/3.0.0/immodules.cache 找到了 gtk 3.24.34 的输入法模块缓存。
      版本行:

      # Created by /usr/bin/gtk-query-immodules-3.0 from gtk+-3.24.34
      

      已找到 gtk 3.24.34 的 fcitx5 输入法模块。

      "/usr/lib/gtk-3.0/3.0.0/immodules/im-fcitx5.so" 
      "fcitx" "Fcitx5 (Flexible Input Method Framework5)" "fcitx5" "/usr/locale" "ja:ko:zh:*" 
      "fcitx5" "Fcitx5 (Flexible Input Method Framework5)" "fcitx5" "/usr/locale" "ja:ko:zh:*" 
      
    3. gtk 4:

      无法找到 gtk 4 的输入法模块缓存

      无法在缓存中找到 gtk 4 的 fcitx5 输入法模块。

  4. Gtk 输入法模块文件:

    1. gtk 2:

      找到的全部 Gtk 2 输入法模块文件均存在。

    2. gtk 3:

      找到的全部 Gtk 3 输入法模块文件均存在。

    3. gtk 4:

      找到的全部 Gtk 4 输入法模块文件均存在。

配置:

Fcitx 插件:

  1. 插件配置文件目录:

    找到了 fcitx5 的插件配置目录:/usr/share/fcitx5/addon

  2. 插件列表:

    1. 找到了 28 个已启用的插件:

      Simplified and Traditional Chinese Translation 5.0.14
      Classic User Interface 5.0.19
      Clipboard 5.0.19
      Cloud Pinyin 5.0.14
      DBus 5.0.19
      DBus Frontend 5.0.19
      Emoji 5.0.19
      Fcitx4 Frontend 5.0.19
      Full width character 5.0.14
      IBus Frontend 5.0.19
      Lua IME API 5.0.9
      Input method selector 5.0.19
      Keyboard 5.0.19
      KDE Input Method Panel 5.0.19
      Lua Addon Loader 5.0.9
      Status Notifier 5.0.19
      Notification 5.0.19
      Pinyin 5.0.14
      Extra Pinyin functionality 5.0.14
      Punctuation 5.0.14
      Quick Phrase 5.0.19
      Spell 5.0.19
      Table 5.0.14
      Unicode 5.0.19
      Wayland 5.0.19
      Wayland Input method frontend 5.0.19
      XCB 5.0.19
      X Input Method Frontend 5.0.19
      
    2. 找到了 0 个被禁用的插件:

  3. 插件库:

    所有插件所需的库都被找到。

  4. 用户界面:

    找到了 2 个已启用的用户界面插件:

    Classic User Interface
    KDE Input Method Panel
    

输入法:

  1. /home/tis/.config/fcitx5/profile:

    [Groups/0]
    # Group Name
    Name=默认
    # Layout
    Default Layout=us
    # Default Input Method
    DefaultIM=pinyin
    
    [Groups/0/Items/0]
    # Name
    Name=keyboard-us
    # Layout
    Layout=
    
    [Groups/0/Items/1]
    # Name
    Name=pinyin
    # Layout
    Layout=
    
    [GroupOrder]
    0=默认
    

日志:

  1. date:

    2022年 08月 21日 星期日 22:49:39 CST
    
  2. /home/tis/.config/fcitx5/crash.log:

    =========================
    Fcitx 5.0.19 -- Get Signal No.: 11
    Date: try "date -d @1661093242" if you are using GNU date ***
    ProcessID: 6276
    fcitx5(+0x172bc)[0x55bdb53c72bc]
    /usr/lib/libc.so.6(+0x38a40)[0x7fc75da51a40]
    /usr/lib/libc.so.6(__libc_free+0x69)[0x7fc75c6eaa29]
    /usr/lib/libcrypto.so.1.1(ERR_clear_error+0x85)[0x7fc74f712695]
    /usr/lib/libcrypto.so.1.1(+0x136da6)[0x7fc74f736da6]
    /usr/lib/libc.so.6(+0x8b717)[0x7fc75c6df717]
    /usr/lib/libcrypto.so.1.1(CRYPTO_THREAD_run_once+0xe)[0x7fc74f7780ce]
    /usr/lib/libcrypto.so.1.1(OPENSSL_init_crypto+0x400)[0x7fc74f737830]
    /usr/lib/libcrypto.so.1.1(+0x136b45)[0x7fc74f736b45]
    /usr/lib/libc.so.6(+0x8b717)[0x7fc75c6df717]
    /usr/lib/libcrypto.so.1.1(CRYPTO_THREAD_run_once+0xe)[0x7fc74f7780ce]
    /usr/lib/libcrypto.so.1.1(OPENSSL_init_crypto+0x36c)[0x7fc74f73779c]
    /usr/lib/libssl.so.1.1(OPENSSL_init_ssl+0x36)[0x7fc74fafc5c6]
    /usr/lib/libssl.so.1.1(SSL_CTX_new+0x2b)[0x7fc74fb080bb]
    /usr/lib/lua/5.4/ssl.so(+0x6c8c)[0x7fc7544e8c8c]
    /usr/lib/liblua.so.5.4(+0x126a2)[0x7fc75c9356a2]
    /usr/lib/liblua.so.5.4(+0x2128f)[0x7fc75c94428f]
    /usr/lib/liblua.so.5.4(+0x12c86)[0x7fc75c935c86]
    /usr/lib/liblua.so.5.4(+0xd1f4)[0x7fc75c9301f4]
    /usr/lib/liblua.so.5.4(+0xd510)[0x7fc75c930510]
    /usr/lib/liblua.so.5.4(lua_pcallk+0x90)[0x7fc75c935d50]
    /usr/lib/lua/5.4/socket/core.so(+0x669c)[0x7fc75c4fe69c]
    /usr/lib/liblua.so.5.4(+0x126a2)[0x7fc75c9356a2]
    /usr/lib/liblua.so.5.4(+0x2128f)[0x7fc75c94428f]
    /usr/lib/liblua.so.5.4(+0x12c86)[0x7fc75c935c86]
    /usr/lib/liblua.so.5.4(+0xd1f4)[0x7fc75c9301f4]
    /usr/lib/liblua.so.5.4(+0xd510)[0x7fc75c930510]
    /usr/lib/liblua.so.5.4(lua_pcallk+0x90)[0x7fc75c935d50]
    /usr/lib/fcitx5/libluaaddonloader.so(+0xf12b)[0x7fc75c99612b]
    /usr/lib/fcitx5/libquickphrase.so(+0x126ba)[0x7fc75d3916ba]
    /usr/lib/fcitx5/libquickphrase.so(+0xfdb7)[0x7fc75d38edb7]
    /usr/lib/fcitx5/libquickphrase.so(+0x10e56)[0x7fc75d38fe56]
    

警告:fcitx5-diagnose 的输出可能包含敏感信息,包括发行版名称,内核版本,正在运行的程序名称等。

尽管这些信息对于开发者诊断问题有帮助,请在公开发送到在线网站前检查并且根据需要移除的对应信息。

pacman -Qs lua
local/fcitx5-lua-git 5.0.9.r1.gd8d2c3d-1
    Lua support for fcitx5, with an imeapi addon implementing googlepinyin api
local/lua 5.4.4-2
    Powerful lightweight programming language designed for extending applications
local/lua-basexx 0.4.1-2
    A Lua library which provides base2(bitfield), base16(hex), base32(crockford/rfc), base64(rfc/url), base85(z85) decoding and encoding for Lua 5.4
local/lua-binaryheap 0.4-2
    Binary heap implementation for Lua 5.4
local/lua-cjson 2.1.0-5
    A fast JSON parsing and encoding support for Lua.
local/lua-cqueues 20200726-3
    Continuation Queues: Embeddable asynchronous networking, threading, and notification framework for Lua 5.4
local/lua-dkjson 2.6-1
    David Kolf’s Pure Lua JSON module with UTF-8 support and no external dependencies for Lua 5.4
local/lua-fifo 0.2-1
    Fifo library for Lua 5.4
local/lua-http 0.4-1
    HTTP Library for Lua 5.4
local/lua-language-server 3.5.3-1
    Lua Language Server coded by Lua
local/lua-lpeg 1.0.2-4
    Pattern-matching library for Lua 5.4
local/lua-lpeg-patterns 0.5-1
    A collection of LPEG patterns for Lua 5.4
local/lua-luaossl 20220711-1
    Most comprehensive OpenSSL module in the Lua universe for Lua 5.4
local/lua-sec 2:1.1.0-1
    Lua bindings for OpenSSL library to provide TLS/SSL communication for Lua 5.4
local/lua-socket 1:3.1.0-1
    Networking support library for the Lua language
local/lua51 5.1.5-9
    Powerful lightweight programming language designed for extending applications
local/lua52 5.2.4-5
    Powerful lightweight programming language designed for extending applications
local/lua53 5.3.6-1
    Powerful lightweight programming language designed for extending applications

missing the doc of the signature of watchEvent's function argument

Hi, currently the document says:

watchEvent (event, function)
    Watch for a event from fcitx.

    Parameters:
        * event int Event Type.
        * function [string](https://www.lua.org/manual/5.1/manual.html#5.4) the function name.

    Returns:
    A unique integer identifier.

    See also:
    [EventType](https://fcitx.github.io/fcitx5-lua/modules/fcitx.html#EventType)

It failed to mention the signature of the function argument, so I had looked into the source, and that's what I found so far:

fun(sym: number, state: number, is_release: boolean) : boolean?

Is it correct? And, when the function returns nil or false, the event.filterAndAccept() will not be fired; but what does this filterAndAccept mean?

data and time format

I wanted to set the Provide current date option when I entered data, but couldn't find out exactly how to do it.
like: when i type "data" then i can choose “2022-09-22” in Candidate

fcitx5-lua requires liblua5.4.so

on openSUSE Tumbleweed, luaaddonloader needs liblua5.4.so to run lua based addons, which is annoying, since liblua5.4.so comes from lua54-devel which is a development package :-(

is there any way to make fcitx5-lua rely on liblua.so.5.4 which belongs to liblua5_4-5?

Thx

Marguerite

ime.register_trigger 函数不触发 handleQuickPhrase

参考 此处 代码,修改为

ime.register_trigger("pinyin_get_current_time", "显示时间", {'test'}, {'时间'})

本地测试发现输入 test 时,候选项中不显示时间,但输入 sj 且候选项中存在 时间 时,正常显示

排查逻辑找到这两处代码:
ime.register_trigger
registerQuickPhrase
按逻辑,最终应该触发 handleQuickPhrase 函数,但似乎并没有被调用,反而是每次都会触发 candidateTrigger 函数

疑惑点:

  1. handleQuickPhrase 是否正常调用;
  2. candidateTrigger 的调用方是哪里,什么逻辑下会被调用?

Could not find Lua 5.4 correctly.

When trying to compile this on Linux From Scratch with Lua version 5.4.0, cmake can't find it correctly even all files located in /usr/include. Terminal output listed below:

CMake Error at /usr/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find Lua (missing: LUA_INCLUDE_DIR) (Required is at least version
  "5.3")
Call Stack (most recent call first):
  /usr/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.17/Modules/FindLua.cmake:232 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:12 (find_package)


-- Configuring incomplete, errors occurred!
See also "/sources/fcitx5-lua/CMakeFiles/CMakeOutput.log".

and I think I have had Lua include files installed correctly:

root [ /sources/fcitx5-lua ]# ls -l /usr/include/lua*
-rw-r--r-- 1 root root 21262  7月 27 19:05 /usr/include/luaconf.h
-rw-r--r-- 1 root root 15765  7月 27 19:05 /usr/include/lua.h
-rw-r--r-- 1 root root   191  7月 27 19:05 /usr/include/lua.hpp
-rw-r--r-- 1 root root  1183  7月 27 19:05 /usr/include/lualib.h

Handling preedit from Lua addon

Thank you for developing.

I updated from Fcitx to Fcitx5 a few days ago.
Currently used with mozc. It works very well.

I have some questions and requests.

Background

I have developed Addon for Fcitx(Fcitx4).

https://github.com/hankei6km/fcitx-at-esc

This addon doesn't work with Fcitx5, so I want to develop a new addon with Lua.

The main features of addon that are planned are as follows.

Execute the following when ESC is pressed.

Commit the text in the pre-editing to context
    ==> Deactivate IME
        ==> Pass through ESC (to Vim etc.)

I wrote the following code, but couldn't get the preedit status.

local fcitx = require("fcitx")

function deactivateInputMethod()
  os.execute("sh -c 'dbus-send --session --print-reply --dest=org.fcitx.Fcitx5 /controller org.fcitx.Fcitx.Controller1.Deactivate >/dev/null &'")
end

local forceDeactivate = false

local confForceDeactivate = false
local confCommitPreedit = false

fcitx.watchEvent(fcitx.EventType.KeyEvent, "keyEventHandler")

function keyEventHandler(sym, state, release)
  if (sym == 65307 and state == 0) and not release then
    if preedit then
      if confCommitPreedit then
        -- fcitx.commitPreedit()
      end
      if confForceDeactivate then
        -- fcitx.deactivateInputMethod()
        deactivateInputMethod()
      end
    else
      -- fcitx.deactivateInputMethod()
      deactivateInputMethod()
    end
  end
  return false
end

Question

  • Is there a way to get the preedit status and text from Lua addon?
  • Is there a way to commit the pre-edit text from Lua addon?

Feature request

It would be helpful if the following features were implemented.

  • preedit flag in KeyEvent haandler
  • fcitx.commitPreedit()
  • fcitx.deactivateInputMethod()
fcitx.watchEvent(fcitx.EventType.KeyEvent, "keyEventHandler")

function keyEventHandler(sym, state, release, preedit)
  if (sym == 65307 and state == 0) and not release then
    if preedit then
      if confCommitPreedit then
        fcitx.commitPreedit()
      end
      if confForceDeactivate then
        fcitx.deactivateInputMethod()
      end

      -- snip

end

or

  • text argument in UpdatePreedit event handler
local curPreeditText = ""

fcitx.watchEvent(fcitx.EventType.UpdatePreedit, "updatePreeditHandler")

function updatePreeditHandler(text)
  -- print(text)
  curPreeditText = text
end

ime.register_trigger not working

fcitx5-chinese-addons-bin/now 5.0.16-1 amd64 [已安装,本地]
fcitx5-chinese-addons-data/jammy,jammy,now 5.0.11-1 all [已安装,自动]
fcitx5-chinese-addons/now 5.0.16-1 all [已安装,本地]
fcitx5-config-qt/jammy,now 5.0.11-1 amd64 [已安装,自动]
fcitx5-data/now 5.0.21-3 all [已安装,本地]
fcitx5-frontend-gtk3/jammy,now 5.0.12-1 amd64 [已安装,自动]
fcitx5-frontend-gtk4/jammy,now 5.0.12-1 amd64 [已安装,自动]
fcitx5-frontend-qt5/jammy,now 5.0.10-1build1 amd64 [已安装,自动]
fcitx5-module-chttrans/jammy,now 5.0.11-1 amd64 [已安装,自动]
fcitx5-module-cloudpinyin/jammy,now 5.0.11-1 amd64 [已安装,自动]
fcitx5-module-fullwidth/jammy,now 5.0.11-1 amd64 [已安装,自动]
fcitx5-module-lua-common/now 5.0.10-1 all [已安装,本地]
fcitx5-module-lua/now 5.0.10-1 amd64 [已安装,本地]
fcitx5-module-pinyinhelper/jammy,now 5.0.11-1 amd64 [已安装,自动]
fcitx5-module-punctuation/jammy,now 5.0.11-1 amd64 [已安装,自动]
fcitx5-modules/now 5.0.21-3 amd64 [已安装,本地]
fcitx5-pinyin/jammy,now 5.0.11-1 amd64 [已安装,自动]
fcitx5-table/jammy,now 5.0.11-1 amd64 [已安装,自动]
fcitx5/now 5.0.21-3 amd64 [已安装,本地]
kde-config-fcitx5/jammy,now 5.0.11-1 amd64 [已安装]
libfcitx-config4/vanessa,now 1:4.2.9.8+mint1+vanessa amd64 [已安装]
libfcitx-core0/vanessa,now 1:4.2.9.8+mint1+vanessa amd64 [已安装]
libfcitx-gclient1/vanessa,now 1:4.2.9.8+mint1+vanessa amd64 [已安装]
libfcitx-qt5-1/jammy,now 1.2.7-1.2build1 amd64 [已安装]
libfcitx-qt5-data/jammy,jammy,now 1.2.7-1.2build1 all [已安装]
libfcitx-utils0/vanessa,now 1:4.2.9.8+mint1+vanessa amd64 [已安装]
libfcitx5-qt-data/jammy,jammy,now 5.0.10-1build1 all [已安装,自动]
libfcitx5-qt1/jammy,now 5.0.10-1build1 amd64 [已安装,自动]
libfcitx5config6/now 5.0.21-3 amd64 [已安装,本地]
libfcitx5core7/now 5.0.21-3 amd64 [已安装,本地]
libfcitx5gclient2/jammy,now 5.0.12-1 amd64 [已安装,自动]
libfcitx5utils2/now 5.0.21-3 amd64 [已安装,本地]

lua 5.3

The code below is not working but ime.register_command is ok

function timestamp(_input)
  return os.time(os.date("!*t"))
end
ime.register_trigger("timestamp", "UNIX 时间戳", { }, { "时间戳" }

watching SwitchInputMethod results in a crash

Calling fcitx.watchEvent with SwitchInputMethod as an argument causes fcitx5 to crash. Other event types mentioned in the documentation work as expected. I've installed lua5.3-dev with apt because it was throwing errors at not being able to find that version of lua, don't know if that's related or not.

It wrote the following into the console when it crashed.

=========================
Fcitx 5.0.5 -- Get Signal No.: 11
Date: try "date -d @1666957142" if you are using GNU date ***
ProcessID: 1394574
/usr/bin/fcitx5(+0xc977)[0x563100a39977]
/lib/x86_64-linux-gnu/libc.so.6(+0x3bd60)[0x7f76c1c37d60]
/lib/x86_64-linux-gnu/libc.so.6(+0x9608a)[0x7f76c028808a]

Hope that helps!

invoking dbus `org.fcitx.Fcitx5` call inside lua addon will block the whole fcitx5 process

first, thanks for making this awesome project, it made my life easier!

i was working on automaticaly setting rime's ascii mode to true, when i pressed , and i encountered the following problem which i think it is worth to report.

my env:

  • fcitx5
  • fcitx5-rime
  • fcitx5-lua

lua that reproduces the problem:

# .local/share/fcitx5/lua/my-ugly-addon/main.lua
local fcitx = require('fcitx')

fcitx.watchEvent(fcitx.EventType.KeyEvent, 'handler')

function handler(sym, state, release)
  --- it seems `return false` mean `un-handled`

  local curim = fcitx.currentInputMethod()
  if curim ~= "rime" then
    return false
  end

  local file = io.popen([[busctl call --user org.fcitx.Fcitx5 /rime org.fcitx.Fcitx.Rime1 GetAsciiMode]], 'r')
  local output = file:read('*all')
  file:close()
  fcitx.log("current ascii mode of rime:")
  fcitx.log(output)

  return false
end

the dbus service is special which is provided by fcitx5 itself; do you think the blocking in here is a expected behavior?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.