Make produceLine output function newline-aware
authorReto Buerki <reet@codelabs.ch>
Thu, 14 Sep 2017 12:41:33 +0000 (14:41 +0200)
committerReto Buerki <reet@codelabs.ch>
Fri, 15 Sep 2017 07:16:18 +0000 (09:16 +0200)
src/output.py
test/test_output.py

index 57bfbb8..fe916dc 100644 (file)
@@ -182,13 +182,14 @@ def produceHeader(borderwidth, *producers):
 
 def produceLine(info, lspace):
     "Produces a line in the header"
-    line = ""
+    result = ""
     if info != "":
-        line += " " * lspace
-        line += info
-        line += "\n"
+        for line in info.splitlines():
+            result += " " * lspace
+            result += line
+            result += "\n"
 
-    return line
+    return result
 
 
 def formatXML(xmlstr, encoding):
index 626cf3c..c37cffd 100644 (file)
@@ -43,6 +43,10 @@ class TestOutput:
         SPACES = 3
         assert output.produceLine(info, SPACES) == result
 
+        info = "info1\ninfo2"
+        result = "   info1\n   info2\n"
+        assert output.produceLine(info, SPACES) == result
+
         emptyinfo = ""
         result = ""
         assert output.produceLine(emptyinfo, SPACES) == result