Scrolling text window plugin

Posted by Solara on Wed 17 Jul 2019 12:56 AM — 16 posts, 63,215 views.

USA #0
I am trying to get the scrolling text window plugin to work. Nick posted it here: https://www.gammon.com.au/forum/?id=13916

Just experimenting with it, I could NOT get the text to wrap at all. Everything else works as is.

Quote:
require "serialize"

ScrollingPlugin = "a160a0dc029b28fc970a935d"

width = 200
height = 400

CallPlugin (ScrollingPlugin, "SetSize" , width, height)

CallPlugin (ScrollingPlugin, "SetTitle", "Tells")

lines = { }
for x = 1, 300 do
lines [x] = string.format ("Line Line Line Line End %x", x)
end -- for

CallPlugin (ScrollingPlugin, "SetText", serialize.save_simple (lines))


Replacing
CallPlugin (ScrollingPlugin, "SetText", serialize.save_simple (lines))
with
CallPlugin ("ScrollingPlugin, "AddLine", serialize.save_simple (lines), wrap)
does not wrap the line either. How do I get this plugin to wrap the text?
Amended on Wed 17 Jul 2019 01:22 AM by Solara
Australia Forum Administrator #1
From the plugin source:


-- if "wrap" is true then long lines are split at the closest space at
-- the RH side of the window (possibly inserting multiple lines) otherwise
-- the line is inserted "as is" possibly truncating it


So you don't put the word "wrap" there like you did, you make it true, ie.


CallPlugin ("ScrollingPlugin, "AddLine", serialize.save_simple (lines), true)


The variable "wrap", if not defined, will be nil and thus considered false.
USA #2
Ahh, thanks for the fast reponse Nick. That works nicely.

Now I'm trying to clean up the output window a bit and have another question.

The output looks like this when you do an AddLine:

{
  [1] = "the message goes
here",
  }
{
  [1] = "this is another
line added",
  }


I'm looking through the serialize.lua file and I can't figure out how to remove the leading and ending {} to make the display a bit more compact/neater. I would also like to remove the [1] and indentation before it also. Where is this found in the Serialize.Lua file?
Amended on Wed 17 Jul 2019 09:35 PM by Nick Gammon
Australia Forum Administrator #3
The indenting is done here:


  local iname = string.rep (" ", indent) .. name -- indented name


And here for save_simple:


table.insert (out, string.rep (" ", indent))


So you can replace "indent" by 0 (or remove the string.rep part) to not indent it.

So in the first case it would become:


  local iname = name


And in the second case just omit that line that outputs the indent.
USA #4
Hmm I changed

local iname = string.rep (" ", indent) .. name -- indented name

to
local iname = name

and I still got the indents. And I also replaced the indent in two places with 0, but that didn't change anything. I also removed the lines completely and that did not change anything either.
table.insert (out, string.rep (" ", indent))

And I'm still getting extra lines at the beginning with { and then another line with } for the end.
Amended on Wed 17 Jul 2019 11:53 PM by Solara
Australia Forum Administrator #5
Did you reload the plugin? Serialize.lua will stay loaded until the plugin is reloaded.
USA #6
Yeah I reinstall scrolling window plugin and also restarted mushclient.
Australia Forum Administrator #7
Well I don't understand that, as it is (I think) the place where the indenting is done.

Does it matter? It is just internal, you don't actually see the serialized stuff.
USA #8
Well the output window shows it like this:

{
  [1] = "the message goes
here",
  }
{
  [1] = "this is another
line added",
  }
and I"m trying to make it neater and more compact. That's 2 empty lines for every message I get. I'm hoping to get it to look like this:

"the message goes
here"

"this is another
line added"
Amended on Wed 17 Jul 2019 11:56 PM by Solara
USA #9
Okay seems I was making changes to serialize.lua that was in a different directory (copied over so it was in same directory as scrolling_windows). Dumb mistake. So editing the serialize.lua under the lua folder fixed the indent issue. So substituting the indent with 0 and using local iname = name did remove the indent.

My output window now looks like this:
{
[1] = "person: testing
testing 1 2 3 4 5 6 7
8",
}


Is there a way now to remove the leading, ending brackets and the entire line they take up?

EDIT: So I was able to remove the ending bracket (but not the now empty line) by changing this line:
    table.insert (out, string.rep (" ", indent) .. "}")
to
    table.insert (out, string.rep (" ", indent)")
Amended on Thu 18 Jul 2019 12:23 AM by Solara
USA #10
Okay I was able to remove the leading/ending {} and the [1] and indents.

Changed this:
local iname = string.rep (" ", indent) .. name  -->  local iname = name

table.insert (out, iname .. " = {}")  -->  table.insert (out, iname)

table.insert (out, "{\n")  -->  table.insert (out, "")

table.insert (out, string.rep (" ", indent))  -->  table.insert (out, string.rep (" ", 0))

table.insert (out, "[" .. basicSerialize (k) .. "] = ")  -->  table.insert (out, "")


Removed:
table.insert (out, string.rep (" ", indent) .. "}")


FYI: Not sure which line that I changed is critical for SetText but that routine does not work anymore and gives an error that the text was not serialized correctly. AddLine still works fine, and since that's all I use, I'm fine with SetText not working. But I have no idea which line caused it to break.

Edit 2:
Changing these lines caused SetText to break:
table.insert (out, string.rep (" ", indent) .. "}")  --> table.insert (out, string.rep (" ", 0))
table.insert (out, "{\n")  -->  table.insert (out, "")
Amended on Thu 18 Jul 2019 02:07 AM by Solara
Australia Forum Administrator #11
Solara said:

Well the output window shows it like this:

{
  [1] = "the message goes
here",
  }
{
  [1] = "this is another
line added",
  }
and I"m trying to make it neater and more compact. That's 2 empty lines for every message I get. I'm hoping to get it to look like this:

"the message goes
here"

"this is another
line added"



What? It looks like you are serializing it twice. Surely the output window (that the user sees) should not be showing Lua variables at all?
Australia Forum Administrator #12
Sometimes you see on web pages the words "fish & chips" appearing as "fish & chips".

That usually means that they ran the "convert ampersands into HTML" function twice on the same string.
Amended on Thu 18 Jul 2019 06:33 AM by Nick Gammon
Australia Forum Administrator #13

The output looks like this when you do an AddLine:

This is starting to look like something for http://snippets-r-us.com/

I think I am trying to solve the wrong problem for you because you didn’t fully specify what you meant by “the output”.

USA #14
My original intention was to get the Scrolling Window plugin working so it would scroll. That was fixed when you pointed out that "CallPlugin ("ScrollingPlugin, "AddLine", serialize.save_simple (lines), wrap)" should be "CallPlugin ("ScrollingPlugin, "AddLine", serialize.save_simple (lines), true)"

Then I wanted to clean up the appearance of the actual window since the output was putting in leading and ending {} and extra line returns, and also having [1] appear with every AddLine.

You pointed me towards the area of serialize.lua that dealt with it, and I was able to remove the {}, [1] and extra line returns to condense the actual scrolling window. It works nicely. But I seemed to have broken the SetText subroutine by changing 2 of those lines. I suspect the brackets {} are important for the SetText subroutine, though the AddLine works perfectly fine without it.

In any case it works well for me now thanks.
Australia Forum Administrator #15
OK, I think I see what is happening here. From this link:

https://www.gammon.com.au/forum/?id=13916

Quote:

That was fixed when you pointed out that "CallPlugin ("ScrollingPlugin, "AddLine", serialize.save_simple (lines), wrap)" should be "CallPlugin ("ScrollingPlugin, "AddLine", serialize.save_simple (lines), true)"


Actually, if you look at that link, you don't serialize single lines.

The serializing is for multiple lines:


-- sets the window text (a table of lines)
CallPlugin (ScrollingPlugin, "SetText", serialize.save_simple (lines))


If you want to add a single line, use the "AddLine" argument, and don't serialize it. Just send the line in question.

Example from that link:


-- add a new line to the end of the table of lines
CallPlugin (ScrollingPlugin, "AddLine", "New line", wrap)


If you want to add multiple lines, do it in a loop.

You combined serializing with adding single lines, and then went to all the effort of trying to make the serializing give nicer output. You didn't need to do that. You shouldn't see the serialized stuff on the screen.




If you are going to use SetText, then you serialize the output (SetText will remove all those braces and things).

If you are going to use AddLine, then don't serialize the output (however send one line at a time).