Source code for zbot.drivers.console
# zbot/drivers//console.py
#
#
""" console bot. """
## IMPORTS
from zbot.defines import BOLD, ENDC, YELLOW
from zbot.log import datefmt
from zbot import Bot, Object, kernel
import logging
import time
import sys
import os
## CONSOLE
[docs]class ConsoleBot(Bot):
def _raw(self, txt):
try: sys.stdout.write(txt) ; sys.stdout.flush()
except Exception as ex: logging.warn(str(ex))
[docs] def say(self, *args, **kwargs):
try: txt = args[1]
except IndexError: txt = args[0]
if self.outer: o = self.outer ; o.write(txt) ; o.write("\n") ; o.flush()
else: self._raw("%s\n" % txt)
[docs] def get_prompt(self, *args, **kwargs): return "%s -=- %s%s<%s " % (time.strftime(datefmt), BOLD, YELLOW, ENDC)
[docs] def get_one(self, *args, **kwargs):
import readline
o = Object()
if not kernel.cfg.do_shell: o.txt = " ".join(kernel.cfg.runargs) ; o._state = "once"
else: o.txt = input(self.get_prompt())
o._target = self
return o