feat: add youdao backend file

This commit is contained in:
JuanZoran
2023-03-16 00:03:13 +08:00
parent efec62d144
commit 978677696e
8 changed files with 146 additions and 43 deletions

View File

@ -24,14 +24,18 @@ local strategy = {
backend.query(data)
while result[name] == nil do
update()
if not update() then
break
end
end
if type(result[name]) == 'table' then
return result[name]
end
end
end
end,
--- TODO :More Strategys
}
@ -58,7 +62,7 @@ local function process(opts)
if not result then
result = strategy[Trans.conf.query](data, data.frontend:wait())
if not result then
-- data.frontend:fallback()
data.frontend:fallback()
return
end
end

View File

@ -115,6 +115,23 @@ function M.display_size(lines, width)
return { height = ds_height, width = ds_width }
end
---Center node utility function
---@param node string -- TODO :Node
---@param win_width integer window width
---@return string
function M.center(node, win_width)
if type(node) == 'string' then
local space = math.max(0, math.floor((win_width - node:width()) / 2))
return string.rep(' ', space) .. node
end
local str = node[1]
win_width = str:width()
local space = math.max(0, math.floor((win_width - str:width()) / 2))
node[1] = string.rep(' ', space) .. str
return node
end
---Execute function in main loop
---@param func function function to be executed
function M.main_loop(func)

View File

@ -157,17 +157,6 @@ function window:open()
end
end
-- function window:center(node)
-- -- TODO :
-- print('TODO Center')
-- -- local text = node[1]
-- -- local width = text:width()
-- -- local win_width = self.width
-- -- local space = math.max(math.floor((win_width - width) / 2), 0)
-- -- node[1] = (' '):rep(space) .. text
-- -- return node
-- end
window.__index = window