Skip to content

Commit 117b29c

Browse files
authored
Merge pull request #1285 from Bumber64/position_lua
position.lua: additional info, option to copy cursor pos
2 parents 959c831 + fc57ea9 commit 117b29c

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Template for new versions:
3636
- `caravan`: If you have managed to select an item that is ethically unacceptable to the merchant, an "Ethics warning" badge will now appear next to the "Trade" button. Clicking on the badge will show you which items that you have selected are problematic. The dialog has a button that you can click to deselect the problematic items in the trade list.
3737
- `confirm`: If you have ethically unacceptable items selected for trade, the "Are you sure you want to trade" confirmation will warn you about them
3838
- `quickfort`: ``#zone`` blueprints now integrated with `preserve-rooms` so you can create a zone and automatically assign it to a noble or administrative role
39+
- `position`: option to copy cursor position to clipboard
3940

4041
## Fixes
4142
- `timestream`: ensure child growth events (e.g. becoming an adult) are not skipped
@@ -46,6 +47,7 @@ Template for new versions:
4647
- `gui/sitemap`: show whether a unit is friendly, hostile, or wild
4748
- `gui/sitemap`: show whether a unit is caged
4849
- `gui/control-panel`: include option for turning off dumping of old clothes for `tailor`, for players who have magma pit dumps and want to save old clothes from being dumped into the magma
50+
- `position`: report current historical era (e.g., "Age of Myth")
4951

5052
## Removed
5153

docs/position.rst

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,30 @@ position
55
:summary: Report cursor and mouse position, along with other info.
66
:tags: fort inspection map
77

8-
This tool reports the current date, clock time, month, and season. It also
9-
reports the cursor position (or just the z-level if no cursor), window size, and
10-
mouse location on the screen.
8+
This tool reports the current date, clock time, month, season, and historical
9+
era. It also reports the keyboard cursor position (or just the z-level if no
10+
active cursor), window size, and mouse location on the screen.
11+
12+
Can also be used to copy the current keyboard cursor position for later use.
1113

1214
Usage
1315
-----
1416

1517
::
1618

17-
position
19+
position [--copy]
20+
21+
Examples
22+
--------
23+
24+
``position``
25+
Print various information.
26+
``position -c``
27+
Copy cursor position to system clipboard.
28+
29+
Options
30+
-------
31+
32+
``-c``, ``--copy``
33+
Copy current keyboard cursor position to the clipboard in format ``0,0,0``
34+
instead of reporting info. For convenience with other tools.

position.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2+
local cursor = df.global.cursor
3+
local args = {...}
4+
if #args > 0 then --Copy keyboard cursor to clipboard
5+
if #args > 1 then
6+
qerror('Too many arguments!')
7+
elseif args[1] ~= '-c' and args[1] ~= '--copy' then
8+
qerror('Invalid argument "'..args[1]..'"!')
9+
elseif cursor.x < 0 then
10+
qerror('No keyboard cursor!')
11+
end
12+
13+
dfhack.internal.setClipboardTextCp437(('%d,%d,%d'):format(cursor.x, cursor.y, cursor.z))
14+
return
15+
end
16+
117
local months = {
218
'Granite, in early Spring.',
319
'Slate, in mid Spring.',
@@ -30,11 +46,15 @@ print('Time:')
3046
print(' The time is '..string.format('%02d:%02d:%02d', hour, minute, second))
3147
print(' The date is '..string.format('%05d-%02d-%02d', df.global.cur_year, month, day))
3248
print(' It is the month of '..months[month])
33-
--TODO: print(' It is the Age of '..age_name)
49+
50+
local eras = df.global.world.history.eras
51+
if #eras > 0 then
52+
print(' It is the '..eras[#eras-1].title.name..'.')
53+
end
3454

3555
print('Place:')
3656
print(' The z-level is z='..df.global.window_z)
37-
print(' The cursor is at x='..df.global.cursor.x..', y='..df.global.cursor.y)
57+
print(' The cursor is at x='..cursor.x..', y='..cursor.y)
3858
print(' The window is '..df.global.gps.dimx..' tiles wide and '..df.global.gps.dimy..' tiles high')
3959
if df.global.gps.mouse_x == -1 then print(' The mouse is not in the DF window') else
4060
print(' The mouse is at x='..df.global.gps.mouse_x..', y='..df.global.gps.mouse_y..' within the window') end

0 commit comments

Comments
 (0)