Skip to content

Commit 0f7174d

Browse files
committed
Hoist pens to module-level constants and inline has_matches
1 parent e6cd895 commit 0f7174d

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

plugins/lua/orders.lua

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,9 @@ local LIST_START_Y_TWO_TABS_ROWS = 10
721721
local BOTTOM_MARGIN = 9
722722
local ARROW_X = 10
723723

724+
local SELECTED_PEN = dfhack.pen.parse{fg=COLOR_BLACK, bg=COLOR_WHITE, bold=true}
725+
local MATCH_PEN = dfhack.pen.parse{fg=COLOR_WHITE, bg=COLOR_BLACK, bold=true}
726+
724727
local function perform_search(text)
725728
local matches = {}
726729

@@ -843,15 +846,15 @@ function OrdersSearchOverlay:init()
843846
key='CUSTOM_ALT_P',
844847
auto_width=true,
845848
on_activate=self:callback('cycle_match', -1),
846-
enabled=function() return self:has_matches() end,
849+
enabled=function() return #self.matched_indices > 0 end,
847850
},
848851
widgets.HotkeyLabel{
849852
frame={t=1, l=12},
850853
label='next',
851854
key='CUSTOM_ALT_N',
852855
auto_width=true,
853856
on_activate=self:callback('cycle_match', 1),
854-
enabled=function() return self:has_matches() end,
857+
enabled=function() return #self.matched_indices > 0 end,
855858
},
856859
},
857860
}
@@ -968,10 +971,6 @@ function OrdersSearchOverlay:get_match_text()
968971
return string.format(': %d of %d', self.current_match_idx, total_matches)
969972
end
970973

971-
function OrdersSearchOverlay:has_matches()
972-
return #self.matched_indices > 0
973-
end
974-
975974
local function is_mouse_key(keys)
976975
return keys._MOUSE_L
977976
or keys._MOUSE_R
@@ -1024,26 +1023,14 @@ end
10241023
function OrdersSearchOverlay:render_highlights(dc)
10251024
if #self.matched_indices == 0 then return end
10261025

1027-
local selected_pen = dfhack.pen.parse{
1028-
fg=COLOR_BLACK,
1029-
bg=COLOR_WHITE,
1030-
bold=true,
1031-
}
1032-
1033-
local match_pen = dfhack.pen.parse{
1034-
fg=COLOR_WHITE,
1035-
bg=COLOR_BLACK,
1036-
bold=true,
1037-
}
1038-
10391026
local selected_order_idx = self.current_match_idx > 0 and
10401027
self.matched_indices[self.current_match_idx] or nil
10411028

10421029
for _, match_order_idx in ipairs(self.matched_indices) do
10431030
local match_y = calculateOrderY(match_order_idx)
10441031

10451032
if match_y then
1046-
local pen = (match_order_idx == selected_order_idx) and selected_pen or match_pen
1033+
local pen = (match_order_idx == selected_order_idx) and SELECTED_PEN or MATCH_PEN
10471034

10481035
dc:seek(ARROW_X, match_y):string('|', pen)
10491036
dc:seek(ARROW_X, match_y + 1):string('>', pen)

0 commit comments

Comments
 (0)