
    Dh                        d Z ddlmZ ddlZddlZddlZddlmZ ee	e	f   Z
ej                  e
   Zeeef   Zej                  e   Zd
dZddZddZdd	Zy)a  
This module provides functions to get the terminal size across different
platforms.

Functions:
    get_terminal_size: Get the current size of the terminal.
    _get_terminal_size_windows: Get terminal size on Windows.
    _get_terminal_size_tput: Get terminal size using `tput`.
    _get_terminal_size_linux: Get terminal size on Linux.

Usage example:
    >>> width, height = get_terminal_size()
    )annotationsN   )
convertersc                 |   t        j                  t              5  ddlm}   |        }ddlm} t        ||j                        r
	 ddd       y	 ddd       t        j                  t              5  ddl	}|j                         \  }}|r|r|dz
  |fcddd       S ddd       t        j                  t              5  t        j                  t        j                  j                  d            }t        j                  t        j                  j                  d            }|r|r||fcddd       S ddd       t        j                  t              5  ddl}|j#                         }|j$                  }|j&                  }|r|r||fcddd       S ddd       t        j                  t              5  t)               }|t+        |      r|cddd       S ddd       t        j                  t              5  t-               }|t+        |      r|cddd       S ddd       t        j                  t              5  t/               }|t+        |      r|cddd       S ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   PxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)	a[  Get the current size of your terminal.

    Multiple returns are not always a good idea, but in this case it greatly
    simplifies the code so I believe it's justified. It's not the prettiest
    function but that's never really possible with cross-platform code.

    Returns:
        width, height: Two integers containing width and height
    r   )get_ipython)zmqshellN)O      r   COLUMNSLINES)
contextlibsuppress	ExceptionIPythonr   	ipykernelr   
isinstanceZMQInteractiveShellshutilget_terminal_sizer   to_intosenvironget	blessingsTerminalwidthheight_get_terminal_size_linuxall_get_terminal_size_windows_get_terminal_size_tput)	r   ipythonr   r   whr   terminalwhs	            w/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/python_utils/terminal.pyr   r      sV    
		Y	' '-&gx;;<  = 
		Y	' 	 	'')1 q5!8	 	 	 
		Y	' bjjnnY78bjjnnW56a4	  
 
		Y	' %%'NNOOa4   
		Y	' %'>c"g	   
		Y	' ')>c"g	   
		Y	' $&>c"g	   e 	 	 
    sT   +I'0"I4=A,J4J3J7J&;J2'I14I>JJJ#&J/2J;c                 .   d } 	 ddl m}m} |j                  j	                  d      } |d      }|j                  j                  ||      } | r:dd l}|j                  d|j                        \  }}}}}}}}	}
}}|	|z
  }|
|z
  }||fS y # t        $ r Y y w xY w)Nr   )create_string_bufferwindlli   hhhhHhhhhhh)
ctypesr)   r*   kernel32GetStdHandleGetConsoleScreenBufferInfor   structunpackraw)resr)   r*   r$   csbir1   _lefttoprightbottomr#   s               r'   r    r    _   s    
C	
 OO((-#B'oo88DA :@--488;
7Aq!Qc5&!Q DLSL!t  s   AB 	BBc                    	 dd l } | j                  ddg| j                  | j                  | j                        }|j                  d       }t	        |d         }| j                  ddg| j                  | j                  | j                        }|j                  d       }t	        |d         }||fS # t
        $ r Y y w xY w)Nr   tputcols)stdinstdoutstderr)inputlines)
subprocessPopenPIPEcommunicateintr   )rC   procoutputr#   r$   s        r'   r!   r!   ~   s    V//????	   
 !!!-q	NW//????	   
 !!!-q	N !t  s   B.B4 4	C ?C c                    dd}  | d      xs  | d      xs  | d      }|sut        j                  t              5  t        j                  t        j
                         t        j                        } | |      }t        j                  |       d d d        |s'	 t        j                  d   t        j                  d   f}t        |d         t        |d         fS # 1 sw Y   NxY w# t        $ r Y y w xY w)Nc                    	 dd l }dd l}dd l}t        j                  t
        |j                  d|j                  | |j                  d                  S # t        $ r Y y w xY w)Nr   hh1234)
fcntlr1   termiostypingcast_OptionalStrDimensionsr2   ioctl
TIOCGWINSZr   )fdrN   r1   rO   s       r'   ioctl_gwinszz._get_terminal_size_linux.<locals>.ioctl_gwinsz   s]    	;;&KKG$6$6?   		s   AA 	AAr   r      r   r   )rU   rG   returnztuple[str, str] | None)
r   r   r   r   openctermidO_RDONLYcloser   rG   )rV   sizerU   s      r'   r   r      s    " ?@l1o@aD  + 	r{{3B#DHHRL	 	::g&

9(==D tAw<T!W%%	 	  		s   AC&C) C&)	C54C5)rX   
Dimensions)rX   OptionalDimensions)__doc__
__future__r   r   r   rP    r   tuplerG   r^   Optionalr_   str_StrDimensionsrR   r   r    r!   r        r'   <module>ri      sh    #  	  38_
__Z0 sCx8 ?D>6&rh   