|
发表于 2024-4-20 01:01:33
|
显示全部楼层
我也有类似需求,写了个函数获取一行或几行间字符的属性,代码如下:
function get_color_string(from_line, to_line)
TOOL.colors = {}
local line,len,char,fmt,key
for i=from_line,to_line do
moveCursor(1, i)
line = getCurrentLine()
len = utf8.len(line)
-- 不知道为什么,最后一个字的fmt取不出来,需要在最后插入一个字符
moveCursor(len, i)
insertText(" ")
for j=0,len-1 do
selectSection(j, 1)
char = getSelection()
fmt = getTextFormat()
if fmt then
key = string.format("%d-%d-%d-%d-%d-%d",
fmt.foreground[1],fmt.foreground[2],fmt.foreground[3],
fmt.background[1],fmt.background[2],fmt.background[3])
table.insert(TOOL.colors, {key, char})
end
end
-- 插入一个换行标记
table.insert(TOOL.colors, {"255-255-255-255-255-255", "\n"})
end
return TOOL.colors
end
其中函数参数from_line, to_line是行数,可以在触发器中用getLineNumber()获取,返回构造的字符和属性的列表。
例如这行:
返回:
{ { "0-255-255-0-0-0", "【" }, { "0-255-255-0-0-0", "闲" }, { "0-255-255-0-0-0", "聊" }, { "0-255-255-0-0-0", "】" }, {
"255-255-255-128-128-0", "☆" }, { "255-255-255-128-128-0", "句" }, { "255-255-255-128-128-0", "比" }, { "255-255-255-128-
128-0", "字" }, { "255-255-255-128-128-0", "栉" }, { "255-255-255-128-128-0", "☆" }, { "192-192-192-0-0-0", " " }, { "180-
0-0-0-0-0", "欧" }, { "180-0-0-0-0-0", "阳" }, { "180-0-0-0-0-0", "摇" }, { "0-255-0-0-0-0", "(" }, { "0-255-0-0-0-0", "Y"
}, { "0-255-0-0-0-0", "a" }, { "0-255-0-0-0-0", "o" }, { "0-255-0-0-0-0", "o" }, { "0-255-0-0-0-0", "u" }, { "0-255-0-0-
0-0", ")" }, { "0-255-255-0-0-0", ":" }, { "0-255-255-0-0-0", " " }, { "0-255-255-0-0-0", "估" }, { "0-255-255-0-0-0",
"计" }, { "0-255-255-0-0-0", "至" }, { "0-255-255-0-0-0", "少" }, { "0-255-255-0-0-0", "1" }, { "0-255-255-0-0-0", "0" },
{ "0-255-255-0-0-0", "0" }, { "0-255-255-0-0-0", "天" }, { "0-255-255-0-0-0", "," }, { "0-255-255-0-0-0", "很" }, { "0-
255-255-0-0-0", "可" }, { "0-255-255-0-0-0", "能" }, { "0-255-255-0-0-0", "得" }, { "0-255-255-0-0-0", "1" }, { "0-255-255-
0-0-0", "年" }, { "192-192-192-0-0-0", " " }, { "192-192-192-0-0-0", " " }, { "255-255-255-0-128-0", "◆" }, { "255-255-
255-0-128-0", "主" }, { "255-255-255-0-128-0", "站" }, { "255-255-255-0-128-0", "◆" }, { "255-255-255-255-255-255", "\n"
} }
有了这个函数,就可以在任务中获取各种颜色特别的显示,比如公孙止、韩员外等就是统计颜色种类最少的字符。
|
|