Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weasel支持快速插入当前时间,日期吗? #63

Closed
vipzrx opened this issue Aug 20, 2016 · 19 comments
Closed

weasel支持快速插入当前时间,日期吗? #63

vipzrx opened this issue Aug 20, 2016 · 19 comments
Milestone

Comments

@vipzrx
Copy link

vipzrx commented Aug 20, 2016

感谢作者开发出这样好用的输入法。之前用的搜狗的输入法,可以输入“sj” “rq” 就会出现多合适的时间,日期.
20160820_121841
20160820_121858

请问rime有这个功能吗? 有的话,怎么设置呢?

@Prcuvu
Copy link
Contributor

Prcuvu commented Aug 20, 2016

没有这个功能。

@vipzrx
Copy link
Author

vipzrx commented Aug 20, 2016

这个功能实现起来复杂吗?
你们要是在输入的时候,怎么获取当前的时间和日期呢?

On 2016/8/20 13:47, Prcuvu wrote:

没有这个功能。


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#63 (comment), or
mute the thread
https://github.com/notifications/unsubscribe-auth/AE2-LjXBZH2luCO3CidX2RpaZycwLpIzks5qhpUDgaJpZM4Jo_kT.

@Prcuvu
Copy link
Contributor

Prcuvu commented Aug 20, 2016

实现起来不太容易。
我输入的时候只需看任务栏末端显示的时间,然后抄下来,不依赖输入法。

@osfans
Copy link
Contributor

osfans commented Aug 22, 2016

抄下來?哈哈。簡單的時間功能,boost應該可以做。

@biaoyinzi
Copy link

可以在码表中增加变量和函数,比如$TIME代表时间,$DATE代表日期等。

@biaoyinzi
Copy link

从码表转换到输入字串时,增加一个过滤器(filter)的调用就可以了。把过滤器做成可以配置就更强大了。

@Nonenever
Copy link

还有数字大写的功能

都能实现就好了

@Prcuvu Prcuvu added this to the 0.10.0+ milestone Mar 3, 2018
@QGB
Copy link

QGB commented Aug 30, 2018

@Prcuvu 小狼毫 0.11.1 自带这个选项吗,怎么开启啊

@sephirxth
Copy link

所以到目前为止,仍没有这个功能吗

@Ace-Who
Copy link

Ace-Who commented Oct 11, 2019

现已可通过 lua 插件实现。我的徐码方案 可供参考。

@Prcuvu Prcuvu closed this as completed Feb 15, 2020
@wanglongbiao
Copy link

wanglongbiao commented Apr 25, 2020

我是通过 lua 脚本解决的,目前感觉还挺好用,现在贴出来,希望对以后搜索到这个问题的人有所帮助。

function date_translator(input, seg)
    if (input == "dd") then
       --- Candidate(type, start, end, text, comment)
       yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
       yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
    end
   if (input == "ww") then
      arr = {"","","","","",""}
      arr[0] = ""
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d 星期"..arr[tonumber(os.date("%w"))]), ""))
   end
   if (input == "tt") then
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), ""))
      yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), ""))
   end
 end
 
 --- 过滤器:单字在先
 function single_char_first_filter(input)
    local l = {}
    for cand in input:iter() do
       if (utf8.len(cand.text) == 1) then
          yield(cand)
       else
          table.insert(l, cand)
       end
    end
    for i, cand in ipairs(l) do
       yield(cand)
    end
 end

@oylbin
Copy link

oylbin commented Nov 1, 2021

我是通过 lua 脚本解决的,目前感觉还挺好用,现在贴出来,希望对以后搜索到这个问题的人有所帮助。

function date_translator(input, seg)
    if (input == "dd") then
       --- Candidate(type, start, end, text, comment)
       yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
       yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
    end
   if (input == "ww") then
      arr = {"","","","","",""}
      arr[0] = ""
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d 星期"..arr[tonumber(os.date("%w"))]), ""))
   end
   if (input == "tt") then
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), ""))
      yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), ""))
   end
 end
 
 --- 过滤器:单字在先
 function single_char_first_filter(input)
    local l = {}
    for cand in input:iter() do
       if (utf8.len(cand.text) == 1) then
          yield(cand)
       else
          table.insert(l, cand)
       end
    end
    for i, cand in ipairs(l) do
       yield(cand)
    end
 end

