feat: debug format function and add content function support

This commit is contained in:
JuanZoran
2023-01-09 01:59:04 +08:00
parent 5a424c66bb
commit eaf8a3acce
12 changed files with 341 additions and 126 deletions

View File

@@ -1,29 +1,78 @@
local M = {}
local display = require("Trans.conf.loader").loaded.conf.ui.display
-- Example:
-- local content = {
-- width = 1,
-- height = 1;
-- lines = {
-- Highlight = {
-- 'first line',
-- 'second line',
-- }
-- }, ---@table
local icon = require("Trans.conf.loader").loaded.conf.ui.icon
local m_field = {}
-- {
-- collins = 3,
-- definition = "n. an expression of greeting",
-- exchange = "s:hellos",
-- oxford = 1,
-- phonetic = "hə'ləʊ",
-- pos = "u:97/n:3",
-- tag = "zk gk",
-- translation = "n. 表示问候, 惊奇或唤起注意时的用语\nint. 喂;哈罗\nn. (Hello)人名;(法)埃洛",
-- word = "hello"
-- }
-- local function format()
--
-- end
local content = {
lines = {
need_format = {
{}, -- line
{}, -- line
{}, -- line
{}, -- line
}
},
highlight = {
[2] = { -- 第几行第几个组件的高亮
[1] = 'highlightname',
},
}
}
M.to_content = function (field)
-- TODO
local line = ''
local format = '%s %s %s %s'
local content = {
height = 1,
local function get_items()
local items = {
m_field.word,
}
if display.phonetic then
table.insert(items, '[' .. m_field.phonetic .. ']')
end
if display.collins_star then
table.insert(items, icon.star:rep(m_field.collins))
end
if display.oxford then
local item
if m_field.oxford and m_field.oxford == 1 then
item = icon.isOxford
else
item = icon.notOxford
end
table.insert(items, item)
end
return items
end
M.content = function(field)
-- TODO
m_field = field or {}
local content = {}
content.lines = {
need_format = {
get_items()
},
highlight = {
[1] = { -- 第一行
'Trans',
}
}
}
return content
end