+
    yj(                         R t ^ RIt^ RIt^ RIt^ RIt^ RItR tR tRsR.t	Rt
Rw
  ttttttttttRtRtRt ! R R	4      tR
RR^ RRRRRRR^ /tRR ltR tR tR# )u6  sshj.term — raw-ANSI terminal mechanics (leaf).

B2 step 2e: moved verbatim from sshj_cli.py (single-file era) — no
behavior change. Owns the DSR cursor query, the Term raw-mode
wrapper, the ANCHOR viewport state, and the key constants. Reads no
theme channels (ms_color lives with the channels it reads).
Nc                  d     \         P                  P                  4       #   \         d     R # i ; i)F)sysstdoutisatty	Exception     src/sshj/term.py_stdout_is_ttyr
      s,    zz  "" s     //c                 r   \         f    \        P                  P                  4       '       d   \        P                  s \         # \        P
                  ! \        P                  ! R\        P                  4      R^R7      s  \         # \         #   \        \        3 d    \        P                  s  \         # i ; i)az  The UI's output stream: ALWAYS the real terminal. When stdout is
captured (the .bashrc wrapper runs sshj inside $(...)), the grid must
paint to /dev/tty so the insert command can travel out through the
stdout PIPE (the fzf pattern: UI on the terminal, result on stdout).
Cached so the DSR query and the paint share one stream. Falls back to
stdout where /dev/tty is unavailable.z/dev/ttyw)	buffering)
_TTY_OUTr   r   r   osfdopenopenO_WRONLYOSErrorr   r   r   r	   _ui_outr      s     	"zz  "":: O	 99RWWZ%E%(A7 O8O # 	"zzHO	"s   #B B <B !B65B6z[rightleftzctrl+c                   L   a  ] tR t^>t o RtR tR tR tR tR
R lt	R t
RtV tR	# )TermzPRaw-mode TTY handle: cbreak input, real-terminal output, cursor + erase helpers.c                    \         P                  P                  4       V n        \	        4       V n        V P
                  P                  4       V n        R V n        ^ ;V n        V n	        R # N)
r   stdinfilenofdr   outtty_fdold
last_lines	last_colsselfs   &r	   __init__Term.__init__@   sF    ))""$9hhoo'+,,$.r   c                   ^ RI p^ RIp\        P                  ! V P                  4      V n        VP                  V P                  4        \        P                  ! V P                  \        P                  4       T P                  4        T P                  R4       R#   \         df     TP                  T P                  .. . R4      ^ ,          '       d$   \        P                  ! T P                  R4       KO   L  \         d      Li ; ii ; i)    Ng           z[?1006h)ttyselecttermios	tcgetattrr   r    	setcbreaktcflushTCIFLUSHr   r   readsizeput)r$   r*   r+   s   &  r	   enter
Term.enterG   s    $$TWW-dgg	OODGGW%5%56 			 	  	mmTWWIr2s;A>>GGDGGS) ? 		s0   
/B D(+C9#C99DDDDc                     V P                  R 4       \        P                  ! V P                  \        P                  V P
                  4       R#   \         d     R# i ; i)z[?1006lN)r3   r,   	tcsetattrr   	TCSADRAINr    r   r#   s   &r	   leave
Term.leave_   sE    	HH]#dggw'8'8$((C 		s   AA AAc                   ^ RI p^ RIp VP                  V P                  \        P
                  R4      pVP                  RVR,          4      w  rEV^ 8:  g   V^ 8:  d   \        h YEuT n        T n        YE3#   \         dF     \        P                  ! 4       pTP                  TP                  rT LK  \         d    ^^PrT  L\i ; ii ; i)r(   Nhh:N   Ns           )fcntlstructioctlr   r,   