我补充一下:

  1. 上面这份lua代码需要命名为rime.lua,存放在用户目录
    比如我电脑上是C:\Users\oylbin\AppData\Roaming\Rime\rime.lua

  2. 然后,还需要修改用户目录下???.custom.yaml文件,比如我用的是“朙月拼音-简化字”,对应的是luna_pinyin_simp.custom.yaml
    在我电脑上的完整路径是C:\Users\oylbin\AppData\Roaming\Rime\luna_pinyin_simp.custom.yaml
    修改的内容是给engine/translators增加一行配置项- lua_translator@date_translator

        patch:
          'engine/translators/+':
              - lua_translator@date_translator
    
  3. 重新部署后生效。
    如果没生效可以先确认一下用户目录下的build目录下的luna_pinyin_simp.schema.yaml中的配置项的最后一个元素是否是lua_translator@date_translator,比如我的是这样:

      translators:
        - punct_translator
        - "table_translator@custom_phrase"
        - script_translator
        - "lua_translator@date_translator"
    

    我目前的理解是每次部署的时候会根据luna_pinyin_simp.custom.yaml自动生成luna_pinyin_simp.schema.yaml。如果生成build下的文件是正确的,那应该就能生效了。

@lotem
Copy link
Member

lotem commented Nov 5, 2021

除了腳本,也​可以開發Rime插件。

關鍵是這個「功能」一直都只有籠統的說明或者個別示例用法,缺少一份完備的設計用來開發通用組件。

@zhengmingliang
Copy link

我是通过 lua 脚本解决的,目前感觉还挺好用,现在贴出来,希望对以后搜索到这个问题的人有所帮助。

function date_translator(input, seg)
    if (input == "dd") then
       --- Candidate(type, start, end, text, comment)
       yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
       yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
    end
   if (input == "ww") then
      arr = {"","","","","",""}
      arr[0] = ""
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d 星期"..arr[tonumber(os.date("%w"))]), ""))
   end
   if (input == "tt") then
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), ""))
      yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), ""))
   end
 end
 
 --- 过滤器:单字在先
 function single_char_first_filter(input)
    local l = {}
    for cand in input:iter() do
       if (utf8.len(cand.text) == 1) then
          yield(cand)
       else
          table.insert(l, cand)
       end
    end
    for i, cand in ipairs(l) do
       yield(cand)
    end
 end

我补充一下:

  1. 上面这份lua代码需要命名为rime.lua,存放在用户目录
    比如我电脑上是C:\Users\oylbin\AppData\Roaming\Rime\rime.lua

  2. 然后,还需要修改用户目录下???.custom.yaml文件,比如我用的是“朙月拼音-简化字”,对应的是luna_pinyin_simp.custom.yaml
    在我电脑上的完整路径是C:\Users\oylbin\AppData\Roaming\Rime\luna_pinyin_simp.custom.yaml
    修改的内容是给engine/translators增加一行配置项- lua_translator@date_translator

        patch:
          'engine/translators/+':
              - lua_translator@date_translator
    
  3. 重新部署后生效。
    如果没生效可以先确认一下用户目录下的build目录下的luna_pinyin_simp.schema.yaml中的配置项的最后一个元素是否是lua_translator@date_translator,比如我的是这样:

      translators:
        - punct_translator
        - "table_translator@custom_phrase"
        - script_translator
        - "lua_translator@date_translator"
    

    我目前的理解是每次部署的时候会根据luna_pinyin_simp.custom.yaml自动生成luna_pinyin_simp.schema.yaml。如果生成build下的文件是正确的,那应该就能生效了。

确实可以,但是在xxx.custom.yaml 中加了配置,重新部署后没有生效,手动在 luna_pinyin_simp.schema.yaml 中加了- "lua_translator@date_translator"之后,就可以了
image

@aleegreat
Copy link

function date_translator(input, seg)
    if (input == "dd") then
       --- Candidate(type, start, end, text, comment)
       yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
       yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
    end
   if (input == "ww") then
      arr = {"","","","","",""}
      arr[0] = ""
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d 星期"..arr[tonumber(os.date("%w"))]), ""))
   end
   if (input == "tt") then
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), ""))
      yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), ""))
   end
 end
 
 --- 过滤器:单字在先
 function single_char_first_filter(input)
    local l = {}
    for cand in input:iter() do
       if (utf8.len(cand.text) == 1) then
          yield(cand)
       else
          table.insert(l, cand)
       end
    end
    for i, cand in ipairs(l) do
       yield(cand)
    end
 end

请教一下,我发现tt要翻很多页才能翻到,请问怎么可以把tt对应的时间选项提到首页啊??谢谢

@AlbertWang2018
Copy link

function date_translator(input, seg)
    if (input == "dd") then
       --- Candidate(type, start, end, text, comment)
       yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
       yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
    end
   if (input == "ww") then
      arr = {"","","","","",""}
      arr[0] = ""
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d 星期"..arr[tonumber(os.date("%w"))]), ""))
   end
   if (input == "tt") then
      yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), ""))
      yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), ""))
   end
 end
 
 --- 过滤器:单字在先
 function single_char_first_filter(input)
    local l = {}
    for cand in input:iter() do
       if (utf8.len(cand.text) == 1) then
          yield(cand)
       else
          table.insert(l, cand)
       end
    end
    for i, cand in ipairs(l) do
       yield(cand)
    end
 end

