This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Lua word wrap
Started by DannySMc, 29 October 2014 - 09:31 AMPosted 29 October 2014 - 10:31 AM
How do you make a word wrap? As in if I gave you a string of 102 letters, how can I split that on two lines? or if I have more how to split to multiple lines? and even add to a table to use a for loop? I don't know >.<
Posted 29 October 2014 - 10:49 AM
Posted 29 October 2014 - 11:03 AM
Thank you that works a treat, what about a word wrap as you type?
Posted 29 October 2014 - 11:10 AM
Ah, now that's a bit trickier. What have you got already got written? You'll want your basic text input functionality sorted out first.
Posted 29 October 2014 - 01:45 PM
Ah, now that's a bit trickier. What have you got already got written? You'll want your basic text input functionality sorted out first.
haven't even started just an idea, but I would assume you would need to somehow take in each letter one at a time, (could add it to the default read() function as an extra, read("*", true), who knows.
Then add it to a table, as you type, once the table hits the 51 character limit, go back through the table and find the first space and then add a new line in? who knows, but at the end you should be able to use table.concat()
Posted 29 October 2014 - 02:05 PM
What sounds like is that you could create a custom read function and instead of the normal term.write that it uses, use write, however that would bring about the problem of backspacing to get back a character after a line break.
If you want a copy of the bios.lua there's a github repo for all the CC code, read starts at line 226
Here.
And the full repo is Here.
If you want a copy of the bios.lua there's a github repo for all the CC code, read starts at line 226
Here.
And the full repo is Here.
Edited on 29 October 2014 - 01:06 PM
Posted 29 October 2014 - 02:20 PM
What sounds like is that you could create a custom read function and instead of the normal term.write that it uses, use write, however that would bring about the problem of backspacing to get back a character after a line break.
If you want a copy of the bios.lua there's a github repo for all the CC code, read starts at line 226
Here.
And the full repo is Here.
easy, make a temporary table that keeps an eye on where you are, if you go back a space, it will read the last entry of the table and go up a line and to the end.