# Path: opennode/oms/util.py
# def exception_logger(fun):
#     @functools.wraps(fun)
#     def wrapper(*args, **kwargs):
#         try:
#             res = fun(*args, **kwargs)
#             if isinstance(res, defer.Deferred):
#                 @res
#                 def on_error(failure):
#                     log.msg("Got unhandled exception: %s" % failure.getErrorMessage(), system='debug')
#                     if get_config().getboolean('debug', 'print_exceptions'):
#                         log.err(failure, system='debug')
#             return res
#         except Exception:
#             if get_config().getboolean('debug', 'print_exceptions'):
#                 log.err(system='debug')
#             raise
#     return wrapper
# 
# def find_nth(haystack, needle, n, start_boundary=None):
#     start = haystack.find(needle, start_boundary)
#     while start >= 0 and n > 1:
#         start = haystack.find(needle, start + len(needle))
#         n -= 1
#     return start
# 
# Path: opennode/oms/endpoint/ssh/terminal.py
# CTRL_A = '\x01'
# 
# CTRL_C = '\x03'
# 
# CTRL_E = '\x05'
# 
# CTRL_K = '\x0b'
# 
# CTRL_X = '\x18'
# 
# CTRL_Y = '\x19'
# 
# CTRL_S = '\x13'
# 
# CTRL_G = '\x07'
# 
# CTRL_L = '\x0c'
# 
# CTRL_W = '\x17'
# 
# DARK_RED = '\x1b[0;31m'
# 
# RESET_COLOR = '\x1b[0m'


import os
        import string
from contextlib import closing
from copy import copy
from twisted.internet import defer
from twisted.conch.insults import insults
from twisted.python import log
from opennode.oms.util import exception_logger, find_nth
from opennode.oms.endpoint.ssh.terminal import CTRL_A, CTRL_C, CTRL_E, CTRL_K, CTRL_X, CTRL_Y, CTRL_S, CTRL_G, CTRL_L, CTRL_W, DARK_RED, RESET_COLOR

                self.write(self.buffer[self.pos:self.eol_pos()])

                if scroll_region:
                    self.reset_scrolling_region()
                self.terminal.restoreCursor()

                self.terminal.cursorPosition(0, current_screen_line + 1)
            else:
                self.terminal.saveCursor()
                self.terminal.index()
                self.write(self.buffer[self.pos:self.eol_pos()])
                self.terminal.restoreCursor()

            self.lines += 1
            self.current_line += 1
            self.current_column = 0
            self.terminal.cursorPos.y += 1
            self.terminal.cursorPos.y = min(self.terminal.cursorPos.y, self.terminal.termSize.y - 1)
        else:
            self.current_column += 1

            highlight = '#' in self.buffer[self.bol_pos():self.pos]

            if highlight:
                self.terminal.write(self.COMMENT_COLOR)

            self.terminal.write(ch)

            if highlight:

# Path: opennode/oms/util.py
# def exception_logger(fun):
#     @functools.wraps(fun)
#     def wrapper(*args, **kwargs):
#         try:
#             res = fun(*args, **kwargs)
#             if isinstance(res, defer.Deferred):
#                 @res
#                 def on_error(failure):
#                     log.msg("Got unhandled exception: %s" % failure.getErrorMessage(), system='debug')
#                     if get_config().getboolean('debug', 'print_exceptions'):
#                         log.err(failure, system='debug')
#             return res
#         except Exception:
#             if get_config().getboolean('debug', 'print_exceptions'):
#                 log.err(system='debug')
#             raise
#     return wrapper
# 
# def find_nth(haystack, needle, n, start_boundary=None):
#     start = haystack.find(needle, start_boundary)
#     while start >= 0 and n > 1:
#         start = haystack.find(needle, start + len(needle))
#         n -= 1
#     return start
# 
# Path: opennode/oms/endpoint/ssh/terminal.py
# CTRL_A = '\x01'
# 
# CTRL_C = '\x03'
# 
# CTRL_E = '\x05'
# 
# CTRL_K = '\x0b'
# 
# CTRL_X = '\x18'
# 
# CTRL_Y = '\x19'
# 
# CTRL_S = '\x13'
# 
# CTRL_G = '\x07'
# 
# CTRL_L = '\x0c'
# 
# CTRL_W = '\x17'
# 
# DARK_RED = '\x1b[0;31m'
# 
# RESET_COLOR = '\x1b[0m'


# Path: opennode/oms/endpoint/ssh/editor.py
import os
        import string
from contextlib import closing
from copy import copy
from twisted.internet import defer
from twisted.conch.insults import insults
from twisted.python import log
from opennode.oms.util import exception_logger, find_nth
from opennode.oms.endpoint.ssh.terminal import CTRL_A, CTRL_C, CTRL_E, CTRL_K, CTRL_X, CTRL_Y, CTRL_S, CTRL_G, CTRL_L, CTRL_W, DARK_RED, RESET_COLOR


                self.write(self.buffer[self.pos:self.eol_pos()])

                if scroll_region:
                    self.reset_scrolling_region()
                self.terminal.restoreCursor()

                self.terminal.cursorPosition(0, current_screen_line + 1)
            else:
                self.terminal.saveCursor()
                self.terminal.index()
                self.write(self.buffer[self.pos:self.eol_pos()])
                self.terminal.restoreCursor()

            self.lines += 1
            self.current_line += 1
            self.current_column = 0
            self.terminal.cursorPos.y += 1
            self.terminal.cursorPos.y = min(self.terminal.cursorPos.y, self.terminal.termSize.y - 1)
        else:
            self.current_column += 1

            highlight = '#' in self.buffer[self.bol_pos():self.pos]

            if highlight:
                self.terminal.write(self.COMMENT_COLOR)

            self.terminal.write(ch)

            if highlight:

                self.terminal.write(RESET_COLOR)