gritter/src/com/jdbernard/twitter/TwitterCLI.groovy

246 lines
7.5 KiB
Groovy
Raw Normal View History

package com.jdbernard.twitter
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
import com.martiansoftware.nailgun.NGContext
import twitter4j.Twitter
import twitter4j.TwitterFactory
import twitter4j.conf.Configuration
import twitter4j.conf.PropertyConfiguration
public class TwitterCLI {
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
private static String EOL = System.getProperty("line.separator")
private static TwitterCLI nailgunInst
private Twitter twitter
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
private Scanner stdin
private Map colors = [:]
private int terminalWidth
private boolean colored
public static void main(String[] args) {
TwitterCLI inst = new TwitterCLI(new File(System.getProperty("user.home"),
".groovy-twitter-cli-rc"))
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
inst.run((args as List) as Queue)
}
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
public static void nailMain(NGContext context) {
if (nailgunInst == null)
nailgunInst = new TwitterCLI(new File(
System.getProperty("user.home"), ".groovy-twitter-cli-rc"))
else
nailgunInst.stdin = new Scanner(context.in)
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
nailgunInst.
nailgunInst.run((context.args as List) as Queue)
}
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
public static void reconfigure(Queue args) {
if (nailgunInst == null) main(args as String[])
else {
nailgunInst = null
nailgunInst = new TwitterCLI(new File(
System.getProperty("user.home"), ".groovy-twitter-cli-rc"))
nailgunInst.run(args)
}
}
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
static String wrapToWidth(String text, int width, String prefix, String suffix) {
int lastSpaceIdx = 0;
int curLineLength = 0;
int lineStartIdx = 0;
int i = 0;
int actualWidth = width - prefix.length() - suffix.length()
String wrapped = ""
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
text = text.replaceAll("[\n\r]", " ")
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
for (i = 0; i < text.length(); i++) {
curLineLength++
if (curLineLength > actualWidth) {
wrapped += prefix + text[lineStartIdx..<lastSpaceIdx] + suffix + EOL
curLineLength = 0
lineStartIdx = lastSpaceIdx + 1
i = lastSpaceIdx
}
if (text.charAt(i).isWhitespace())
lastSpaceIdx = i
}
if (i - lineStartIdx > 1)
wrapped += prefix + text[lineStartIdx..<text.length()]
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
return wrapped
}
public TwitterCLI(File propFile) {
// load the configuration
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
Properties cfg = new Properties()
propFile.withInputStream { is -> cfg.load(is) }
// create a twitter instance
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
twitter = (new TwitterFactory(new PropertyConfiguration(cfg))).getInstance()
// configure the colors
colors.author = new ConsoleColor(cfg.getProperty("colors.author", "BLUE:false"))
colors.mentioned = new ConsoleColor(cfg.getProperty("colors.mentioned", "GREEN:false"))
colors.error = new ConsoleColor(cfg.getProperty("colors.error", "RED:true"))
colors.option = new ConsoleColor(cfg.getProperty("colors.option", "YELLOW:true"))
colors.even = new ConsoleColor(cfg.getProperty("colors.even", "WHITE"))
colors.odd = new ConsoleColor(cfg.getProperty("colors.odd", "YELLOW"))
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
// configure the terminal width
terminalWidth = (System.getenv().COLUMNS ?: cfg.terminalWidth ?: 79) as int
colored = (cfg.colored ?: 'true') as boolean
stdin = new Scanner(System.in)
}
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
public void run(Queue args) {
if (args.size() < 1) printUsage()
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
while (args.peek()) {
def command = args.poll()
switch (command.toLowerCase()) {
case ~/h.*/: help(args); break
case ~/p.*/: post(args); break
case ~/r.*/: reconfigure(args); break
case ~/se.*/: set(args); break
case ~/sh.*/: show(args); break
case ~/t.*/: timeline(args); break
default:
printUsage()
}
}
}
public void help(Queue args) {
}
public void post(Queue args) {
def status = args.poll()
if (!status) {
println color("post ", colors.option) +
color("command requires one option: ", colors.error) +
"twitter post <status>"
return
}
if (status.length() > 140) {
println color("Status exceeds Twitter's 140 character limit.", colors.error)
return
}
print "Update status: '$status'? "
if (stdin.nextLine() ==~ /yes|y|true|t/)
twitter.updateStatus(status)
}
public void set(Queue args) {
def option = args.poll()
def value = args.poll()
if (!value) { // note: if option is null, value is null
println color("set", colors.option) +
color(" command requires two options: ", colors.error) +
"twitter set <param> <value>"
return
}
switch (option) {
case "terminalWidth": terminalWidth = value as int; break
case "colored": colored = value.toLowerCase() ==~ /true|t|on|yes|y/
break
default:
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
println color("No property named ", colors.error) +
color(option, colors.option) +
color(" exists.", colors.error)
}
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
}
public void show(Queue args) {
}
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
public void timeline(Queue args) {
String timeline = args.poll() ?: "friends"
switch (timeline) {
// friends
case ~/f.*/: printTimeline(twitter.friendsTimeline); break
// mine
case ~/m.*/: printTimeline(twitter.userTimeline); break
// user
case ~/u.*/:
String user = args.poll()
if (user) {
if (user.isNumber())
printTimeline(twitter.getUserTimeline(user as int))
else printTimeline(twitter.getUserTimeline(user))
} else println color("No user specified.", colors.error)
break;
default:
println color("Unknown timeline: ", colors.error) +
color(timeline, colors.option)
break;
}
}
void printTimeline(def timeline) {
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
int authorLen = 0, textLen
String statusIndent
def textColor = colors.even
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
timeline.each { status ->
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
if (status.user.screenName.length() > authorLen)
authorLen = status.user.screenName.length()
}
timeline.eachWithIndex { status, rowNum ->
String text = status.text
print color(status.user.screenName.padLeft(authorLen), colors.author)
print ": "
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
statusIndent = "".padLeft(authorLen + 2)
textLen = terminalWidth - statusIndent.length()
if (text.length() > textLen) {
text = wrapToWidth(text, terminalWidth, statusIndent, "").
substring(statusIndent.length())
}
textColor = (rowNum % 2 == 0 ? colors.even : colors.odd)
text = text.replaceAll(/(@\w+)/, color("\$1", colors.mentioned, textColor))
println color(text, textColor)
}
}
public static void printUsage() {
// TODO
}
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
public String resetColor() { colored ? "\u001b[m" : "" }
public String color(def message, ConsoleColor color,
ConsoleColor existing = null) {
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
if (!colored) return message
return color.toString() + message + (existing ?: resetColor())
Added color, better nailgun support, new argument processing model, base commands. ConsoleColor Added to support for terminal colors by using ANSI escape codes. Basically cross-platform (as close as we're going to get with Java's API) TwitterCLI Added colored output and configurable settings controlling it. Created a specific Nailgun entry-point. When using Nailgun the Twitter object is cached in the JVM so that it doesn't need to be recreated each time a call is made. This also means that settings changed from the command line persist until the Nailgun server is reset. Added functionality to wrap the status nicely to a set width (used for printing timelines). Arguments are not processed internally as a Queue, so each command/option is popped off the queue before it is processed. Added and updated base commands: help - not implemented, will be used to display online help about a command. post - Basic implementation added. It checks the length of the status, and asks for confirmation from the user before posting. reconfigure - If a Nailgun server is being used, it is useful to be able to reconfigure the client without restarting the nailgun server. This scraps the current instance cached by the ng server and creates a fresh instance. set - Allows the user to set a configurable value on the command line. So far, only the following configurable values are available: terminalWidth - integer, used for calculating text wrapping. colored - boolean, enables or disables colored output. show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
}
}