@@ -115,24 +115,35 @@ def kill_session(self):
115
115
raise exc .LibTmuxException (proc .stderr )
116
116
117
117
def switch_client (self ):
118
- """``$ tmux switch-client``.
118
+ """
119
+ Switch client to this session.
120
+
121
+ Raises
122
+ ------
119
123
120
- :param: target_session: str. note this accepts fnmatch(3).
121
- :raises: :exc:`exc.LibTmuxException`
124
+ :exc:`exc.LibTmuxException`
122
125
"""
123
126
proc = self .cmd ('switch-client' , '-t%s' % self .id )
124
127
125
128
if proc .stderr :
126
129
raise exc .LibTmuxException (proc .stderr )
127
130
128
131
def rename_session (self , new_name ):
129
- """Rename session and return new :class:`Session` object.
132
+ """
133
+ Rename session and return new :class:`Session` object.
130
134
131
- :param new_name: new session name
132
- :type new_name: str
133
- :raises: :exc:`exc.BadSessionName`
134
- :rtype: :class:`Session`
135
+ Parameters
136
+ ----------
137
+ new_name : str
138
+ new session name
135
139
140
+ Returns
141
+ -------
142
+ :class:`Session`
143
+
144
+ Raises
145
+ ------
146
+ :exc:`exc.BadSessionName`
136
147
"""
137
148
session_check_name (new_name )
138
149
@@ -153,33 +164,35 @@ def new_window(self,
153
164
attach = True ,
154
165
window_index = '' ,
155
166
window_shell = None ):
156
- """Return :class:`Window` from ``$ tmux new-window``.
167
+ """
168
+ Return :class:`Window` from ``$ tmux new-window``.
157
169
158
170
By default, this will make the window active. For the new window
159
171
to be created and not set to current, pass in ``attach=False``.
160
172
161
- :param window_name: window name.
162
- :type window_name: str
163
- :param start_directory: specifies the working directory in which the
164
- new window is created.
165
- :type start_directory: str
166
- :param attach: make new window the current window after creating it,
167
- default True.
168
- :param window_index: create the new window at the given index position.
169
- Default is empty string which will create the window in the next
170
- available position.
171
- :type window_index: str
172
- :param window_shell: execute a command on starting the window. The
173
- window will close when the command exits.
174
- NOTE: When this command exits the window will close. This feature
175
- is useful for long-running processes where the closing of the
176
- window upon completion is desired.
177
- :type window_command: str
178
- :param type: bool
179
- :rtype: :class:`Window`
180
-
173
+ Parameters
174
+ ----------
175
+ window_name : str, optional
176
+ start_directory : str, optional
177
+ working directory in which the new window is created.
178
+ attach : bool, optional
179
+ make new window the current window after creating it, default True.
180
+ window_index : str
181
+ create the new window at the given index position. Default is empty
182
+ string which will create the window in the next available position.
183
+ window_shell : str
184
+ execute a command on starting the window. The window will close
185
+ when the command exits.
186
+
187
+ .. note::
188
+ When this command exits the window will close. This feature is
189
+ useful for long-running processes where the closing of the
190
+ window upon completion is desired.
191
+
192
+ Returns
193
+ -------
194
+ :class:`Window`
181
195
"""
182
-
183
196
wformats = ['session_name' , 'session_id' ] + formats .WINDOW_FORMATS
184
197
tmux_formats = ['#{%s}' % f for f in wformats ]
185
198
@@ -229,14 +242,15 @@ def new_window(self,
229
242
return window
230
243
231
244
def kill_window (self , target_window = None ):
232
- """``$ tmux kill-window``.
245
+ """Close a tmux window, and all panes inside it, ``$ tmux kill-window``
233
246
234
247
Kill the current window or the window at ``target-window``. removing it
235
248
from any sessions to which it is linked.
236
249
237
- :param target_window: the ``target window``.
238
- :type target_window: str
239
-
250
+ Parameters
251
+ ----------
252
+ target_window : str, optional
253
+ window to kill
240
254
"""
241
255
242
256
if target_window :
@@ -270,8 +284,9 @@ def _windows(self):
270
284
def list_windows (self ):
271
285
"""Return a list of :class:`Window` from the ``tmux(1)`` session.
272
286
273
- :rtype: :class:`Window`
274
-
287
+ Returns
288
+ -------
289
+ :class:`Window`
275
290
"""
276
291
windows = [
277
292
w for w in self ._windows if w ['session_id' ] == self ._session_id
@@ -289,10 +304,12 @@ def windows(self):
289
304
290
305
@property
291
306
def attached_window (self ):
292
- """Return active :class:`Window` object.
293
-
294
- :rtype: :class:`Window`
307
+ """
308
+ Return active :class:`Window` object.
295
309
310
+ Returns
311
+ -------
312
+ :class:`Window`
296
313
"""
297
314
active_windows = []
298
315
for window in self ._windows :
@@ -313,15 +330,24 @@ def attached_window(self):
313
330
raise exc .LibTmuxException ('No Windows' )
314
331
315
332
def select_window (self , target_window ):
316
- """Return :class:`Window` selected via ``$ tmux select-window``.
333
+ """
334
+ Return :class:`Window` selected via ``$ tmux select-window``.
335
+
336
+ Parameters
337
+ ----------
338
+ window : str
339
+ ``target_window`` also 'last-window' (``-l``), 'next-window'
340
+ (``-n``), or 'previous-window' (``-p``)
317
341
318
- :param: window: ``target_window`` also 'last-window' (``-l``),
319
- 'next-window' (``-n``), or 'previous-window' (``-p``)
320
- :type window: integer
321
- :rtype: :class:`Window`
342
+ Returns
343
+ -------
344
+ :class:`Window`
322
345
323
- :todo: assure ``-l``, ``-n``, ``-p`` work.
346
+ Notes
347
+ -----
348
+ .. todo::
324
349
350
+ assure ``-l``, ``-n``, ``-p`` work.
325
351
"""
326
352
327
353
target = '-t%s' % target_window
@@ -339,21 +365,30 @@ def attached_pane(self):
339
365
340
366
return self .attached_window .attached_pane
341
367
342
- def set_option (self , option , value , g = False ):
343
- """Set option ``$ tmux set-option <option> <value>``.
344
-
345
- todo: needs tests
346
-
347
- :param option: the window option. such as 'default-shell'.
348
- :type option: str
349
- :param value: window value. True/False will turn in 'on' and 'off'. You
350
- can also enter 'on' or 'off' directly.
351
- :type value: bool
352
- :param global: check for option globally across all servers (-g)
353
- :type global: bool
354
- :raises: :exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
355
- :exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
356
-
368
+ def set_option (self , option , value , _global = False ):
369
+ """
370
+ Set option ``$ tmux set-option <option> <value>``.
371
+
372
+ Parameters
373
+ ----------
374
+ option : str
375
+ the window option. such as 'default-shell'.
376
+ value : str, int, or bool
377
+ True/False will turn in 'on' and 'off'. You can also enter 'on' or
378
+ 'off' directly.
379
+ _global : bool, optional
380
+ check for option globally across all servers (-g)
381
+
382
+ Raises
383
+ ------
384
+ :exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
385
+ :exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
386
+
387
+ Notes
388
+ -----
389
+ .. todo::
390
+
391
+ Needs tests
357
392
"""
358
393
359
394
if isinstance (value , bool ) and value :
@@ -363,7 +398,7 @@ def set_option(self, option, value, g=False):
363
398
364
399
tmux_args = tuple ()
365
400
366
- if g :
401
+ if _global :
367
402
tmux_args += ('-g' ,)
368
403
369
404
tmux_args += (option , value ,)
@@ -375,27 +410,37 @@ def set_option(self, option, value, g=False):
375
410
if isinstance (proc .stderr , list ) and len (proc .stderr ):
376
411
handle_option_error (proc .stderr [0 ])
377
412
378
- def show_options (self , option = None , g = False ):
379
- """Return a dict of options for the window.
413
+ def show_options (self , option = None , _global = False ):
414
+ """
415
+ Return a dict of options for the window.
380
416
381
417
For familiarity with tmux, the option ``option`` param forwards to pick
382
418
a single option, forwarding to :meth:`Session.show_option`.
383
419
384
- :param option: optional. show a single option.
385
- :type option: str
386
- :param g: Pass ``-g`` flag for global variable (server-wide)
387
- :type g: bool
388
- :rtype: :py:obj:`dict`
389
-
420
+ Parameters
421
+ ----------
422
+ option : str, optional
423
+ name of option, e.g. 'visual-silence'. Defaults to None, which
424
+ returns all options.
425
+ _global : bool, optional
426
+ Pass ``-g`` flag for global variable (server-wide)
427
+
428
+ Returns
429
+ -------
430
+ :py:obj:`dict`
431
+
432
+ Notes
433
+ -----
434
+ Uses ``_global`` for keyword name instead of ``global`` to avoid
435
+ colliding with reserved keyword.
390
436
"""
391
-
392
437
tmux_args = tuple ()
393
438
394
- if g :
439
+ if _global :
395
440
tmux_args += ('-g' ,)
396
441
397
442
if option :
398
- return self .show_option (option , g = g )
443
+ return self .show_option (option , _global = _global )
399
444
else :
400
445
tmux_args += ('show-options' ,)
401
446
session_options = self .cmd (
@@ -412,24 +457,36 @@ def show_options(self, option=None, g=False):
412
457
413
458
return session_options
414
459
415
- def show_option (self , option , g = False ):
460
+ def show_option (self , option , _global = False ):
416
461
"""Return a list of options for the window.
417
462
418
- :todo: test and return True/False for on/off string
463
+ Parameters
464
+ ----------
465
+ option : str
466
+ option name
467
+ _global : bool, optional
468
+ use global option scope, same as ``-g``
469
+
470
+ Returns
471
+ -------
472
+ str, int, or bool
473
+
474
+ Raises
475
+ ------
476
+ :exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
477
+ :exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
419
478
420
- :param option: option to return.
421
- :type option: str
422
- :param global: check for option globally across all servers (-g)
423
- :type global: bool
424
- :rtype: str, int or bool
425
- :raises: :exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
426
- :exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
479
+ Notes
480
+ -----
481
+ Uses ``_global`` for keyword name instead of ``global`` to avoid
482
+ colliding with reserved keyword.
427
483
484
+ Test and return True/False for on/off string.
428
485
"""
429
486
430
487
tmux_args = tuple ()
431
488
432
- if g :
489
+ if _global :
433
490
tmux_args += ('-g' ,)
434
491
435
492
tmux_args += (option ,)
0 commit comments