mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 11:40:29 +00:00
Clarify the cc.strings.wrap docs a little
Also make the example a bit more "useful". Hopefully this should clarify that the function returns a table rather than a single string. Closes #678.
This commit is contained in:
parent
58054ad2d1
commit
fd262a7995
@ -5,17 +5,24 @@
|
|||||||
|
|
||||||
local expect = require "cc.expect".expect
|
local expect = require "cc.expect".expect
|
||||||
|
|
||||||
--- Wraps a block of text, so that each line fits within the given width.
|
--[[- Wraps a block of text, so that each line fits within the given width.
|
||||||
--
|
|
||||||
-- This may be useful if you want to wrap text before displaying it to a
|
This may be useful if you want to wrap text before displaying it to a
|
||||||
-- @{monitor} or @{printer} without using @{_G.print|print}.
|
@{monitor} or @{printer} without using @{_G.print|print}.
|
||||||
--
|
|
||||||
-- @tparam string text The string to wrap.
|
@tparam string text The string to wrap.
|
||||||
-- @tparam[opt] number width The width to constrain to, defaults to the width of
|
@tparam[opt] number width The width to constrain to, defaults to the width of
|
||||||
-- the terminal.
|
the terminal.
|
||||||
--
|
@treturn { string... } The wrapped input string as a list of lines.
|
||||||
-- @treturn { string... } The wrapped input string.
|
@usage Wrap a string and write it to the terminal.
|
||||||
-- @usage require "cc.strings".wrap("This is a long piece of text", 10)
|
|
||||||
|
term.clear()
|
||||||
|
local lines = require "cc.strings".wrap("This is a long piece of text", 10)
|
||||||
|
for i = 1, #lines do
|
||||||
|
term.setCursorPos(1, i)
|
||||||
|
term.write(lines[i])
|
||||||
|
end
|
||||||
|
]]
|
||||||
local function wrap(text, width)
|
local function wrap(text, width)
|
||||||
expect(1, text, "string")
|
expect(1, text, "string")
|
||||||
expect(2, width, "number", "nil")
|
expect(2, width, "number", "nil")
|
||||||
|
Loading…
Reference in New Issue
Block a user