请教一下,我发现 tt 要翻很多页才能翻到,请问怎么可以把 tt 对应的时间选项提到首页啊??谢谢

if (input == "time") then
local cand = Candidate("time", seg.start, seg._end, os.date("%H%M"), " ")
cand.quality = 1
yield(cand)
end

cand.quality = 1 就是让结果在第一个,网上搜索 ‘rime 日期’ 答案很多。

@AHSHA98
Copy link

AHSHA98 commented Jan 18, 2023

function date_translator(input, seg)
if (input == "date") then
--- Candidate(type, start, end, text, comment)
local dateTab = {'一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '二十一', '二十二', '二十三', '二十四', '二十五', '二十六', '二十七', '二十八', '二十九', '三十', '三十一'}
local yearTab = {[0] = '〇', '一', '二', '三', '四', '五', '六', '七', '八', '九'}
local year_tbl = ""
for i = 1, 4 do
year_tbl = year_tbl..yearTab[tonumber(string.sub(os.date("%Y"), i, i))]
end
yield(Candidate("date", seg.start, seg._end, os.date("%Y.%m.%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
yield(Candidate("date", seg.start, seg._end, year_tbl.."年"..dateTab[tonumber(os.date("%m"))].."月"..dateTab[tonumber(os.date("%d"))].."日", ""))
yield(Candidate("date", seg.start, seg._end, os.date("%m-%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y/%m/%d"), ""))
end
if (input == "week") then
local weakTab = {'日', '一', '二', '三', '四', '五', '六'}
yield(Candidate("week", seg.start, seg._end, "周"..weakTab[tonumber(os.date("%w")+1)], ""))
yield(Candidate("week", seg.start, seg._end, "星期"..weakTab[tonumber(os.date("%w")+1)], ""))
yield(Candidate("week", seg.start, seg._end, "礼拜"..weakTab[tonumber(os.date("%w")+1)], ""))
end
if (input == "time") then
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%H:%M"), ""))
end
if (input == "ydt") then
yield(Candidate("date", seg.start, seg._end, os.date("%Y.%m%d.%H%M"), ""))
end
end

--- 过滤器:单字在先
function single_char_first_filter(input)
local l = {}
for cand in input:iter() do
if (utf8.len(cand.text) == 1) then
yield(cand)
else
table.insert(l, cand)
end
end
for cand in ipairs(l) do
yield(cand)
end
end

@AHSHA98
Copy link

AHSHA98 commented Jan 18, 2023

增加一个中文的“二〇二三年一月十八日”

@yuzbyu
Copy link

yuzbyu commented Jun 30, 2023

function date_translator(input, seg) if (input == "date") then --- Candidate(type, start, end, text, comment) local dateTab = {'一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '二十一', '二十二', '二十三', '二十四', '二十五', '二十六', '二十七', '二十八', '二十九', '三十', '三十一'} local yearTab = {[0] = '〇', '一', '二', '三', '四', '五', '六', '七', '八', '九'} local year_tbl = "" for i = 1, 4 do year_tbl = year_tbl..yearTab[tonumber(string.sub(os.date("%Y"), i, i))] end yield(Candidate("date", seg.start, seg._end, os.date("%Y.%m.%d"), "")) yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), "")) yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), "")) yield(Candidate("date", seg.start, seg._end, year_tbl.."年"..dateTab[tonumber(os.date("%m"))].."月"..dateTab[tonumber(os.date("%d"))].."日", "")) yield(Candidate("date", seg.start, seg._end, os.date("%m-%d"), "")) yield(Candidate("date", seg.start, seg._end, os.date("%Y/%m/%d"), "")) end if (input == "week") then local weakTab = {'日', '一', '二', '三', '四', '五', '六'} yield(Candidate("week", seg.start, seg._end, "周"..weakTab[tonumber(os.date("%w")+1)], "")) yield(Candidate("week", seg.start, seg._end, "星期"..weakTab[tonumber(os.date("%w")+1)], "")) yield(Candidate("week", seg.start, seg._end, "礼拜"..weakTab[tonumber(os.date("%w")+1)], "")) end if (input == "time") then yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), "")) yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), "")) yield(Candidate("date", seg.start, seg._end, os.date("%H:%M"), "")) end if (input == "ydt") then yield(Candidate("date", seg.start, seg._end, os.date("%Y.%m%d.%H%M"), "")) end end

--- 过滤器:单字在先 function single_char_first_filter(input) local l = {} for cand in input:iter() do if (utf8.len(cand.text) == 1) then yield(cand) else table.insert(l, cand) end end for cand in ipairs(l) do yield(cand) end end

大佬,wubi——pinyin的能搞一下吗,有中文的地方,是乱码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests