+ statusTxt = (" ".join(options['extra_args'])
+ if options['extra_args']
+ else str(input("message: ")))
+ replies = []
+ ptr = re.compile("@[\w_]+")
+ while statusTxt:
+ s = ptr.match(statusTxt)
+ if s and s.start() == 0:
+ replies.append(statusTxt[s.start():s.end()])
+ statusTxt = statusTxt[s.end()+1:]
+ else:
+ break
+ replies = " ".join(replies)
+ if len(replies) >= 140:
+ # just go back
+ statusTxt = replies
+ replies = ""
+
+ splitted = []
+ while statusTxt:
+ limit = 140 - len(replies)
+ if len(statusTxt) > limit:
+ end = string.rfind(statusTxt, ' ', 0, limit)
+ else:
+ end = limit
+ splitted.append(" ".join((replies,statusTxt[:end])))
+ statusTxt = statusTxt[end:]
+
+ for status in splitted:
+ twitter.statuses.update(status=status)
+
+class TwitterShell(Action):
+
+ def render_prompt(self, prompt):
+ '''Parses the `prompt` string and returns the rendered version'''
+ prompt = prompt.strip("'").replace("\\'","'")
+ for colour in ansi.COLOURS_NAMED:
+ if '[%s]' %(colour) in prompt:
+ prompt = prompt.replace(
+ '[%s]' %(colour), ansi.cmdColourNamed(colour))
+ prompt = prompt.replace('[R]', ansi.cmdReset())
+ return prompt
+
+ def __call__(self, twitter, options):
+ prompt = self.render_prompt(options.get('prompt', 'twitter> '))
+ while True:
+ options['action'] = ""
+ try:
+ args = input(prompt).split()
+ parse_args(args, options)
+ if not options['action']:
+ continue
+ elif options['action'] == 'exit':
+ raise SystemExit(0)
+ elif options['action'] == 'shell':
+ print('Sorry Xzibit does not work here!', file=sys.stderr)
+ continue
+ elif options['action'] == 'help':
+ print('''\ntwitter> `action`\n
+ The Shell Accepts all the command line actions along with:
+
+ exit Leave the twitter shell (^D may also be used)
+
+ Full CMD Line help is appended below for your convinience.''', file=sys.stderr)
+ Action()(twitter, options)
+ options['action'] = ''
+ except NoSuchActionError as e:
+ print(e, file=sys.stderr)
+ except KeyboardInterrupt:
+ print('\n[Keyboard Interrupt]', file=sys.stderr)
+ except EOFError:
+ print(file=sys.stderr)
+ leaving = self.ask(subject='Leave')
+ if not leaving:
+ print('Excellent!', file=sys.stderr)
+ else:
+ raise SystemExit(0)
+
+class PythonPromptAction(Action):
+ def __call__(self, twitter, options):
+ try:
+ while True:
+ smrt_input(globals(), locals())
+ except EOFError:
+ pass