Skip to content

Commit 73fe6ae

Browse files
Merge pull request #77 from raphaelcoeffic/simplify_incs
simplified increment functions (page, line, etc…)
2 parents 5252636 + 26fc0e9 commit 73fe6ae

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

src/SCRIPTS/BF/ui.lua

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -133,38 +133,22 @@ local function processMspReply(cmd,rx_buf)
133133
end
134134
end
135135

136-
local function MaxLines()
137-
return #(Page.fields)
136+
local function incMax(val, inc, base)
137+
return ((val + inc + base - 1) % base) + 1
138138
end
139139

140140
local function incPage(inc)
141-
currentPage = currentPage + inc
142-
if currentPage > #(PageFiles) then
143-
currentPage = 1
144-
elseif currentPage < 1 then
145-
currentPage = #(PageFiles)
146-
end
147-
currentLine = 1
148-
Page = nil
149-
collectgarbage()
141+
currentPage = incMax(currentPage, inc, #(PageFiles))
142+
Page = nil
143+
collectgarbage()
150144
end
151145

152146
local function incLine(inc)
153-
currentLine = currentLine + inc
154-
if currentLine > MaxLines() then
155-
currentLine = 1
156-
elseif currentLine < 1 then
157-
currentLine = MaxLines()
158-
end
147+
currentLine = incMax(currentLine, inc, #(Page.fields))
159148
end
160149

161150
local function incMenu(inc)
162-
menuActive = menuActive + inc
163-
if menuActive > #(menuList) then
164-
menuActive = 1
165-
elseif menuActive < 1 then
166-
menuActive = #(menuList)
167-
end
151+
menuActive = incMax(menuActive, inc, #(menuList))
168152
end
169153

170154
local function requestPage()

0 commit comments

Comments
 (0)