B
    zW(              &   @   s  d dl mZ d dlZddlmZmZmZ edZeedZ	da
dddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+g&ad,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 ZdGd:d;Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZedFkre  dS )H    )print_functionN   )Bbytesord2z^[ -~]*$)~   r   )   r   )i  r   )i  r   )i  r   )i  r   )i  r   )io  r   )i  r   )i  r   )i  r   )i_     )i+  r   )ia  r   )i   r   )i   r   )i(#  r   )i*#  r	   )i+  r   )i>0  r	   )i?0  r   )i0  r	   )i0  r   )iM  r	   )iM  r   )i  r	   )i  r   )ij  r	   )i  r   )i#  r   )ik  r	   )i  r   )i`  r	   )i  r   )i  r	   )i r   )i r	   )i r   c             C   s6   | dks| dkrdS xt D ]\}}| |kr|S qW dS )z5Return the screen column width for unicode ordinal o.      r   r   )widths)onumwid r   E/var/www/html/venv/lib/python3.7/site-packages/screen/old_str_util.py	get_widthR   s    r   c       	      C   s  t | tst| t| | }|d@ s2||d fS td|d f}t| | }|dk rZ|S |d@ dkrt| |d  }|d@ dkr|S |d@ d> |d	@ B }|dk r|S ||d fS |d
k r|S |d@ dkrHt| |d  }|d@ dkr|S t| |d  }|d@ dkr|S |d@ d> |d	@ d> B |d	@ B }|dk r<|S ||d
 fS |dk rV|S |d@ dkrt| |d  }|d@ dkr|S t| |d  }|d@ dkr|S t| |d  }|d@ dkr|S |d@ d> |d	@ d> B |d	@ d> B |d	@ B }|dk r|S ||d fS |S )zH
    Return (ordinal at pos, next position) for UTF-8 encoded text.
       r   ?r	               ?         r      i               i   )
isinstancer   AssertionErrorr   ordlen)	textposZb1errorltZb2r   Zb3Zb4r   r   r   
decode_one]   s\     

,
r)   c             C   s   t | | |d fS )z7
    decode_one implementation for unicode strings
    r   )r#   )r%   ir   r   r   decode_one_uni   s    r+   c             C   s~   t | tst| td|d f}|}xR|dkrxt| | d@ dkr^t| |\}}||d fS |d8 }||d kr(|S q(W dS )z
    Return (ordinal at pos, next position) for UTF-8 encoded text.
    pos is assumed to be on the trailing byte of a utf-8 sequence.
    r   r   r   r   r   r   N)r!   r   r"   r#   r   r)   )r%   r&   r'   pr   nextr   r   r   decode_one_right   s    
r.   c             C   s   | dkst | ad S )N)utf8Znarrowwide)r"   _byte_encoding)encr   r   r   set_byte_encoding   s    r3   c               C   s   t S )N)r1   r   r   r   r   get_byte_encoding   s    r4   c             C   s  ||kst t||ft| to(tdk}t| t }|s>|rttg| }|}d}d}	xB||k r|| |\}
}	t|
}|| |kr||fS |	}||7 }qXW ||fS t| tkst t| || }||kr||| fS tdkrt	| ||dkr|d8 }||| fS )a9  
    Calculate the closest position to the screen column pref_col in text
    where start_offs is the offset into text assumed to be screen column 0
    and end_offs is the end of the range to search.

    text may be unicode or a byte string in the target _byte_encoding

    Returns (position, actual_col).
    r/   r   r   r0   r	   )
r"   reprr!   r   r1   r)   r+   r   typewithin_double_byte)r%   
start_offsend_offsZpref_colutfsunisdecoder*   scnr   wr   r   r   calc_text_pos   s0    

r@   c             C   s   t | }|dks |dks ||kr$|}||ks<tt||ft| toLtdk}t| t }|rht| rv|rt| st	t
g| }|}d}d}	x.||k r|| |\}
}	t|
}|	}||7 }qW |S || S )am  
    Return the screen column width of text between start_offs and end_offs.

    text may be unicode or a byte string in the target _byte_encoding

    Some characters are wide (take two columns) and others affect the
    previous character (take zero columns).  Use the widths table above
    to calculate the screen column width of text[start_offs:end_offs]
    r   r/   r   )r$   r"   r5   r!   r   r1   SAFE_ASCII_REmatchSAFE_ASCII_BYTES_REr)   r+   r   )r%   r8   r9   r(   r:   r;   r<   r*   r=   r>   r   r?   r   r   r   
calc_width   s$    
rE   c             C   sn   t | tr"t| | }t|dkS t | ts0ttdkrRt| |\}}t|dkS tdkrjt| ||dkS dS )z
    Test if the character at offs within text is wide.

    text may be unicode or a byte string in the target _byte_encoding
    r	   r/   r0   r   F)	r!   unicoder#   r   r   r"   r1   r)   r7   )r%   Zoffsr   r>   r   r   r   is_wide_char   s    
rG   c             C   s   ||k st t| tr|d S t| ts,t tdkrb|d }x t| | d@ dkr\|d8 }q>W |S tdkrt| ||d dkr|d S |d S )z?
    Return the position of the character before end_offs.
    r   r/   r   r   r0   r	   )r"   r!   rF   r   r1   r   r7   )r%   r8   r9   r   r   r   r   move_prev_char  s    
rH   c             C   s   ||k st t| tr|d S t| ts,t tdkrj|d }x(||k rdt| | d@ dkrd|d7 }q>W |S tdkrt| ||dkr|d S |d S )z@
    Return the position of the character after start_offs.
    r   r/   r   r   r0   r	   )r"   r!   rF   r   r1   r   r7   )r%   r8   r9   r   r   r   r   move_next_char  s    
rI   c             C   s   t | tstt| | }d|  kr.dk rnn n<||kr>dS t| |d  dkrjt| ||d dkrjdS dS |dk rzdS |d }x&||krt| | dk rP |d8 }qW || d@ rdS dS )aj  Return whether pos is within a double-byte encoded character.

    text -- byte string in question
    line_start -- offset of beginning of line (< pos)
    pos -- offset in question

    Return values:
    0 -- not within dbe char, or double_byte_encoding == False
    1 -- pos is on the 1st half of a dbe char
    2 -- pos is on the 2nd half of a dbe char
    @      r   r      r	   r   )r!   r   r"   r   r7   )r%   Z
line_startr&   vr*   r   r   r   r7   1  s&    
r7   c              C   s*  dd l } g }d }x| j D ]}|d d dkr2q| }|dd\}}|dd\}}|ddd }d|kr|dd }t|d	}|d
krd}	n|dkrd}	nd}	|d kr|d|	f |	}||	kr||	f|d< q|||	f |	}qW td x$|dd  D ]}
td|
f  qW td d S )Nr   r   #;z #  .z..   )Z	COMBININGZMODIFIERz	<control>)WFr	   rA   z
widths = [z	%r,])sysstdin	readlinesstripsplitintappendprint)rV   outlastlinehexrestr   Zword1r   lr   r   r   r   process_east_asian_widthZ  s:    
rd   __main__)r   r   )
__future__r   recompatr   r   r   compilerB   rD   r1   r   r   r)   r+   r.   r3   r4   r@   rE   rG   rH   rI   r7   rd   __name__r   r   r   r   <module>   st   
4%
#)'
