6 { shortname
= 'h', longname
= 'help', desc
= 'Show this help menu' },
7 { longname
= 'display', desc
= 'Set the display to connect to', arg
= true },
12 table.sort(optlist
, function(a
, b
) return a
.longname
< b
.longname
end)
14 local function usage()
15 print("\nUsage: dumpcmap <colormap id>\n")
16 for _
, o
in ipairs(optlist
) do
19 str
= '-' .. o
.shortname
23 print(string.format(' %s --%-15s %s', str
, o
.longname
, o
.desc
))
29 for _
, i
in ipairs(optlist
) do
31 shorts
[i
.shortname
] = i
.longname
40 for _
, i
in ipairs(arg
) do
45 if string.sub(i
, 1, 1) == '-' then
46 if string.sub(i
, 2, 2) == '-' then
47 local opt
= string.sub(i
,3)
48 local val
= longs
[opt
]
56 print("Unknown long option "..i
)
60 for o
in string.gmatch(string.sub(i
, 2), '.') do
62 options
[shorts
[o]]
= true
64 print("Unknown option -"..o
)
70 if options
.colormap
then
79 if not options
.colormap
then
92 local x
= lxcb
.connect(options
.display
)
93 if (not x
) or x
:has_error() then
94 print("Error: cannot open display")
102 local cookie
= x
:query_colors(options
.colormap
, query
)
104 query
= x
:query_colors_reply(cookie
)
106 print("Invalid colormap ID")
110 for i
= 1, query
.colors_len
do
111 print(string.format("RGB[%03d] = %04X %04X %04X",
114 query
.colors
[i
].green
,
115 query
.colors
[i
].blue
))