lovebird icon indicating copy to clipboard operation
lovebird copied to clipboard

Whitespaces are being trimmed

Open Kinrany opened this issue 7 years ago • 4 comments

Currently it's almost impossible to use something like inspect.lua to inspect tables because there's no indentation. Probably trimmed when the text is being converted to HTML.

Kinrany avatar Apr 26 '17 12:04 Kinrany

You can use <pre></pre> tag. It doen't ignore spaces.

egordorichev avatar Apr 26 '17 12:04 egordorichev

Yeah, but that would require

  1. output parsed as HTML, which is not always convenient
  2. extra code
  3. lovebird-specific print code if I don't want tags to show up in regular console

Kinrany avatar Apr 26 '17 13:04 Kinrany

To expand on @egordorichev 's suggestion, you can paste the following into your code after you require() lovebird. This will automatically wrap multi-line prints in <pre></pre> and html-escape them:

lovebird.allowhtml = true
local oldprint = lovebird.print

lovebird.print = function(...)
  local t = {}
  for i = 1, select("#", ...) do
    table.insert(t, tostring(select(i, ...)))
  end
  local str = table.concat(t, " ")
  if str:find("\n") then
    oldprint("<pre>" .. lovebird.htmlescape(str) .. "</pre>")
  else
    oldprint( (lovebird.htmlescape(str)) )
  end
end

2017-04-26-190811_823x471_scrot

rxi avatar Apr 26 '17 18:04 rxi

Much better, thanks!

You could also save the old lovebird.print as lovebird.printhtml, this way it's possible to use both HTML and text output.

Kinrany avatar Apr 26 '17 18:04 Kinrany