Fixed issue #1 by modifying TwitterCLI.color()

Added optional third parameter representing the color to set instead of adding
a reset. If null or not given, a reset is used (current behavior).
This commit is contained in:
Jonathan Bernard 2010-11-06 23:51:44 -05:00
parent 16bd16dcf8
commit 9727732360

View File

@ -205,6 +205,7 @@ public class TwitterCLI {
int authorLen = 0, textLen int authorLen = 0, textLen
String statusIndent String statusIndent
def textColor = colors.even
timeline.each { status -> timeline.each { status ->
if (status.user.screenName.length() > authorLen) if (status.user.screenName.length() > authorLen)
@ -223,8 +224,9 @@ public class TwitterCLI {
substring(statusIndent.length()) substring(statusIndent.length())
} }
text = text.replaceAll(/(@\w+)/, color("\$1", colors.mentioned)) textColor = (rowNum % 2 == 0 ? colors.even : colors.odd)
println color(text, (rowNum % 2 == 0 ? colors.even : colors.odd)) text = text.replaceAll(/(@\w+)/, color("\$1", colors.mentioned, textColor))
println color(text, textColor)
} }
} }
@ -234,9 +236,10 @@ public class TwitterCLI {
public String resetColor() { colored ? "\u001b[m" : "" } public String resetColor() { colored ? "\u001b[m" : "" }
public String color(def message, ConsoleColor color) { public String color(def message, ConsoleColor color,
ConsoleColor existing = null) {
if (!colored) return message if (!colored) return message
return color.toString() + message + resetColor() return color.toString() + message + (existing ?: resetColor())
} }
} }