Started implementing show lists command.

Also added Windows XP support to build file.
Created a working gritter.bat file in bin.
This commit is contained in:
Jonathan Bernard 2010-11-09 16:53:44 -06:00
parent f616cd9f39
commit c9f73e60ea
4 changed files with 41 additions and 10 deletions

View File

@ -0,0 +1 @@
ng com.jdbernard.twitter.TwitterCLI %*

View File

@ -9,7 +9,7 @@
<target name="ng-deploy" depends="build"> <target name="ng-deploy" depends="build">
<!-- Stop the Nailgun Server --> <!-- Stop the Nailgun Server -->
<exec executable="cmd" os=""> <exec executable="cmd" os="Windows XP">
<arg value="/c"/> <arg value="/c"/>
<arg value="ng-stop"/> <arg value="ng-stop"/>
</exec> </exec>
@ -32,7 +32,7 @@
</copy> </copy>
<!-- start the NG server up again. --> <!-- start the NG server up again. -->
<exec executable="cmd" os=""> <exec executable="cmd" os="Windows XP">
<arg value="/c"/> <arg value="/c"/>
<arg value="ng-start"/> <arg value="ng-start"/>
</exec> </exec>

View File

@ -1,7 +1,7 @@
#Tue, 09 Nov 2010 09:22:12 -0600 #Tue, 09 Nov 2010 16:34:03 -0600
lib.local=true lib.local=true
name=gritter name=gritter
version=0.1 version=0.1
build.number=117 build.number=123
nailgun.classpath.dir=/home/jdbernard/programs/nailgun/classpath linux.nailgun.classpath.dir=/home/jdbernard/programs/nailgun/classpath
win32.nailgun.classpath.dir=C\:/Documents and Settings/jbernard/My Documents/ng-classpath nailgun.classpath.dir=C\:/Documents and Settings/jbernard/My Documents/ng-classpath

View File

@ -23,6 +23,7 @@ public class TwitterCLI {
private int terminalWidth private int terminalWidth
private boolean colored private boolean colored
private boolean printStatusTimestamps
private Logger log = LoggerFactory.getLogger(getClass()) private Logger log = LoggerFactory.getLogger(getClass())
@ -100,7 +101,7 @@ public class TwitterCLI {
twitter = (new TwitterFactory(new PropertyConfiguration(cfg))).getInstance() twitter = (new TwitterFactory(new PropertyConfiguration(cfg))).getInstance()
// configure the colors // configure the colors
colors.author = new ConsoleColor(cfg.getProperty("colors.author", "BLUE:false")) colors.author = new ConsoleColor(cfg.getProperty("colors.author", "CYAN:false"))
colors.mentioned = new ConsoleColor(cfg.getProperty("colors.mentioned", "GREEN:false")) colors.mentioned = new ConsoleColor(cfg.getProperty("colors.mentioned", "GREEN:false"))
colors.error = new ConsoleColor(cfg.getProperty("colors.error", "RED:true")) colors.error = new ConsoleColor(cfg.getProperty("colors.error", "RED:true"))
colors.option = new ConsoleColor(cfg.getProperty("colors.option", "YELLOW:true")) colors.option = new ConsoleColor(cfg.getProperty("colors.option", "YELLOW:true"))
@ -111,6 +112,7 @@ public class TwitterCLI {
terminalWidth = (System.getenv().COLUMNS ?: cfg.terminalWidth ?: 79) as int terminalWidth = (System.getenv().COLUMNS ?: cfg.terminalWidth ?: 79) as int
colored = (cfg.colored ?: 'true') as boolean colored = (cfg.colored ?: 'true') as boolean
printStatusTimestamps = (cfg."timeline.printTimestamps" ?: 'true') as boolean
stdin = new Scanner(System.in) stdin = new Scanner(System.in)
} }
@ -276,6 +278,31 @@ public class TwitterCLI {
/* ======== WORKER FUNCTIONS ========*/ /* ======== WORKER FUNCTIONS ========*/
public void printLists(def lists) {
int colSize = 0
// fins largest indentation needed
lists.each { list ->
curColSize = list.user.screenName.length() +
list.user.slug.length() + list.user.fullName.length() +
list.user.id.length()
colSize = Math.max(colSize, curColSize)
}
lists.each { list ->
col1 = color(list.user.screenName, color.author) + "/" +
color("${list.slug} (${list.id})", color.option)
println col1.padLeft(colSize) + ": " + list.fullName
print color("M: ${list.user.memberCount} S: ${list.user.subscriberCount}".
padLeft(2).padRight(colSize - 2), colors.author)
println wrapToWidth(list.description, terminalWidth,
"".padLeft(colSize), "").subtring(colSize)
}
}
public void printTimeline(def timeline) { public void printTimeline(def timeline) {
log.debug("Printing a timeline: {}", timeline) log.debug("Printing a timeline: {}", timeline)
@ -304,7 +331,7 @@ public class TwitterCLI {
if (!user) user = twitter.screenName if (!user) user = twitter.screenName
printLists(twitter.showUserLists(user)) printLists(twitter.getUserLists(user, -1)) // TODO paging
} }
public void showListMembers(LinkedList args) { public void showListMembers(LinkedList args) {
@ -553,15 +580,18 @@ public class TwitterCLI {
// add author's username // add author's username
result = color(status.user.screenName.padLeft( result = color(status.user.screenName.padLeft(
authorLength), colors.author, textColor) + ": " authorLength) + ": ", colors.author, textColor)
// format the status text // format the status text
String text = status.text String text = status.text
// wrap text to terminal width if neceary // if this status takes up more room than we have left on the line
if (text.length() > terminalWidth - indent.length()) { if (text.length() > terminalWidth - indent.length()) {
// wrap text to terminal width
text = wrapToWidth(text, terminalWidth, indent, ""). text = wrapToWidth(text, terminalWidth, indent, "").
substring(indent.length()) substring(indent.length())
// if we are
} }
// color @mentions in the tweet // color @mentions in the tweet