function echoPrompt(prompt)
local args = {} -- a table to hold ColourNote arguments
-- pack the styles into the args table
table.foreach(prompt, function (i, style)
table.extend(args, {RGBToName(style.textcolour), RGBToName(style.backcolour), style.text})
end)
ColourNote(unpack(args))
end
function findInStyles(styles, pat)
for i, style in ipairs(styles) do
local first, last = string.find(style.text, pat)
if first then
return first, last, i
end
end
return nil
end
rgb_map = {}
function toRGB(col_name)
if col_name == "" or col_name == nil then return 0 end
local rgb = rgb_map[col_name]
if rgb == nil then
rgb = ColourNameToRGB(col_name)
rgb_map[col_name] = rgb
end
return rgb
end
function makeStyle(fore, back, txt)
return {textcolour = toRGB(fore), backcolour = toRGB(back), text=txt}
end
PromptProcessor = {
replFunc = nil,
achaea = false,
fix = nil}
PromptProcessor.repl1 = function(prompt, wildcs)
local change, txt
local fore, back = ""
local style = {}
local wildcs = filterWildcs(wildcs)
for k,v in pairs(wildcs) do
if PromptProcessor["last_"..k] then
change = tonumber(wildcs[k]) - PromptProcessor["last_"..k]
if change > 0 then
txt = "+" .. tostring(change) .. k
fore = "lime"
elseif change < 0 then
txt = tostring(change) .. k
fore = "red"
end
if change ~= 0 then
table.insert(prompt, makeStyle("silver", "", "["))
table.insert(prompt, makeStyle(fore,back,txt))
table.insert(prompt, makeStyle("silver", "", "]"))
end
end
if tonumber(v) ~= nil then
PromptProcessor["last_"..k] = tonumber(v)
end
SetEntity("prompt:curr" .. string.upper(k), v)
end
return prompt
end
function SetHints(name, output, wildcs)
if wildcs[1] == "on" then
EnableTrigger("prompt", true)
if name ~= "mute" then
AnsiNote(ANSI(33), "[", ANSI(36), "PromptCatcher", ANSI(33), "]: ", ANSI(37), "You will now see hints in your prompt.", ANSI(0))
end
SetVariable("hintprompt", 1)
elseif wildcs[1] == "off" then
EnableTrigger("prompt", false)
if name ~= "mute" then
AnsiNote(ANSI(33), "[", ANSI(36), "PromptCatcher", ANSI(33), "]: ", ANSI(37), "You will no longer see hints in your prompt.", ANSI(0))
end
SetVariable("hintprompt", 0)
end
end
function SetFixes(name, output, wildcs)
if wildcs[1] == "on" then
PromptProcessor.fix = true
if name ~= "mute" then
AnsiNote(ANSI(33), "[", ANSI(36), "PromptCatcher", ANSI(33), "]: ", ANSI(37), "Your prompts will now be fixed with newlines.", ANSI(0))
end
SetVariable("fixprompt", 1)
elseif wildcs[1] == "off" then
PromptProcessor.fix = false
if name ~= "mute" then
AnsiNote(ANSI(33), "[", ANSI(36), "PromptCatcher", ANSI(33), "]: ", ANSI(37), "Your prompts will no longer be fixed with newlines.", ANSI(0))
end
SetVariable("fixprompt", 0)
end
end
if tonumber(GetVariable("fixprompt")) == 1 then
SetFixes("mute", "", {"on"})
else
SetFixes("mute", "", {"off"})
end
if tonumber(GetVariable("hintprompt")) == 1 then
SetHints("mute", "", {"on"})
else
SetHints("mute", "", {"off"})
end
terminated = false
function OnPluginPacketReceived(packet)
--local start = GetInfo(232)
if PromptProcessor.fix then -- fix prompts only if this option is set
local pat = "\27%[%d?;?%d%dm\13\10"
if terminated and (string.sub(packet, 1,2) == "\13\10") then
packet = string.sub(packet, 3, -1)
terminated = false
elseif (string.find(packet, pat) == 1) then
i,j = string.find(packet, pat)
packet = string.sub(packet, 1, j-2) .. string.sub(packet, j+1, -1)
terminated = false
end
packet = string.gsub(packet, "-\255\249\13\10", "-\13\10")
packet = string.gsub(packet, "-\255\249", "-\13\10")
terminated = true
end
--local timing = GetInfo(232) - start
--AppendToNotepad("test", "Timing: " .. tostring(timing) .. "\r\n")
return packet
end
function debugPrompt(n,o,w,s)
w = filterWildcs(w)
tprint(w)
end
function filterWildcs(w)
local tab = {}
for k,v in pairs(w) do
if type(k) == "string" and v and v ~= "" then
tab[k] = v
end
end
return tab
end
]]>
</script>
</muclient>
|