Fixed boundaries function.

master
AardCrowley 2 years ago committed by GitHub
parent d8ef36d6c4
commit 05286b7476
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,54 +6,24 @@
<!-- Plugin "RoomCharWindow" generated by Plugin Wizard --> <!-- Plugin "RoomCharWindow" generated by Plugin Wizard -->
<muclient> <muclient>
<plugin <plugin name="NoteWindow" author="Crowley" id="c49e43d9dce931263263088b" language="Lua" purpose="Note output and hyperlinks" save_state="y" date_written="2022-03-09 11:02:09" requires="5.07" version="1.0" sequence="10">
name="NoteWindow"
author="Crowley" </plugin>
id="c49e43d9dce931263263088b" <!-- Aliases -->
language="Lua"
purpose="Note output and hyperlinks" <aliases>
save_state="y" <alias match="^(note(?: read(?: \d+| last| again)?)?)$" enabled="y" regexp="y" script="startNoteRead" sequence="100">
date_written="2022-03-09 11:02:09" </alias>
requires="5.07"
version="1.0" <alias match="^notewin (on|off|show|hide|clear|help)$" enabled="y" regexp="y" ignore_case="y" script="toggleNoteWin" sequence="100">
sequence="10" </alias>
>
<alias match="^(note\s?(?:list(?:\s\d+)?|unread|to\s\w+|from\s\w+|subj\s.+)?)$" enabled="y" regexp="y" script="startNoteList" sequence="100">
</plugin> </alias>
<!-- Aliases --> </aliases>
<aliases> <script>
<alias <![CDATA[
match="^(note(?: read(?: \d+| last| again)?)?)$"
enabled="y"
regexp="y"
script="startNoteRead"
sequence="100"
>
</alias>
<alias
match="^notewin (on|off|show|hide|clear|help)$"
enabled="y"
regexp="y"
ignore_case="y"
script="toggleNoteWin"
sequence="100"
>
</alias>
<alias
match="^(note\s?(?:list(?:\s\d+)?|unread|to\s\w+|from\s\w+|subj\s.+)?)$"
enabled="y"
regexp="y"
script="startNoteList"
sequence="100"
>
</alias>
</aliases>
<script>
<![CDATA[
local extras = require "aard_lua_extras" local extras = require "aard_lua_extras"
require "gmcphelper" require "gmcphelper"
local snapshotV = tonumber(extras.PackageVersion()) local snapshotV = tonumber(extras.PackageVersion())
@ -127,37 +97,41 @@ function addToWindow(lines)
NotesWin:show() NotesWin:show()
end end
function findBoundaries(tbl)
function findBoundaries(lines) local start_idx = 1
local first_index = nil while start_idx<= #tbl and not tbl[start_idx][2]:find("~") and not tbl[start_idx][2]:find("No more new posts") do
local last_index = nil start_idx = start_idx + 1
end
-- Find the first and last indices with ~ in the text field
for i, v in ipairs(lines) do local end_idx = #tbl
if (string.find(v[1].text, "~") or string.find(v[1].text, "No more new posts")) and not first_index then while end_idx >= 1 and not tbl[end_idx][2]:find("~") and not tbl[end_idx][2]:find("There are no new") do
first_index = i end_idx = end_idx - 1
end end
if (string.find(v[1].text, "~") or string.find(v[1].text, "There are no new")) then
last_index = i if start_idx > 1 then
end table.remove(tbl, 1)
end start_idx = start_idx - 1
end
-- Remove all the entries before the first ~ and after the last ~
if first_index and last_index then if end_idx < #tbl then
for i = #lines, last_index + 1, -1 do table.remove(tbl)
table.remove(lines, i) end_idx = end_idx - 1
end end
for i = first_index - 1, 1, -1 do
table.remove(lines, i) for i = end_idx, start_idx, -1 do
end table.remove(tbl, i)
end end
return lines local lines = {}
for _, entry in ipairs(tbl) do
table.insert(lines, entry[2])
end
return lines
end end
function hyperlinknotes(lines) function hyperlinknotes(lines)
for i,v in ipairs(findBoundaries(lines)) do for i,v in ipairs(extract_lines(lines)) do
if i < 5 or i == #lines then if i < 5 or i == #lines then
Simulate(stylesToANSI(v) .. "\n") Simulate(stylesToANSI(v) .. "\n")
else else
@ -174,31 +148,36 @@ function hyperlinknotes(lines)
end end
function toggleNoteWin(name, line, wildcards) function toggleNoteWin(name, line, wildcards)
if wildcards[1] == "on" or wildcards[1] == "show" then local noteOpt = wildcards[1]
if noteOpt == "on" then
noteShow = "true" noteShow = "true"
SetVariable("noteShow", noteShow) SetVariable("noteShow", noteShow)
ColourNote("white", "blue", "Toggled Note Window Status: " .. wildcards[1]) ColourNote("white", "blue", "Note Extender: Displaying notes in window.")
NotesWin:show() elseif noteOpt == "off" then
elseif wildcards[1] == "off" or wildcards[1] == "hide" then
noteShow = "false" noteShow = "false"
SetVariable("noteShow", noteShow) SetVariable("noteShow", noteShow)
ColourNote("white", "blue", "Toggled Note Window Status: " .. wildcards[1]) ColourNote("white", "blue", "Note Extender: Displaying notes in main output.")
elseif noteOpt == "show" then
NotesWin:fit_contents(850, 500)
NotesWin:show()
elseif noteOpt == "hide" then
NotesWin:hide() NotesWin:hide()
elseif wildcards[1] == "clear" then elseif noteOpt == "clear" then
NotesWin:clear(false) NotesWin:clear(false)
NotesWin:hide() NotesWin:hide()
ColourNote("white", "blue", "Clearing Note Window...") elseif noteOpt == "help" then
elseif wildcards[1] == "help" then
onHelp() onHelp()
end end
end end
function onHelp() function onHelp()
ColourNote("yellow", "", "Basic commands:") ColourNote("yellow", "", "Basic commands:")
ColourNote("orange", "", string.format("%-30s - %s", "notewin <on|show|off|hide>", "Toggles the display of the note window.")) ColourNote("orange", "", string.format("%-30s - %s", "notewin <on|off>", "Toggles where notes are displayed (window or output)."))
ColourNote("orange", "", string.format("%s-30s - %s", "notewin <show|hide>", "Shows or hides the note window."))
ColourNote("orange", "", string.format("%-30s - %s", "notewin clear", "Clears the note window of existing content.")) ColourNote("orange", "", string.format("%-30s - %s", "notewin clear", "Clears the note window of existing content."))
end end
]]> ]]>
</script> </script>
</muclient> </muclient>

Loading…
Cancel
Save