# Path: ipodio/console.py
# class Console(object):
#     _width = None
# 
#     def _get_console_size(self):
#         return (self._get_window_size(sys.stdin)
#                 or self._get_window_size(sys.stdout)
#                 or self._get_window_size(sys.stderr)
#                 or self._get_term_window_size()
#                 or (25, 80))
# 
#     def _get_term_window_size(self):
#         try:
#             with os.open(os.ctermid(), os.O_RDONLY) as term:
#                 return self._get_window_size(term)
#         except:
#             return None
# 
#     def _get_window_size(self, fd):
#         try:
#             data = fcntl.ioctl(fd, termios.TIOCGWINSZ, '0' * 8)
#             height, width, hp, wp = struct.unpack('HHHH', data)
#             return height, width
#         except:
#             return None
# 
#     @property
#     def width(self):
#         if self._width is None:
#             _, self._width = self._get_console_size()
#         return self._width
# 
#     def relative_width(self, percentage):
#         """Return the width of a part of the screen in number of characters"""
#         return int((self.width - 4) * percentage)


import fcntl
import struct
import termios
from contextlib import contextmanager
from expects import expect
from mamba import describe, context, before
from ipodio.console import Console
## -*- coding: utf-8 -*-




class IoctlMock(object):
    fail = False
    _data = (20, 70, 0, 0)  # h w x x

    def monkey_patch(self):
        fcntl.ioctl = self

    @property
    @contextmanager
    def failing(self):
        self.fail = True

# Path: ipodio/console.py
# class Console(object):
#     _width = None
# 
#     def _get_console_size(self):
#         return (self._get_window_size(sys.stdin)
#                 or self._get_window_size(sys.stdout)
#                 or self._get_window_size(sys.stderr)
#                 or self._get_term_window_size()
#                 or (25, 80))
# 
#     def _get_term_window_size(self):
#         try:
#             with os.open(os.ctermid(), os.O_RDONLY) as term:
#                 return self._get_window_size(term)
#         except:
#             return None
# 
#     def _get_window_size(self, fd):
#         try:
#             data = fcntl.ioctl(fd, termios.TIOCGWINSZ, '0' * 8)
#             height, width, hp, wp = struct.unpack('HHHH', data)
#             return height, width
#         except:
#             return None
# 
#     @property
#     def width(self):
#         if self._width is None:
#             _, self._width = self._get_console_size()
#         return self._width
# 
#     def relative_width(self, percentage):
#         """Return the width of a part of the screen in number of characters"""
#         return int((self.width - 4) * percentage)


# Path: spec/unit/console_spec.py
import fcntl
import struct
import termios
from contextlib import contextmanager
from expects import expect
from mamba import describe, context, before
from ipodio.console import Console

## -*- coding: utf-8 -*-




class IoctlMock(object):
    fail = False
    _data = (20, 70, 0, 0)  # h w x x

    def monkey_patch(self):
        fcntl.ioctl = self

    @property
    @contextmanager
    def failing(self):
        self.fail = True

        yield