parent
73afe0e954
commit
52fbf49309
|
@ -54,37 +54,35 @@ data.history = {}
|
||||||
|
|
||||||
local search_term = nil
|
local search_term = nil
|
||||||
local function itera (inc,a, i)
|
local function itera (inc,a, i)
|
||||||
i = i + inc
|
i = i + inc
|
||||||
local v = a[i]
|
local v = a[i]
|
||||||
if v then return i,v end
|
if v then return i,v end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Load history file in history table
|
--- Load history file in history table
|
||||||
-- @param id The data.history identifier which is the path to the filename.
|
-- @param id The data.history identifier which is the path to the filename.
|
||||||
-- @param[opt] max The maximum number of entries in file.
|
-- @param[opt] max The maximum number of entries in file.
|
||||||
local function history_check_load(id, max)
|
local function history_check_load(id, max)
|
||||||
if id and id ~= ""
|
if id and id ~= "" and not data.history[id] then
|
||||||
and not data.history[id] then
|
data.history[id] = { max = 50, table = {} }
|
||||||
data.history[id] = { max = 50, table = {} }
|
|
||||||
|
|
||||||
if max then
|
if max then
|
||||||
data.history[id].max = max
|
data.history[id].max = max
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = io.open(id, "r")
|
local f = io.open(id, "r")
|
||||||
|
if not f then return end
|
||||||
|
|
||||||
-- Read history file
|
-- Read history file
|
||||||
if f then
|
for line in f:lines() do
|
||||||
for line in f:lines() do
|
if util.table.hasitem(data.history[id].table, line) == nil then
|
||||||
if util.table.hasitem(data.history[id].table, line) == nil then
|
table.insert(data.history[id].table, line)
|
||||||
table.insert(data.history[id].table, line)
|
if #data.history[id].table >= data.history[id].max then
|
||||||
if #data.history[id].table >= data.history[id].max then
|
break
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
f:close()
|
end
|
||||||
end
|
f:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -137,7 +135,7 @@ local function history_save(id)
|
||||||
util.mkdir(id:sub(1, i - 1))
|
util.mkdir(id:sub(1, i - 1))
|
||||||
f = assert(io.open(id, "w"))
|
f = assert(io.open(id, "w"))
|
||||||
end
|
end
|
||||||
for i = 1, math.min(#data.history[id].table, data.history[id].max) do
|
for i = 1, math.min(#data.history[id].table, data.history[id].max) do
|
||||||
f:write(data.history[id].table[i] .. "\n")
|
f:write(data.history[id].table[i] .. "\n")
|
||||||
end
|
end
|
||||||
f:close()
|
f:close()
|
||||||
|
|
Loading…
Reference in New Issue