# Path: giraffez/fmt.py
# def format_table(lines, header=True):
#     widths = [0] * len(lines[0])
#     for line in lines:
#         widths = [max(a, len(str(b))) for a, b in zip(widths, line)]
#     output = []
#     for i, line in enumerate(lines):
#         output.append(" | ".join([str(field).ljust(w) for w, field in zip(widths, line)]))
#         if i == 0 and header:
#             output.append("-"*len(output[0]))
#     return "\n".join(output)
# 
# def replace_cr(s):
#     if not isinstance(s, str):
#         return s
#     return s.strip().replace('\r', '\n')
# 
# Path: giraffez/logging.py
# def run_once(f):
#     def wrapper(*args, **kwargs):
# def setup_logging():
#     def colorize(cls, color, s):
#     def blue(cls, s):
#     def green(cls, s):
#     def gray(cls, s):
#     def white(cls, s):
#     def disabled(cls, s):
#     def bold(cls, s):
#     def fail(cls, s):
# def highlight(s):
#     def __init__(self, fd=None, level=INFO):
#     def level(self):
#     def level(self, v):
#     def _write(self, args, level=None, console=False):
#     def write(self, *args, **kwargs):
#     def info(self, *args, **kwargs):
#     def verbose(self, *args, **kwargs):
#     def debug(self, *args, **kwargs):
#     def fatal(self, msg=""):
#     def __init__(self, fd=None, level=INFO):
#     def _write(self, args, level=None, console=True):
# CONSOLE_HEADER = "\033[95m"
# CONSOLE_BLUE = "\033[94m"
# CONSOLE_GREEN = "\033[92m"
# CONSOLE_GRAY = "\033[37m"
# CONSOLE_WHITE = "\033[97m"
# CONSOLE_WARNING = "\033[93m"
# CONSOLE_ENDC = "\033[0m"
# CONSOLE_FAIL = "\033[91m"
# CONSOLE_BOLD = "\033[1m"
# CONSOLE_UNDERLINE = "\033[4m" 
# CONSOLE_DISABLED = "\033[38;5;240m" 
# class colors(object):
# class Logger(object):
# class LockingLogger(Logger):
# 
# Path: giraffez/utils.py
# def get_version_info():
#     from giraffez.__init__ import __title__, __version__
#     return __title__, __version__
# 
# def timer(f):
#     @functools.wraps(f)
#     def wrapper(*args, **kwds):
#         start = time.time()
#         result = f(*args, **kwds)
#         elapsed = time.time() - start
#         sys.stderr.write("{} took {:.4f}s to finish\n".format(f.__name__, elapsed))
#         return result
#     return wrapper


import cmd as _cmd
import os
import sys
import time
import atexit
import itertools
import functools
import threading
    import os
    import readline
        import readline
from .constants import *
from .errors import *
from ._teradata import TeradataError
from .fmt import format_table, replace_cr
from .logging import log, setup_logging
from .utils import get_version_info, timer
            ec = sum([line.count(c) for c in self.end_chars])
            if sc != ec:
                while True:
                    q = input("       > ")
                    if not q:
                        break
                    line += q
                    sc = sum([line.count(c) for c in self.start_chars])
                    ec = sum([line.count(c) for c in self.end_chars])
                    if sc == ec:
                        break
        except KeyboardInterrupt:
            sys.stderr.write("\n")
            return
        try:
            result = self.command(line)
        except TeradataError as error:
            log.write("{0!r}".format(error))
            return
        if not result:
            log.write("No results")
            return
        if self.table_output and not (line.lower().startswith("show") or line.lower().startswith("help")):
            log.write()
            rows = [replace_cr(row) for row in result]
            rows.insert(0, result.columns.names)
            sys.stdout.write(format_table(rows))
            sys.stdout.write("\n")
        else:
            for row in result:

# Path: giraffez/fmt.py
# def format_table(lines, header=True):
#     widths = [0] * len(lines[0])
#     for line in lines:
#         widths = [max(a, len(str(b))) for a, b in zip(widths, line)]
#     output = []
#     for i, line in enumerate(lines):
#         output.append(" | ".join([str(field).ljust(w) for w, field in zip(widths, line)]))
#         if i == 0 and header:
#             output.append("-"*len(output[0]))
#     return "\n".join(output)
# 
# def replace_cr(s):
#     if not isinstance(s, str):
#         return s
#     return s.strip().replace('\r', '\n')
# 
# Path: giraffez/logging.py
# def run_once(f):
#     def wrapper(*args, **kwargs):
# def setup_logging():
#     def colorize(cls, color, s):
#     def blue(cls, s):
#     def green(cls, s):
#     def gray(cls, s):
#     def white(cls, s):
#     def disabled(cls, s):
#     def bold(cls, s):
#     def fail(cls, s):
# def highlight(s):
#     def __init__(self, fd=None, level=INFO):
#     def level(self):
#     def level(self, v):
#     def _write(self, args, level=None, console=False):
#     def write(self, *args, **kwargs):
#     def info(self, *args, **kwargs):
#     def verbose(self, *args, **kwargs):
#     def debug(self, *args, **kwargs):
#     def fatal(self, msg=""):
#     def __init__(self, fd=None, level=INFO):
#     def _write(self, args, level=None, console=True):
# CONSOLE_HEADER = "\033[95m"
# CONSOLE_BLUE = "\033[94m"
# CONSOLE_GREEN = "\033[92m"
# CONSOLE_GRAY = "\033[37m"
# CONSOLE_WHITE = "\033[97m"
# CONSOLE_WARNING = "\033[93m"
# CONSOLE_ENDC = "\033[0m"
# CONSOLE_FAIL = "\033[91m"
# CONSOLE_BOLD = "\033[1m"
# CONSOLE_UNDERLINE = "\033[4m" 
# CONSOLE_DISABLED = "\033[38;5;240m" 
# class colors(object):
# class Logger(object):
# class LockingLogger(Logger):
# 
# Path: giraffez/utils.py
# def get_version_info():
#     from giraffez.__init__ import __title__, __version__
#     return __title__, __version__
# 
# def timer(f):
#     @functools.wraps(f)
#     def wrapper(*args, **kwds):
#         start = time.time()
#         result = f(*args, **kwds)
#         elapsed = time.time() - start
#         sys.stderr.write("{} took {:.4f}s to finish\n".format(f.__name__, elapsed))
#         return result
#     return wrapper


# Path: giraffez/shell.py
import cmd as _cmd
import os
import sys
import time
import atexit
import itertools
import functools
import threading
    import os
    import readline
        import readline
from .constants import *
from .errors import *
from ._teradata import TeradataError
from .fmt import format_table, replace_cr
from .logging import log, setup_logging
from .utils import get_version_info, timer

            ec = sum([line.count(c) for c in self.end_chars])
            if sc != ec:
                while True:
                    q = input("       > ")
                    if not q:
                        break
                    line += q
                    sc = sum([line.count(c) for c in self.start_chars])
                    ec = sum([line.count(c) for c in self.end_chars])
                    if sc == ec:
                        break
        except KeyboardInterrupt:
            sys.stderr.write("\n")
            return
        try:
            result = self.command(line)
        except TeradataError as error:
            log.write("{0!r}".format(error))
            return
        if not result:
            log.write("No results")
            return
        if self.table_output and not (line.lower().startswith("show") or line.lower().startswith("help")):
            log.write()
            rows = [replace_cr(row) for row in result]
            rows.insert(0, result.columns.names)
            sys.stdout.write(format_table(rows))
            sys.stdout.write("\n")
        else:
            for row in result:

                log.write("\t".join([str(replace_cr(x)) for x in row]))