TIOCGWINSZunpack
ValueErrorr   r   get_terminal_sizelinescolumnsr   r!   r"   )r$   r>   r?   packedrE   colsss   &      r	   r2   	Term.sizef   s    
	%[[g.@.@)LF --fRj9KEzTQY   ' +0'{  	%%((*ggqyyt % "t%		%s*   AA6 6C,B00C>CCCc                   ^ RI pVP                  V P                  .. . V4      ^ ,          '       d#   \        P                  ! V P                  ^4      pMR# V'       g   R# V^ ,          pV^8w  d   VR9   d   \        # VR9   d   \
        # V^	8X  d   \        # V^8X  d   \        h^Tu;8:  d   ^ 8  d?   M M;\        \        \        R4      V,           ^,
          4      P                  4       ,           # ^ Tu;8:  d   ^8  d   M R# \        V4      # R# \        ^.4      p\        ^4       FY  pVP                  V P                  .. . R4      ^ ,          '       d+   V\        P                  ! V P                  ^4      ,          pKY   M	  \        V4      p\        V4      ^8  d   VR,          R9   d   VP!                  R4      '       gX   VP                  V P                  .. . R4      ^ ,          '       d+   V\        P                  ! V P                  ^4      ,          pKm   \"        P$                  ! RV4      pV'       d   VP'                  ^4      R8X  d   \(        # V'       d   VP'                  ^4      R8X  d   \*        # R# \        V4      ^8  d   V^,          VR,          rV	\        R	4      \        R
4      39   d   V
\        R4      8X  d   \(        # V
\        R4      8X  d   \*        # V
\        R4      8X  d   \,        # V
\        R4      8X  d   \.        # V
\        R4      8X  d   \0        # V
\        R4      8X  d   \2        # V	\        R	4      8X  d;   V
\        R4      8X  d   VR8X  d   \4        # V
\        R4      8X  d   VR8X  d   \6        # \8        # )r(   NagMbP?:      Ng{Gz?s   \x1b\[<?(\d+)s   64s   65[OABCDFH5s   [5~6s   [6~)
      )      )s   [<s   [?)   M   m   ~)r+   r   r   r1   K_ENTERK_BSK_TABKeyboardInterruptK_CTRLchrordupper	bytearrayrangebyteslenendswithrematchgroupK_UPK_DOWNK_RIGHTK_LEFTK_ENDK_HOMEK_PGUPK_PGDNK_ESC)r$   timeoutr+   bcseq_rI   mintrolasts   &&         r	   read_keyTerm.read_keyv   s   ==$''BG4Q77#AaD7H}H}AvAv''A{{CHqL1$4 5 ; ; ===Q}} 1v oqA}}dggYB6q99rwwtww**	 
 #J
 q6Q;1S6^3jj!344==$''BD9!<<!,,A*A.AQWWQZ5(QWWQZ5(q6Q;A$"4S3s8,,3s8#K3s8#!M3s8#"N3s8#!M3s8# L3s8#!MCH$s3x'AO%s3x'AO%r   c                    \        V R R4      pVf   \        4       ;q n        VP                  V4       VP	                  4        R# )r   N)getattrr   r   writeflush)r$   rI   r   s   && r	   r3   Term.put   s5    dE4(;$Y&C(		!		r   )r   r"   r!   r    r   r   N)g?)__name__
__module____qualname____firstlineno____doc__r%   r4   r9   r2   r   r3   __static_attributes____classdictcell__)__classdict__s   @r	   r   r   >   s-     Z- 0 KZ r   r   rowcolcapturedFtopkscrolledc                8    ^ RI p^ RIp\        P                  P	                  4       p\
        P                  ! V4      '       g   R# \        P                  ! V4      p VP                  V4       \        4       pVP                  R4       VP                  4        Rp\        P                  ! 4       V ,           p\        P                  ! 4       V8  d_   VP                  V.. . R4      w  p p	V'       g   K=  \
        P                  ! V^4      p
V
'       g   MWj,          pV
R8X  g   Kn  RV9   g   Kw   \        P                   ! RV4      pV'       di   \#        VP%                  ^4      4      ^,
          \#        VP%                  ^4      4      ^,
          3\        P&                  ! V\        P(                  V4       #  \        P&                  ! V\        P(                  V4       R#   \        P&                  ! T\        P(                  T4       i ; i  \*         d     R# i ; i)u   Ask the terminal for the cursor position (DSR). 0-based (row, col) or None.
The DSR byte goes to the SAME stream the UI paints to (Term.out) — when
stdout is captured by the .bashrc wrapper, that is /dev/tty.Nz[6nr   g?   Rs   [s   \[(\d+);(\d+)R)r*   r+   r   r   r   r   r   r,   r-   r.   r   r   r   timer1   rn   searchintrp   r7   r8   r   )rz   r*   r+   r   r    r   dataendrr~   r{   r   s   &           r	   query_cursorr      s   YYyy}}#	:MM")CIIi IIKD))+'C))+# --b"d;1aGGBN	9T!1		,d3A1771:*C
Oa,??b'"3"3S9  b'"3"3S9  b'"3"3S9 sV   AH
 H
 BG 2 G G %G .G AG &H
 7&H
 (HH
 
HHc                     \         R,          '       g1   \        4       p V '       d   V w  \         R&   \         R&   R\         R&   R# R# )zEOne-shot DSR query of the writing line (or leave it bottom-anchored).r   r   r   TN)ANCHORr   )poss    r	   capture_anchorr      s8    *n+.(F5M6%=!z r   c           	     H   RP                  R V RP                  R W3 4       4      3 4       4      RP                  R W3 4       4      V3pV F!  pV'       g   K  \        V4      V8:  g   K  Vu # 	  V'       d(   V^8  d   RV\        ^V^,
          4      ) R ,           # R# R# )	ut  Pick the longest identity tier that fits `avail` cols:
`lan · ts name` -> `ts name` -> `name` (ts and name space-joined, matching
Identity.display). Drop a WHOLE tier rather than clipping a partial IP (a
dangling `…42.66` reads like a broken value). If even the name doesn't
fit, keep its tail (the only part a user can act on). Returns "" when
nothing meaningful fits.u    · c              3   8   "   T F  q'       g   K  Vx  K  	  R # 5ir   r   .0ps   & r	   	<genexpr>)_identity_display_tier.<locals>.<genexpr>  s     PJ!aAAJ   	
 c              3   8   "   T F  q'       g   K  Vx  K  	  R # 5ir   r   r   s   & r	   r   r     s     -IAqaar   c              3   8   "   T F  q'       g   K  Vx  K  	  R # 5ir   r   r   s   & r	   r   r     s     ,Jq!Jr   u   …N )joinrl   max)lantsnameavailtiersrI   s   &&&&  r	   _identity_display_tierr     s     	PSXX-I"-I%IJPP,RJ,,E
 1Q5H  49QJutSEAI../00FBFr   )
updownpguppgdnhomer   r4   bsesctab)g      ?)r   r   rn   r   r,   r   r
   r   r   _GRID_BOTTOM_ROWCSIrq   rr   rw   rx   rv   ru   ra   rb   ry   rc   rs   rt   re   r   r   r   r   r   r   r   r	   <module>r      s    
 	 
  (  6 LN HffffeWdE5
		J Jj uaUE4
tZ
$#L"r   