# 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
        return struct.pack('HHHH', *self._data)


ioctl = IoctlMock()
ioctl.monkey_patch()



with describe(Console) as _:
    with context('when created'):
        def it_should_have_a_width_property():
            expect(_.console()).to.have.property('width')

    with context('when accesing width'):
        def it_should_return_system_console_width():
            expect(_.console().width).to.be(_.width)

    with context('when calling relative_width'):
        def it_should_return_the_proportional_size():
            relative_width = _.console().relative_width(0.8)

            expect(relative_width).to.be(_.relative_width_80)

    with context('when ioctl fails'):
        def it_should_return_default_values():
            with ioctl.failing:
                expect(_.console().width).to.be(_.default)

    @before.all
    def fixture():

# 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

        return struct.pack('HHHH', *self._data)


ioctl = IoctlMock()
ioctl.monkey_patch()



with describe(Console) as _:
    with context('when created'):
        def it_should_have_a_width_property():
            expect(_.console()).to.have.property('width')

    with context('when accesing width'):
        def it_should_return_system_console_width():
            expect(_.console().width).to.be(_.width)

    with context('when calling relative_width'):
        def it_should_return_the_proportional_size():
            relative_width = _.console().relative_width(0.8)

            expect(relative_width).to.be(_.relative_width_80)

    with context('when ioctl fails'):
        def it_should_return_default_values():
            with ioctl.failing:
                expect(_.console().width).to.be(_.default)

    @before.all
    def fixture():

        _.console = lambda: Console()