Page 1 of 1
Hanging indent
Posted: Fri Jun 23, 2017 5:23 pm
by Ulenspiegel
Hello!
Does anybody know how to configure Mudlet's output window to use hanging indent? That is, if text is wrapped, first line of it is flush to left margin, and
subsequent lines are all indented.
Thanks in advance.
Re: Hanging indent
Posted: Fri Jun 23, 2017 11:07 pm
by SilverDragon
You'll want to check out Preferences --> Main Display --> Word wrapping. There's two options "wrap lines at", and "indent wrapped lines by", I daresay what you're looking for is the second option. :]
However, one caveat I can think of is that there's no automatic adjustment for how much it indents based on the previous line, so you basically just pick a number of spaces to indent, and that's what you get.
Re: Hanging indent
Posted: Sat Jun 24, 2017 3:24 am
by Ulenspiegel
Thanks.
But I'm afraid that the option there only yields normal indent (first line of paragraph indented to the right, the rest of the lines flush to left margin). What I'm looking for is
hanging indent, where in wrapped paragraph first line is flush with the margin, while subsequent lines are indented. Here's description and illustration to how it should look:
http://www.webopedia.com/TERM/H/hanging_indent.html
Re: Hanging indent
Posted: Sat Jun 24, 2017 12:08 pm
by Jor'Mox
Can you put in a negative number for the indent distance?
Re: Hanging indent
Posted: Sat Jun 24, 2017 2:23 pm
by Ulenspiegel
Nope, I tried. It would be logical, but no - Mudlet won't let me put a negative number there.
Re: Hanging indent
Posted: Sat Jun 24, 2017 2:34 pm
by Jor'Mox
Well, then right now, there is probably no way you can get a hanging indent on wrapped lines. But I'm sure you could put in a feature request asking for it.
Re: Hanging indent
Posted: Sat Jun 24, 2017 2:57 pm
by Ulenspiegel
Thanks; I guess I'll write the request, and in the meantime will try and see if it's possible to do own wrapping in Lua somehow.
Re: Hanging indent
Posted: Sat Jun 24, 2017 3:29 pm
by Jor'Mox
Well, that you could do, actually. Basically you need to create a "Lua Function" trigger. The function it checks will be where you normally put a pattern for the trigger, and if the function returns true, I think it will then run the code in the normal code block. Given what you are trying to do, I would just leave the code block empty, and do everything in the single function. It could look something like this:
function my_line_wrap()
local wrap = 100
local str = ""
local indent = " "
if #line > wrap then -- checks to see if line needs to be wrapped
selectCurrentLine()
replace("") -- clears the text from the game
local len = 0
for w in string.gmatch(line,"(%s*[^%s]+)") -- loops through the current line, one word at a time
if len + #w <= wrap then -- checks to see if word fits in line
str = str .. w -- appends next word
len = len + #w -- keeps track of line length
else
echo(str .. "\n") -- writes accumulated text
str = indent .. string.trim(w) -- starts new line
len = #w + #indent
end
end
end
end
Note that this function does NOTHING to maintain colors. Adding that would add notably more complexity, but should be possible.
Re: Hanging indent
Posted: Mon Jun 26, 2017 3:20 am
by SlySven
Ulenspiegel wrote:Thanks.
But I'm afraid that the option there only yields normal indent (first line of paragraph indented to the right, the rest of the lines flush to left margin)...
I have been looking in that area of the code base recently and I cannot say I was really that much whelmed by the current behaviour {I need to do something because in the on-going work striving towards
I18n our current development code will have difficulties with non-Basic Multi-Plane characters e. g.
Oh bu***r the forum throws an error when I try to post a message containing such characters and other things such as combining diacriticals}.
Although each line may get wrapped if it exceeds the given limit, if there are several such lines in succession they are each considered and wrapped individually which may not be quite what users expect. Of course any simple fix to reflow the wrapped around text is probably going to break something for some existing scripts so it may not be that simple a job. In your case where you say the first line is indented - was it indented by you putting spaces in (or did it come from the MUD server with them) because the "wrapping" action seems to justifiable only kick in if an individual line exceeds the given limit and THEN it is wrapped on its own. From what I recall either the start of the original line would be left flush and the portion that was wrapped around was indented by the given amount or visa-verse (I cannot remember which) but the next line of the original text was then treated so it too either started left flush and the "overflow" was indented (or the opposite way around). I.e.:
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
would get converted to something like:
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
or like:
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
Neither of which may be quite what you were expecting...!