-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcenter.lua
More file actions
28 lines (24 loc) · 825 Bytes
/
Copy pathcenter.lua
File metadata and controls
28 lines (24 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- center marker — toggle a fixed crosshair at the map's current
-- centre. Toggle pattern: when enabled, an `on_tick` subscriber is
-- registered against the bus and its `EventHandle` is held; toggle
-- off calls `:remove()` so the callback is genuinely gone from the
-- bus iteration (no per-frame `if not enabled then return end`
-- early-return cost when the marker is hidden).
local handle = nil
local function toggle()
if handle then
handle:remove()
handle = nil
else
handle = ttymap.api.frame.on_tick(function(map)
local lon, lat = map:center()
map:point(lon, lat, "+", "accent_alt")
end)
end
end
ttymap.register_palette_command({
label = "Toggle center marker",
hint = "c",
invoke = toggle,
})
ttymap.register_keybind("c", toggle)