
    ^h`                     D   S r SSKrSSKrSSKJr  \R
                  R                  \R                  R                  S5      5      r	\R                  r\\	R                  l        \\	R                  l        \\	R                  l        \\/\	R                  l        \	R                  rS rS rS r\R
                  R                  \R                  R                  S5      5      r\R,                  r\\l        \\R.                  \R0                  \\/\l        \R2                  r\R.                  \l        \/\l        \R4                  rS\l        \\R6                  /\l        \R8                  r\\l        \\\/\l        \R:                  r\\l        \R<                  rS\l        \\\/\l        \R>                  rS\l        \/\l        \R@                  r S\ l        \/\ l        S	r!\RE                  \S
5      r#S r$S r%S r&\RN                  " S\\\5      r(\(" \&5      r)S r*S r+g)zBInputhook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
    N)Eventobjcc                 R    [        U [        5      (       d  U R                  S5      n U $ )zensure utf8 bytesutf8)
isinstancebytesencode)ss    \/home/james-whalen/.local/lib/python3.13/site-packages/IPython/terminal/pt_inputhooks/osx.py_utf8r      s"    aHHVH    c                 >    [         R                  [        U 5      5      $ )z)create a selector name (for ObjC methods))r   sel_registerNamer   )names    r   nr      s      t--r   c                 >    [         R                  [        U 5      5      $ )zget an ObjC Class by name)r   objc_getClassr   )	classnames    r   Cr   !   s    eI.//r   CoreFoundation   kCFRunLoopCommonModesc                  |    [         [         /[        R                  l        [	        [        S5      [        S5      5      $ )z0Return the global NSApplication instance (NSApp)NSApplicationsharedApplicationvoid_pr   objc_msgSendargtypesmsgr   r    r   r   _NSAppr"   N   s-    "(&!1Dq!1%8#9::r   c                 |   [         [         [         [         [         [         [         [         [         [         [         /[        R                  l        [	        [        S5      [        S5      SSSSSSSSS5      n[         [         [         [         /[        R                  l        [	        U [        S5      [        U5      S5        g)zWake the ApplicationNSEventz]otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:   r   NzpostEvent:atStart:Tr   )NSAppevents     r   _waker(   T   s     	"D 	)	B	
 								E  #)&&&!ADq%&ut<r   c                     [        U 5        [        U 5        [        5       n[        [        [        /[        R
                  l        [        U[        S5      U5        [        U5        g)z.Callback to fire when there's input to be readzstop:N)
CFFileDescriptorInvalidate	CFReleaser"   r   r   r   r   r    r   r(   )fdrefflagsinfor&   s       r   _input_callbackr/   w   sE    u%eHE"(&&!9Dqz5!	%Lr   c                     [        SU S[        S5      n[        U[        5        [	        SUS5      n[        5       n[        X2[        5        [        U5        g)z;Register callback to stop eventloop when there's data on fdNFr   )	CFFileDescriptorCreate_c_input_callbackCFFileDescriptorEnableCallBackskCFFileDescriptorReadCallBack#CFFileDescriptorCreateRunLoopSourceCFRunLoopGetCurrentCFRunLoopAddSourcer   r+   )fdr,   sourceloops       r   _stop_on_readr;      sI    "4U4EtLE#E+HI0ua@F Dt%:;fr   c                     [        5       n[        U R                  5       5        [        [        /[        R
                  l        [        U[        S5      5        g)zInputhook for Cocoa (NSApp)runN)	r"   r;   filenor   r   r   r   r    r   )contextr&   s     r   	inputhookr@      s9    HE'.."#"(&!1Dqxr   ),__doc__ctypesctypes.util	threadingr   cdllLoadLibraryutilfind_libraryr   c_void_pr   r   restyper   r   r   r    r   r   r   r   r1   c_intc_bool#CFFileDescriptorGetNativeDescriptorr3   c_ulongr5   r6   r7   r+   r*   r4   in_dllr   r"   r(   r/   	CFUNCTYPE_c_callback_func_typer2   r;   r@   r!   r   r   <module>rR      s/     {{v{{77?@	#    &   "   $f-   
.0 (()A)ABR)ST'>> !'  #)6<<PV"W  &4&X&X #.4ll # +06x # ,"0"P"P *.  ',2FNN+C  (&4&X&X #.4 # +06/G # ,$88 $  #66 !  %vv6  $$		 X	 +FF %)  "'-h  # !" n6MN ; =F ((vvvF )/: r   