Finally fixed findBoundaries

master
AardCrowley 2 years ago committed by GitHub
parent 861ece5d1f
commit 7d6a64dd1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,59 +3,27 @@
<!-- Saved on Wednesday, March 09, 2022, 11:04 AM --> <!-- Saved on Wednesday, March 09, 2022, 11:04 AM -->
<!-- MuClient version 5.07-pre --> <!-- MuClient version 5.07-pre -->
<!-- Plugin "RoomCharWindow" generated by Plugin Wizard -->
<muclient> <muclient>
<plugin <plugin name="NoteExtender" 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"
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"
>
</plugin> </plugin>
<!-- Aliases --> <!-- Aliases -->
<aliases> <aliases>
<alias <alias match="^(note(?: read(?: \d+| last| again)?)?)$" enabled="y" regexp="y" script="startNoteRead" sequence="100">
match="^(note(?: read(?: \d+| last| again)?)?)$"
enabled="y"
regexp="y"
script="startNoteRead"
sequence="100"
>
</alias> </alias>
<alias <alias match="^notewin (on|off|show|hide|clear|help)$" enabled="y" regexp="y" ignore_case="y" script="toggleNoteWin" sequence="100">
match="^notewin (on|off|show|hide|clear|help)$"
enabled="y"
regexp="y"
ignore_case="y"
script="toggleNoteWin"
sequence="100"
>
</alias> </alias>
<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">
match="^(note\s?(?:list(?:\s\d+)?|unread|to\s\w+|from\s\w+|subj\s.+)?)$"
enabled="y"
regexp="y"
script="startNoteList"
sequence="100"
>
</alias> </alias>
</aliases> </aliases>
<script> <script>
<![CDATA[ <![CDATA[
local extras = require "aard_lua_extras"
require "gmcphelper" require "gmcphelper"
local extras = require "aard_lua_extras"
local snapshotV = tonumber(extras.PackageVersion()) local snapshotV = tonumber(extras.PackageVersion())
local prefix = GetAlphaOption("script_prefix") local prefix = GetAlphaOption("script_prefix")
@ -118,46 +86,36 @@ function startNoteList(name, line, wildcards)
Capture.untagged_output(param, true, true, true, hyperlinknotes, false) Capture.untagged_output(param, true, true, true, hyperlinknotes, false)
end end
function addToWindow(lines) function findBoundaries(tbl)
NotesWin:clear(false) local startIdx = 1
NotesWin:add_text(lines, false) local endIdx = #tbl
NotesWin:fit_contents(850, 500) while startIdx<= endIdx and not tbl[startIdx][1].text:find("~") and not tbl[strtIdx][1].text:find("No more new") do
NotesWin:set_scroll(1) table.remove(tbl, startIdx)
NotesWin:show() startIdx = startIdx + 1
end end
while endIdx >= 1 and not tbl[endIdx][1].text:find("~") and not tbl[endIdx][1].text:find("There are no") and not tbl[endIdx][1].text:find("Changed to") do
function findBoundaries(lines) table.remove(tbl, endIdx)
local first_index = nil endIdx = endIdx -1
local last_index = nil
-- Find the first and last indices with ~ in the text field
for i, v in ipairs(lines) do
if (string.find(v[1].text, "~") or string.find(v[1].text, "No more new posts")) and not first_index then
first_index = i
end
if (string.find(v[1].text, "~") or string.find(v[1].text, "There are no new")) then
last_index = i
end
end end
-- Remove all the entries before the first ~ and after the last ~ return tbl
if first_index and last_index then
for i = #lines, last_index + 1, -1 do
table.remove(lines, i)
end
for i = first_index - 1, 1, -1 do
table.remove(lines, i)
end
end end
return lines function addToWindow(lines)
local lines = findBoundaries(lines)
NotesWin:clear(false)
NotesWin:add_text(lines, false)
NotesWin:fit_contents(850, 500)
NotesWin:set_scroll(1)
NotesWin:show()
end end
function hyperlinknotes(lines) function hyperlinknotes(lines)
for i,v in ipairs(findBoundaries(lines)) do for i,v in ipairs(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,26 +132,33 @@ 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.")
elseif wildcards[1] == "off" or wildcards[1] == "hide" then elseif noteOpt == "off" 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 wildcards[1] == "clear" then elseif noteOpt == "show" then
NotesWin:fit_contents(850, 500)
NotesWin:show()
elseif noteOpt == "hide" then
NotesWin:hide()
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

Loading…
Cancel
Save