function init_ansi()
ANSI_colours = {
[GetNormalColour (BLACK)] = ANSI(0,30),
[GetNormalColour (RED)] = ANSI(0,31),
[GetNormalColour (GREEN)] = ANSI(0,32),
[GetNormalColour (YELLOW)] = ANSI(0,33),
[GetNormalColour (BLUE)] = ANSI(0,34),
[GetNormalColour (MAGENTA)] = ANSI(0,35),
[GetNormalColour (CYAN)] = ANSI(0,36),
[GetNormalColour (WHITE)] = ANSI(0,37),
[GetBoldColour (BLACK)] = ANSI(1,30),
[GetBoldColour (RED)] = ANSI(1,31),
[GetBoldColour (GREEN)] = ANSI(1,32),
[GetBoldColour (YELLOW)] = ANSI(1,33),
[GetBoldColour (BLUE)] = ANSI(1,34),
[GetBoldColour (MAGENTA)] = ANSI(1,35),
[GetBoldColour (CYAN)] = ANSI(1,36),
[GetBoldColour (WHITE)] = ANSI(1,37)
} -- end conversion table
end
init_ansi()
-- also provide the reverse of the extended_colours global table
colours_extended = {}
for i,v in ipairs(extended_colours) do
colours_extended[v] = i
end
-- Returns a string with embedded ansi codes.
-- This can get confused if the player has redefined their color chart.
function stylesToANSI (styles)
local line = {}
local reinit = true
for _,v in ipairs (styles) do
if ANSI_colours[v.textcolour] then
table.insert(line, ANSI_colours[v.textcolour])
elseif colours_extended[v.textcolour] then -- use 256 color xterm ansi when necessary
table.insert(line, ANSI(38,5,colours_extended[v.textcolour]))
elseif reinit then -- limit performance damage
reinit = false
init_ansi()
end
table.insert(line, v.text)
end
table.insert(line, ANSI(0))
return table.concat(line)
end
function chat_echo (name, line, wildcards)
if wildcards [1] == false then
echo = not echo -- toggle
else
echo = wildcards [1]:lower () == " on"
end -- if
if echo then
ColourNote ("yellow", "", "Echoing chats in main window ENABLED.")
else
ColourNote ("yellow", "", "Echoing chats in main window DISABLED.")
end -- if
end -- function chat_echo
function chat_show (name, line, wildcards)
WindowShow( Win, true )
ColourNote ("yellow", "", "Chats window now shown. Type 'chats hide' to hide it.")
end -- function chat_show
function chat_hide (name, line, wildcards)
WindowShow( Win, false )
ColourNote ("yellow", "", "Chats window now hidden. Type 'chats show' to see it again.")
end -- function chat_hide
-- right click menu
function right_click_menu ()
menustring ="Copy All To Clipboard|Change Font|Turn Echo "
if echo then
menustring = menustring .. "Off"
else
menustring = menustring .. "On"
end -- if
menustring = menustring.."|>Timestamp|No Timestamps|30 Aug 13:29:49|30 Aug 01:20:12PM|13:29:08|1:22:06 PM"
result = WindowMenu (Win,
WindowInfo (Win, 14), -- x position
WindowInfo (Win, 15), -- y position
menustring) -- content
if result == "Copy All To Clipboard" then
GetAllBufferedMessages()
ColourNote ("yellow", "", "All buffered messages copied to clipboard.")
elseif result == "Change Font" then
wanted_font = utils.fontpicker (BODY_FONT_NAME, BODY_FONT_SIZE) --font dialog
if wanted_font then
BODY_FONT_NAME = wanted_font.name
BODY_FONT_SIZE = wanted_font.size
SetVariable ("bodyfont", BODY_FONT_NAME)
SetVariable ("font_size", BODY_FONT_SIZE)
OnPluginInstall()
end
elseif result == "Turn Echo Off" then
echo = false
ColourNote ("yellow", "", "Echoing chats in main window DISABLED.")
elseif result == "Turn Echo On" then
echo = true
ColourNote ("yellow", "", "Echoing chats in main window ENABLED.")
elseif result == "No Timestamps" then
timestamp = false
ColourNote ("yellow", "", "Timestamps in communication window DISABLED.")
elseif result == "30 Aug 13:29:49" then
timestamp = true
date_format = "[%d %b %H:%M:%S] "
ColourNote ("yellow", "", "Timestamps in communication window ENABLED using format like '30 Aug 13:29:49'.")
elseif result == "30 Aug 01:20:12PM" then
timestamp = true
date_format = "[%d %b %I:%M:%S%p] "
ColourNote ("yellow", "", "Timestamps in communication window ENABLED using format like '30 Aug 01:20:12PM'.")
elseif result == "13:29:08" then
timestamp = true
date_format = "[%H:%M:%S] "
ColourNote ("yellow", "", "Timestamps in communication window ENABLED using format like '13:29:08'.")
elseif result == "1:22:06 PM" then
timestamp = true
date_format = "[%I:%M:%S%p] "
ColourNote ("yellow", "", "Timestamps in communication window ENABLED using format like '1:22:06 PM'.")
end -- if
end -- function right_click_menu
]]>
</script>
</muclient>
[EDIT] Code tags added. |