This version should wrap the input bar non-destructively so that data gets sent with only those newlines that were added explicitly by the player. It also allows modifications/insertions mid-line. The comment about me not seeing the point of this still applies, but if this is what the OP wants, then this is what the OP gets.
To get a version that sends with the wrap line breaks included (useful for automatically formatting Aardwolf notes, for example, if you change 80 to 79), just remove these three linesfunction OnPluginCommandEntered(sText)
return stripLoneLF(sText)
end
And, of course, modify the plugin name/purpose appropriately, as it's no longer non-destructive.
 |
To save and install the AutoWrapInput plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as AutoWrapInput.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file AutoWrapInput.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="AutoWrapInput_non_destructive"
author="Fiendish"
id="0620f3f9b9bf0ea4d2f5703b"
language="Lua"
purpose="Wraps input at 80 characters non-destructively"
save_state="y"
date_written="2011-11-23 19:36:00"
requires="4.79"
version="1.0"
>
</plugin>
<aliases>
<alias
match="^wrap_input( (.*))?$"
enabled="y"
regexp="y"
sequence="100"
ignore_case="y"
script="activate_wrapping"
></alias>
</aliases>
<script>
<![CDATA[
SetVariable("wrapping", GetVariable("wrapping") or "off")
local wrapping = (GetVariable("wrapping") == "on")
function activate_wrapping(name, line, wildcards)
if wildcards[1] == "" then
Note("Input wrapping is currently: "..GetVariable("wrapping"))
elseif wildcards[2] == "on" or wildcards[2] == "off" then
SetVariable("wrapping", wildcards[2])
wrapping = (wildcards[2] == "on")
Note("Input wrapping set to: "..wildcards[2])
else
Note("WRAP_INPUT ERROR: Expected either 'wrap_input on' or 'wrap_input off'.")
end
end
-- We distinguish between \n and \r\n given an assumption that on Windows (and through Wine)
-- the Enter key always inserts \r\n so that \n can be used to display wrapped lines (MUSHclient handles this)
-- while differentiating line breaks inserted by the user.
function lines(str)
local t = {}
local function helper(line) table.insert(t, line) return "" end
helper((str:gsub("(.-)\r\n", helper)))
return t
end
function OnPluginCommandEntered(sText)
return stripLoneLF(sText)
end
function stripLoneLF(sText)
return string.gsub(sText,"([^\r])\n","%1")
end
function OnPluginCommandChanged()
if not wrapping then
return
end
local user_input = GetCommand()
local user_input_lines = lines(stripLoneLF(user_input))
for i,v in ipairs(user_input_lines) do
local char_count = 80
local line_len = #v
while line_len > char_count do
if string.sub(user_input_lines[i],char_count+1,char_count+1) ~= "\n" then
user_input_lines[i] = string.sub(user_input_lines[i],1,char_count).."\n"..string.sub(user_input_lines[i],char_count+1)
char_count = char_count + 1
line_len = line_len + 1
end
char_count = char_count + 80
end
end
final_input = table.concat(user_input_lines,"\r\n")
-- prevent display errors if the user has input auto-resizing enabled
-- by temporarily changing the minimum number of lines to the amount that
-- the user has typed
if GetOption ("auto_resize_command_window") == 1 then
min_lines = GetOption ("auto_resize_minimum_lines")
max_lines = GetOption ("auto_resize_maximum_lines")
SetOption ("auto_resize_minimum_lines", math.min(max_lines,#user_input_lines))
end
-- enable insertion/deletion in the middle of sections
local selection_start = GetInfo(236)
local selection_end = math.max(0,selection_start-1)
SetCommandSelection (1, -1) -- select everything
PasteCommand(final_input) -- overwrite with wrapped version
-- put the cursor back in the right place after mid-line insertion/deletions
local count = 0
for i in string.gmatch(string.sub(user_input,1,selection_end),"[^\r]\n") do
count = count - 1
end
for i in string.gmatch(string.sub(final_input,1,selection_end),"[^\r]\n") do
count = count + 1
end
SetCommandSelection (selection_start+count, selection_end+count)
-- undo the above resize change
if GetOption ("auto_resize_command_window") == 1 then
SetOption ("auto_resize_minimum_lines", min_lines)
end
end
]]>
</script>
</muclient>
|