Rewrapping text in a miniconsole
Rewrapping text in a miniconsole
So, I want to rewrap the text in my miniconsoles when they are resized. Currently, my only real strategy is to use moveCursor to move it to the top, then step through each line and rewrap that line, if moveCursor fails, I stop my script (because I reached the end). Any ideas for a better way to do this?
Last edited by Jor'Mox on Tue Jun 04, 2013 3:38 pm, edited 1 time in total.
Re: Rewrapping text in a miniconsole
Also, while this works for when the miniconsole is made smaller, it obviously doesn't unwrap lines when it is made larger. Any ideas on how to achieve that?
Re: Rewrapping text in a miniconsole
Never mind, fixed it. For those that might be interested, this is what I did:
Where window is the name of the miniconsole, and buffer is the name of the text buffer I have been putting the text in. When writing into the buffers, I echo text into it, and then cecho the same text into the window for display. Then, when I get a window resize, I readjust the window wrap value, and run this for each of my windows. Seems to work well, and keep colors nicely. However, you need to set the buffer word wrap length to something large so as to avoid it wrapping lines and losing colors.
Re: Rewrapping text in a miniconsole
By the way, is there any chance we will ever have a way to have access to text in rich text format? I.E. I know we can use copy/paste/appendBuffer to grab things with formatting, but at no point is the text used accessible to let it be edited or interacted with. Even putting copied text into some sort of clipboard that we could interact with would be very useful, I think.
Re: Rewrapping text in a miniconsole
The buffer is fully accessible including all format properties. Use the various select functions and then act on the selected text i.e. replace, add, delete, reformat or retrieve text or format properties of the selected text. For "clipboard" type of background buffers -> createBuffer().
Re: Rewrapping text in a miniconsole
Well, I am actually using a buffer for what I did. But, while I can see that some of the functions work well with buffers, I guess I'm not seeing (in the help or in the wiki) how you would use selectString with one, or other functions like getLineNumber.
Mostly, I seem to be able to getCurrentLine and moveCursor, as well as the various ways of adding text normally (echo and its variants, insertText, paste, etc...).
But maybe I just don't know the proper syntax. So, suppose I had pasted some text into a previously created buffer, that we shall say is named "clipboard" just because. How would you suggest finding an arbitrary string (or perhaps a regex match), getting the matched string, and then replacing it with something (possibly an edited version of the original)?
Here is something of an example of what would be nice if it worked:
Mostly, I seem to be able to getCurrentLine and moveCursor, as well as the various ways of adding text normally (echo and its variants, insertText, paste, etc...).
But maybe I just don't know the proper syntax. So, suppose I had pasted some text into a previously created buffer, that we shall say is named "clipboard" just because. How would you suggest finding an arbitrary string (or perhaps a regex match), getting the matched string, and then replacing it with something (possibly an edited version of the original)?
Here is something of an example of what would be nice if it worked:
By the way, I tested this in a miniconsole, and then echoed the text variable at the end for me to see. The text in the console didn't change, but the text variable did.
Re: Rewrapping text in a miniconsole
There's a regression in mudlet-lua that accidentally overwrites the client's replace function with a version that can't handle multiple windows. You can fix this yourself by deleting the redefinition of the replace function (mudlet-lua/lua/GUIUtils.lua at the very bottom delete everything between do and end.
Re: Rewrapping text in a miniconsole
So, just so I'm clear about things, the select functions just target whatever cursor you moved most recently, yes? I think it could be nice if you could specify a window with them, but I can at least live with that.
As I am often coding things for others, is there any way to fix the replace issue that doesn't involve editing the GUIUtils file? It wasn't a problem for me, and I know I an just supply a replacement version for people to use, but some people are still uncomfortable with doing that.
Also, is there any way to retrieve cursor position when referring to anything other than the main window? Or, failing that, is there a way to move a cursor relative to where it is currently located? For example, suppose I am using a buffer to store a bunch of text, and I want to retrieve the line before the last one. Right now, I don't seem to be able to use getLineNumber or getLineCount to determine where the last line is, so I would have to iterate through the whole buffer until moveCursor failed and use that to determine the last line and work from that, which doesn't really seem like a particularly good strategy to use.
As I am often coding things for others, is there any way to fix the replace issue that doesn't involve editing the GUIUtils file? It wasn't a problem for me, and I know I an just supply a replacement version for people to use, but some people are still uncomfortable with doing that.
Also, is there any way to retrieve cursor position when referring to anything other than the main window? Or, failing that, is there a way to move a cursor relative to where it is currently located? For example, suppose I am using a buffer to store a bunch of text, and I want to retrieve the line before the last one. Right now, I don't seem to be able to use getLineNumber or getLineCount to determine where the last line is, so I would have to iterate through the whole buffer until moveCursor failed and use that to determine the last line and work from that, which doesn't really seem like a particularly good strategy to use.
Re: Rewrapping text in a miniconsole
1. No, the select functions take a buffer name parameter just like all other relevant buffer functions.
2. No, a Lua file in mudlet-lua overrides the function definition. Unless people use latest git you'll need to provide a fixed mudlet-lua replacement or wait for the next release (coming soon though).
3. getLineCount("mywindow")
2. No, a Lua file in mudlet-lua overrides the function definition. Unless people use latest git you'll need to provide a fixed mudlet-lua replacement or wait for the next release (coming soon though).
3. getLineCount("mywindow")
Re: Rewrapping text in a miniconsole
So, I double checked, and it was just not refreshing the display on the miniconsole after I changed the text, so that is why I was thinking something was odd with the select functions.
However, I also double checked, and calling getLineCount for my miniconsole windows and the buffers I'm using to store backups of their text return 0 for getLineCount, despite obviously having text, and multiple lines. So, something is not working correctly for the getLineCount function. Also, getLineNumber returns the same value (the current line in the main window) regardless of if I pass it a window name or not. The getLines function actually produces an error when called in this manner: getLines("windowName",1,2), specifically: getLines: wrong argument type.
Testing so far shows that getCurrentLine is the only such function that works properly with other windows and buffers. The other functions: getLineCount, getLineNumber, getColumnNumber, getLastLineNumber, and getLines all return either incorrect values, produce an error, or return values for the main window. getLastLineNumber requires the argument "main" to produce any result, when it would normally be assumed that if no window is passed, the main window is intended, but, despite taking a window argument, it still only produces real results for the main window (it returned -1 for other windows and buffers).
Also, looking in the GUIUtils file, it is clear that while the prefix and suffix functions take a window argument, they do not pass the window name to the getLineNumber function used to move the cursor, which will produce incorrect behavior regardless of if the getLineNumber function was properly returning results for other windows or not.
However, I also double checked, and calling getLineCount for my miniconsole windows and the buffers I'm using to store backups of their text return 0 for getLineCount, despite obviously having text, and multiple lines. So, something is not working correctly for the getLineCount function. Also, getLineNumber returns the same value (the current line in the main window) regardless of if I pass it a window name or not. The getLines function actually produces an error when called in this manner: getLines("windowName",1,2), specifically: getLines: wrong argument type.
Testing so far shows that getCurrentLine is the only such function that works properly with other windows and buffers. The other functions: getLineCount, getLineNumber, getColumnNumber, getLastLineNumber, and getLines all return either incorrect values, produce an error, or return values for the main window. getLastLineNumber requires the argument "main" to produce any result, when it would normally be assumed that if no window is passed, the main window is intended, but, despite taking a window argument, it still only produces real results for the main window (it returned -1 for other windows and buffers).
Also, looking in the GUIUtils file, it is clear that while the prefix and suffix functions take a window argument, they do not pass the window name to the getLineNumber function used to move the cursor, which will produce incorrect behavior regardless of if the getLineNumber function was properly returning results for other windows or not.