From fd262a7995dc3fb31a6417a75fe55bb15f090044 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 14 Jan 2021 09:11:08 +0000 Subject: [PATCH] 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. --- .../lua/rom/modules/main/cc/strings.lua | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/resources/data/computercraft/lua/rom/modules/main/cc/strings.lua b/src/main/resources/data/computercraft/lua/rom/modules/main/cc/strings.lua index 49f5cd0d4..89d6e475c 100644 --- a/src/main/resources/data/computercraft/lua/rom/modules/main/cc/strings.lua +++ b/src/main/resources/data/computercraft/lua/rom/modules/main/cc/strings.lua @@ -5,17 +5,24 @@ local expect = require "cc.expect".expect ---- 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 --- @{monitor} or @{printer} without using @{_G.print|print}. --- --- @tparam string text The string to wrap. --- @tparam[opt] number width The width to constrain to, defaults to the width of --- the terminal. --- --- @treturn { string... } The wrapped input string. --- @usage require "cc.strings".wrap("This is a long piece of text", 10) +--[[- 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 +@{monitor} or @{printer} without using @{_G.print|print}. + +@tparam string text The string to wrap. +@tparam[opt] number width The width to constrain to, defaults to the width of +the terminal. +@treturn { string... } The wrapped input string as a list of lines. +@usage Wrap a string and write it to the terminal. + + 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) expect(1, text, "string") expect(2, width, "number", "nil")