On Thu, May 28, 2009 at 13:14, Julien Danjou <[email protected]> wrote:
> Pushed.

Ay, sorry, forgot to add string to the environment, see amended patch.

kk
From fa95409bee45053474ab50f0422ca147913dd5ed Mon Sep 17 00:00:00 2001
From: koniu <[email protected]>
Date: Wed, 27 May 2009 16:49:20 +0100
Subject: [PATCH] awful.util: add linewrap()

Signed-off-by: koniu <[email protected]>
Signed-off-by: Julien Danjou <[email protected]>
---
 lib/awful/util.lua.in |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in
index 5965bda..95d6717 100644
--- a/lib/awful/util.lua.in
+++ b/lib/awful/util.lua.in
@@ -15,6 +15,7 @@ local print = print
 local type = type
 local rtable = table
 local pairs = pairs
+local string = string
 local capi =
 {
     awesome = awesome,
@@ -261,4 +262,24 @@ function table.hasitem(t, item)
     end
 end
 
+--- Split a string into multiple lines
+-- @param text String to wrap.
+-- @param width Maximum length of each line. Default: 72.
+-- @param indent Number of spaces added before each wrapped line. Default: 0.
+-- @return The string with lines wrapped to width.
+function linewrap(text, width, indent)
+    local text = text or ""
+    local width = width or 72
+    local indent = indent or 0
+
+    local pos = 1
+    return text:gsub("(%s+)()(%S+)()",
+        function(sp, st, word, fi)
+            if fi - pos > width then
+                pos = st
+                return "\n" .. string.rep(" ", indent) .. word
+            end
+        end)
+end
+
 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
-- 
1.6.3.1

Reply via email to