feat: format code and add cmd doc
This commit is contained in:
@@ -12,21 +12,33 @@ function M:new()
|
||||
return content
|
||||
end
|
||||
|
||||
--- NOTE :highlight 格式说明:
|
||||
--- 1. 字符串
|
||||
|
||||
|
||||
function M:insert_items_to_line(items, opts)
|
||||
-- NOTE :
|
||||
-- local items = {
|
||||
-- -- style1: string 不需要单独设置高亮的情况
|
||||
-- 'text',
|
||||
-- -- style2: string[] 需要设置高亮,第二个名称为高亮组
|
||||
-- {'text2', 'highlight name'},
|
||||
-- }
|
||||
|
||||
-- local opts = {
|
||||
-- -- 可选的参数
|
||||
-- highlight = 'highlight name' -- string 该行的高亮
|
||||
-- indent = 4 -- integer 该行的应该在开头的缩进
|
||||
-- interval = 4 -- integer 该行组件的间隔
|
||||
-- }
|
||||
function M:insert_items_to_line(items)
|
||||
type_check {
|
||||
items = { items, 'table' },
|
||||
opts = { opts, 'table', true },
|
||||
}
|
||||
|
||||
self.size = self.size + 1 -- line数加一
|
||||
|
||||
local line = {
|
||||
space = (' '):rep(opts.interval),
|
||||
indent = opts.indent,
|
||||
highlight = opts.highlight,
|
||||
space = (' '):rep(items.interval),
|
||||
indent = items.indent,
|
||||
highlight = items.highlight,
|
||||
}
|
||||
local highlight = {}
|
||||
|
||||
@@ -45,7 +57,7 @@ function M:insert_items_to_line(items, opts)
|
||||
self.lines[self.size] = line
|
||||
end
|
||||
|
||||
---遍历lines和高亮的迭代器
|
||||
|
||||
---Usage:
|
||||
--- local buffer_id
|
||||
--- local lines, highlights = M:lines()
|
||||
|
@@ -3,7 +3,6 @@ local M = {}
|
||||
local display = require("Trans.conf.loader").loaded.conf.ui.display
|
||||
local icon = require("Trans.conf.loader").loaded.conf.ui.icon
|
||||
|
||||
local m_field = {}
|
||||
-- {
|
||||
-- collins = 3,
|
||||
-- definition = "n. an expression of greeting",
|
||||
@@ -17,64 +16,53 @@ local m_field = {}
|
||||
-- }
|
||||
|
||||
|
||||
local content = {
|
||||
lines = {
|
||||
need_format = {
|
||||
{}, -- line
|
||||
{}, -- line
|
||||
{}, -- line
|
||||
{}, -- line
|
||||
}
|
||||
},
|
||||
highlight = {
|
||||
[2] = { -- 第几行第几个组件的高亮
|
||||
[1] = 'highlightname',
|
||||
},
|
||||
}
|
||||
}
|
||||
-- local data = {
|
||||
-- { word, 'TransWord' },
|
||||
-- -- NOTE :如果平配置设置显示,并且数据库中存在则有以下字段
|
||||
-- { phonetic, 'TransPhonetic' },
|
||||
-- collins,
|
||||
-- oxford
|
||||
-- -- { phonetic, 'TransPhonetic' },
|
||||
-- }
|
||||
|
||||
local function get_items()
|
||||
local items = {
|
||||
m_field.word,
|
||||
---@alias stuff
|
||||
---| 'data' # 所有组件的信息
|
||||
---| 'highlight?' # 整个组件的高亮
|
||||
---| 'indent?' # 每行整体的缩进
|
||||
---| 'interval?' # 每个组件的间隔
|
||||
---@alias component stuff[]
|
||||
|
||||
---从查询结果中获取字符串
|
||||
---@param field table 查询的结果
|
||||
---@return component component 提取的组件信息[包含多个组件]
|
||||
M.component = function(field)
|
||||
local component = {}
|
||||
local stuffs = {}
|
||||
local data = {
|
||||
{field.word, 'TransWord'},
|
||||
}
|
||||
if display.phonetic then
|
||||
table.insert(items, '[' .. m_field.phonetic .. ']')
|
||||
|
||||
if display.phonetic and field.phonetic then
|
||||
table.insert(data, {
|
||||
'[' .. field.phonetic .. ']', 'TransPhonetic'
|
||||
})
|
||||
end
|
||||
|
||||
if display.collins_star then
|
||||
table.insert(items, icon.star:rep(m_field.collins))
|
||||
if display.collins and field.collins then
|
||||
table.insert(data, {
|
||||
icon.star:rep(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)
|
||||
if display.oxford and field.oxford then
|
||||
table.insert(data, {
|
||||
field.oxford
|
||||
})
|
||||
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
|
||||
stuffs.data = data
|
||||
component[1] = stuffs
|
||||
return component
|
||||
end
|
||||
|
||||
return M
|
||||
|
Reference in New Issue
Block a user