2424
2525from  . import  exc , formats 
2626from  .common  import  (
27+     AsyncTmuxCmd ,
2728    EnvironmentMixin ,
2829    PaneDict ,
2930    SessionDict ,
@@ -251,8 +252,12 @@ def cmd(
251252
252253        Output of `tmux -L ... new-window -P -F#{window_id}` to a `Window` object: 
253254
254-         >>> Window.from_window_id(window_id=session.cmd( 
255-         ... 'new-window', '-P', '-F#{window_id}').stdout[0], server=session.server) 
255+         >>> Window.from_window_id( 
256+         ...     window_id=session.cmd( 
257+         ...         'new-window', '-P', '-F#{window_id}' 
258+         ...     ).stdout[0], 
259+         ...     server=session.server, 
260+         ... ) 
256261        Window(@4 3:..., Session($1 libtmux_...)) 
257262
258263        Create a pane from a window: 
@@ -263,7 +268,9 @@ def cmd(
263268        Output of `tmux -L ... split-window -P -F#{pane_id}` to a `Pane` object: 
264269
265270        >>> Pane.from_pane_id(pane_id=window.cmd( 
266-         ... 'split-window', '-P', '-F#{pane_id}').stdout[0], server=window.server) 
271+         ...     'split-window', '-P', '-F#{pane_id}').stdout[0], 
272+         ...     server=window.server 
273+         ... ) 
267274        Pane(%... Window(@... ...:..., Session($1 libtmux_...))) 
268275
269276        Parameters 
@@ -301,6 +308,90 @@ def cmd(
301308
302309        return  tmux_cmd (* svr_args , * cmd_args )
303310
311+     async  def  acmd (
312+         self ,
313+         cmd : str ,
314+         * args : t .Any ,
315+         target : str  |  int  |  None  =  None ,
316+     ) ->  AsyncTmuxCmd :
317+         """Execute tmux command respective of socket name and file, return output. 
318+ 
319+         Examples 
320+         -------- 
321+         >>> import asyncio 
322+         >>> async def test_acmd(): 
323+         ...     result = await server.acmd('display-message', 'hi') 
324+         ...     print(result.stdout) 
325+         >>> asyncio.run(test_acmd()) 
326+         [] 
327+ 
328+         New session: 
329+ 
330+         >>> async def test_new_session(): 
331+         ...     result = await server.acmd( 
332+         ...         'new-session', '-d', '-P', '-F#{session_id}' 
333+         ...     ) 
334+         ...     print(result.stdout[0]) 
335+         >>> asyncio.run(test_new_session()) 
336+         $... 
337+ 
338+         Output of `tmux -L ... new-window -P -F#{window_id}` to a `Window` object: 
339+ 
340+         >>> async def test_new_window(): 
341+         ...     result = await session.acmd('new-window', '-P', '-F#{window_id}') 
342+         ...     window_id = result.stdout[0] 
343+         ...     window = Window.from_window_id(window_id=window_id, server=server) 
344+         ...     print(window) 
345+         >>> asyncio.run(test_new_window()) 
346+         Window(@... ...:..., Session($... libtmux_...)) 
347+ 
348+         Create a pane from a window: 
349+ 
350+         >>> async def test_split_window(): 
351+         ...     result = await server.acmd('split-window', '-P', '-F#{pane_id}') 
352+         ...     print(result.stdout[0]) 
353+         >>> asyncio.run(test_split_window()) 
354+         %... 
355+ 
356+         Output of `tmux -L ... split-window -P -F#{pane_id}` to a `Pane` object: 
357+ 
358+         >>> async def test_pane(): 
359+         ...     result = await window.acmd('split-window', '-P', '-F#{pane_id}') 
360+         ...     pane_id = result.stdout[0] 
361+         ...     pane = Pane.from_pane_id(pane_id=pane_id, server=server) 
362+         ...     print(pane) 
363+         >>> asyncio.run(test_pane()) 
364+         Pane(%... Window(@... ...:..., Session($1 libtmux_...))) 
365+ 
366+         Parameters 
367+         ---------- 
368+         target : str, optional 
369+             Optional custom target. 
370+ 
371+         Returns 
372+         ------- 
373+         :class:`common.AsyncTmuxCmd` 
374+         """ 
375+         svr_args : list [str  |  int ] =  [cmd ]
376+         cmd_args : list [str  |  int ] =  []
377+         if  self .socket_name :
378+             svr_args .insert (0 , f"-L{ self .socket_name }  " )
379+         if  self .socket_path :
380+             svr_args .insert (0 , f"-S{ self .socket_path }  " )
381+         if  self .config_file :
382+             svr_args .insert (0 , f"-f{ self .config_file }  " )
383+         if  self .colors :
384+             if  self .colors  ==  256 :
385+                 svr_args .insert (0 , "-2" )
386+             elif  self .colors  ==  88 :
387+                 svr_args .insert (0 , "-8" )
388+             else :
389+                 raise  exc .UnknownColorOption 
390+ 
391+         cmd_args  =  ["-t" , str (target ), * args ] if  target  is  not   None  else  [* args ]
392+ 
393+         return  await  AsyncTmuxCmd .run (* svr_args , * cmd_args )
394+ 
304395    @property  
305396    def  attached_sessions (self ) ->  list [Session ]:
306397        """Return active :class:`Session`s. 
0 commit comments