
    Mf(                         d dl mZ d dlZddlmZmZmZ  ej        d          Z ej         ed                    Z	da
g dad Zd Zd	 Zd
 Zd Zd Zd ZddZd Zd Zd Zd Zd Zedk    r e             dS dS )    )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                 P    | dk    s| dk    rdS t           D ]\  }}| |k    r|c S dS )z5Return the screen column width for unicode ordinal o.      r   r   )widths)onumwids      R/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/screen/old_str_util.py	get_widthr   R   sI     	Cxx188q  S88JJJ 1    c                    t          | t                    s
J |             t          | |                   }|dz  s||dz   fS t          d          |dz   f}t	          |           |z
  }|dk     r|S |dz  dk    r@t          | |dz                      }|dz  dk    r|S |dz  dz  |d	z  z  }|dk     r|S ||dz   fS |d
k     r|S |dz  dk    rlt          | |dz                      }|dz  dk    r|S t          | |dz                      }|dz  dk    r|S |dz  dz  |d	z  dz  z  |d	z  z  }|dk     r|S ||d
z   fS |dk     r|S |dz  dk    rt          | |dz                      }|dz  dk    r|S t          | |dz                      }|dz  dk    r|S t          | |dz                      }|dz  dk    r|S |dz  dz  |d	z  dz  z  |d	z  dz  z  |d	z  z  }|dk     r|S ||dz   fS |S )zH
    Return (ordinal at pos, next position) for UTF-8 encoded text.
       r   ?r
               ?         r      i               i   )
isinstancer   r   ordlen)	textposb1errorltb2r   b3b4s	            r   
decode_oner/   ]   s    dE""((D(((	d3iB9 37{HHcAgE	TSB	Avv	DyD$sQw-  9L4iA"t),t88L#'z	Avv	DyD$sQw-  9L$sQw-  9L4iBBI!#34T	Bu99L#'z	Avv	DyD$sQw-  9L$sQw-  9L$sQw-  9L4iBBI"#45"t)9IJbSWiXw;;L#'zLr   c                 6    t          | |                   |dz   fS )z7
    decode_one implementation for unicode strings
    r   )r%   )r'   is     r   decode_one_unir2      s     tAw<<Qr   c                    t          | t                    s
J |             t          d          |dz
  f}|}|dk    rNt          | |                   dz  dk    rt	          | |          \  }}||dz
  fS |dz  }||dz
  k    r|S |dk    LdS 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*   pr   nexts         r   decode_one_rightr6      s    
 dE""((D(((HHcAgEA
q&&Q==44'' q))GAta!e8O	QA::L q&&&&&&r   c                     | dv sJ | a d S )N)utf8narrowwide_byte_encoding)encs    r   set_byte_encodingr>      s    ,,,,,NNNr   c                      t           S )Nr;    r   r   get_byte_encodingrA      s    r   c                 F   ||k    sJ t          ||f                      t          | t                    o
t          dk    }t          | t                     }|s|r\t          t
          g|         }|}d}d}	||k     r8 || |          \  }
}	t          |
          }||z   |k    r||fS |	}||z  }||k     8||fS t          |           t          k    sJ t          |                       ||z   }||k    r|||z
  fS t          dk    rt          | ||          dk    r|dz  }|||z
  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).
    r8   r   r   r:   r
   )	reprr$   r   r<   r/   r2   r   typewithin_double_byte)r'   
start_offsend_offspref_colutfsunisdecoder1   scnr   ws               r   calc_text_posrO      sg    !!!4X(>#?#?!!!dE""?~'?D$&&&D t n-d3(ll6$??DAq!A2v  "uA!GB (ll "u::T

XAH}}J...dJ22a77FAa*nr   c                    t          |           }|dk    s|dk    s||k    r|}||k    sJ t          ||f                      t          | t                    o
t          dk    }t          | t                     }|rt
                              |           r|rgt                              |           sMt          t          g|         }|}d}d}	||k     r+ || |          \  }
}	t          |
          }|	}||z  }||k     +|S ||z
  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   r8   r   )r&   rC   r$   r   r<   SAFE_ASCII_REmatchSAFE_ASCII_BYTES_REr/   r2   r   )r'   rF   rG   r+   rI   rJ   rK   r1   rL   rM   r   rN   s               r   
