ó
šxŠ\c           @  sÁ   d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d g Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z e d k r½ e	 ƒ  \ Z Z e d j d e d e ƒ ƒ n  d S(   sk  
get_terminal_size() -- return width and height of terminal as a tuple

code from:
http://stackoverflow.com/questions/566746/how-to-get-console- window-width-in-
python

written by
Harco Kuppens (http://stackoverflow.com/users/825214/harco-kuppens)

It is mentioned in the stackoverflow response that this code works
on linux, os x, windows and cygwin (windows).
iÿÿÿÿ(   t   print_functionN(   t   PY3t   get_terminal_sizet   is_terminalc          C  sª   d d l  }  t r t j ƒ  S|  j ƒ  } d } | d k r^ t ƒ  } | d k r^ t ƒ  } q^ n  | d k s… | d k s… | j d ƒ r‘ t	 ƒ  } n  | d k r¦ d	 } n  | S(
   sÐ   
    Detect terminal size and return tuple = (width, height).

    Only to be used when running in a terminal. Note that the IPython notebook,
    IPython zmq frontends, or IDLE do not run in a terminal,
    iÿÿÿÿNt   Windowst   Linuxt   Darwint   CYGWINiP   i   (   iP   i   (
   t   platformR   t   shutilR   t   systemt   Nonet   _get_terminal_size_windowst   _get_terminal_size_tputt
   startswitht   _get_terminal_size_linux(   R   t
   current_ost   tuple_xy(    (    s9   lib/python2.7/site-packages/pandas/io/formats/terminal.pyR      s    
		c          C  s=   y t  ƒ  }  Wn t k
 r! t SXt |  d ƒ r5 t St Sd S(   sz   
    Detect if Python is running in a terminal.

    Returns True if Python is running in a terminal or False if not.
    t   kernelN(   t   get_ipythont	   NameErrort   Truet   hasattrt   False(   t   ip(    (    s9   lib/python2.7/site-packages/pandas/io/formats/terminal.pyR   4   s    c          C  sÞ   yM d d l  m }  m } |  j j d ƒ } | d ƒ } |  j j | | ƒ } Wn t t f k
 rg d  SX| rÖ d d  l	 } | j
 d | j ƒ \ } } } }	 }
 } } } } } } | | d } | | d } | | f Sd  Sd  S(   Niÿÿÿÿ(   t   windllt   create_string_bufferiôÿÿÿi   t   hhhhHhhhhhhi   (   t   ctypesR   R   t   kernel32t   GetStdHandlet   GetConsoleScreenBufferInfot   AttributeErrort
   ValueErrorR   t   structt   unpackt   raw(   R   R   t   ht   csbit   resR"   t   bufxt   bufyt   curxt   curyt   wattrt   leftt   topt   rightt   bottomt   maxxt   maxyt   sizext   sizey(    (    s9   lib/python2.7/site-packages/pandas/io/formats/terminal.pyR   E   s    6
c          C  sØ   yv t  j d d g d t  j d t  j ƒ}  |  j d d  ƒ } t  j d d g d t  j d t  j ƒ}  |  j d d  ƒ } Wn t k
 rŠ d  SXy. t | d ƒ } t | d ƒ } | | f SWn t t f k
 rÓ d  SXd  S(   Nt   tputt   colst   stdint   stdoutt   inputt   linesi    (	   t
   subprocesst   Popent   PIPEt   communicateR   t   OSErrort   intR!   t
   IndexError(   t   proct   output_colst   output_rowsR6   t   rows(    (    s9   lib/python2.7/site-packages/pandas/io/formats/terminal.pyR   ^   s"    		c          C  sù   d „  }  |  d ƒ p* |  d ƒ p* |  d ƒ } | s‚ y8 t  j t  j ƒ  t  j ƒ } |  | ƒ } t  j | ƒ Wq‚ t k
 r~ q‚ Xn  | s• | d	 k rÛ y( d d l  m } | d | d f } WqÛ t t f k
 r× d  SXn  t
 | d ƒ t
 | d ƒ f S(
   Nc         S  sn   yL d d  l  } d d  l } d d  l } | j d | j |  | j d ƒ ƒ } Wn | j t f k
 ri d  SX| S(   Niÿÿÿÿt   hht   1234(	   t   fcntlt   termiosR"   R#   t   ioctlt
   TIOCGWINSZt   errort   IOErrorR   (   t   fdRH   RI   R"   t   cr(    (    s9   lib/python2.7/site-packages/pandas/io/formats/terminal.pyt   ioctl_GWINSZ{   s    "i    i   i   iÿÿÿÿ(   t   environt   LINESt   COLUMNS(   i    i    (   t   ost   opent   ctermidt   O_RDONLYt   closeR?   RQ   R!   t   KeyErrorR   R@   (   RP   RO   RN   t   env(    (    s9   lib/python2.7/site-packages/pandas/io/formats/terminal.pyR   z   s     	
$t   __main__s   width = {w} height = {h}t   wR%   (   t   __doc__t
   __future__R    RT   R	   R;   t   pandas.compatR   t   __all__R   R   R   R   R   t   __name__R3   R4   t   printt   format(    (    (    s9   lib/python2.7/site-packages/pandas/io/formats/terminal.pyt   <module>   s   					