calc_widthrU      s)    
TBA8r>>x"}}!!!4X(>#?#?!!!dE""?~'?D$&&&D 
]((.. 
D 
ATAZAZ[_A`A` 
n-d3(ll6$??DAq!AA!GB	 (ll
 	j  r   c                 P   t          | t                    r(t          | |                   }t          |          dk    S t          | t                    sJ t
          dk    r&t          | |          \  }}t          |          dk    S t
          dk    rt          | ||          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
   r8   r:   r   F)r$   unicoder%   r   r   r<   r/   rE   )r'   offsr   rM   s       r   is_wide_charrY      s     $   !T
OO||q  dE"""""$%%1||q  !$d33q885r   c                 l   ||k     sJ t          | t                    r|dz
  S t          | t                    sJ t          dk    rD|dz
  }t	          | |                   dz  dk    r!|dz  }t	          | |                   dz  dk    !|S t          dk    rt          | ||dz
            dk    r|dz
  S |dz
  S )z?
    Return the position of the character before end_offs.
    r   r8   r   r   r:   r
   r$   rW   r   r<   r   rE   r'   rF   rG   r   s       r   move_prev_charr]     s         $   !|dE"""""qL47mmd"d**FA 47mmd"d**$6tZTU$V$VZ[$[$[!|a<r   c                 ~   ||k     sJ t          | t                    r|dz   S t          | t                    sJ t          dk    rP|dz   }||k     rCt	          | |                   dz  dk    r'|dz  }||k     rt	          | |                   dz  dk    '|S t          dk    rt          | ||          dk    r|dz   S |dz   S )z@
    Return the position of the character after start_offs.
    r   r8   r   r   r:   r
   r[   r\   s       r   move_next_charr_     s         $   A~dE"""""N(lltDG}}t3t;;FA (lltDG}}t3t;;$6tZ$T$TXY$Y$YA~>r   c                    t          | t                    sJ t          | |                   }d|cxk    rdk     rCn n@||k    rdS t          | |dz
                     dk    rt          | ||dz
            dk    rdS dS |dk     rdS |dz
  }||k    r%t          | |                   dk     rn|dz  }||k    %||z
  dz  rd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   rE   )r'   
line_startr(   vr1   s        r   rE   rE   1  s    dE"""""T#YAq4*1S1W$&&!$
C!G<<AAqq4xxqaA
z//Q==4	Q z//
 	a1} q1r   c                     dd l } g }d }| j                                        D ]}|d d         dk    r|                                }|                    dd          \  }}|                    dd          \  }}|                    dd          d         }d|v r|                    d          d         }t          |d	          }|d
v rd}	n	|dv rd}	nd}	||                    d|	f           |	}||	k    r||	f|d<   |                    ||	f           |	}t          d           |dd          D ]}
t          d|
d           t          d           d S )Nr   r   #;z #  .z..   )	COMBININGMODIFIERz	<control>)WFr
   rQ   z
widths = [	,])sysstdin	readlinesstripsplitintappendprint)rs   outlastlinehexrestr   word1r   lr   s              r   process_east_asian_widthr   Z  s   JJJ
CD	##%%  8s??zz||JJsA&&	TJJua((	T

3""1%#::))D//!$C#rll:::AAJAAA<JJ1vD199AhCGGJJQx   DD	,W  n	#JJJJJr   __main__)r   r   )
__future__r   recompatr   r   r   compilerR   rT   r<   r   r   r/   r2   r6   r>   rA   rO   rU   rY   r]   r_   rE   r   __name__r@   r   r   <module>r      s{  , & % % % % % 				 " " " " " " " " " " 
;'' bj:// '
 '
 '
X  1 1 1h    "    " " "J !  !  !  !F  $  $  $$ $ $R$ $ $N z r   