3
3
import os
4
4
5
5
import yaml
6
- from yaml import Loader
7
6
8
7
from utils import get_tmux_option , run_shell_command
9
8
@@ -66,28 +65,18 @@ def __init__(self, theme_config):
66
65
"""Constructor."""
67
66
status_line = theme_config .get ("status_line" )
68
67
status_left = theme_config .get ("status_left" )
69
- self .fg_format = get (
70
- status_left , "fg_format" , status_line .get ("foreground" )
71
- )
72
- self .bg_format = get (
73
- status_left , "bg_format" , status_line .get ("background" )
74
- )
75
- self .fg_icon = get (
76
- status_left , "fg_icon" , status_line .get ("foreground" )
77
- )
78
- self .bg_icon = get (
79
- status_left , "bg_icon" , status_line .get ("background" )
80
- )
68
+ self .fg_format = get (status_left , "fg_format" , status_line .get ("foreground" ))
69
+ self .bg_format = get (status_left , "bg_format" , status_line .get ("background" ))
70
+ self .fg_icon = get (status_left , "fg_icon" , status_line .get ("foreground" ))
71
+ self .bg_icon = get (status_left , "bg_icon" , status_line .get ("background" ))
81
72
self .fg_decorator = status_left .get (
82
73
"fg_decorator" , status_line .get ("foreground" )
83
74
)
84
75
self .bg_decorator = get (
85
76
status_left , "bg_decorator" , status_line .get ("background" )
86
77
)
87
78
self .icon = get (status_left , "icon" , status_line .get ("left_icon" ))
88
- self .decorator = status_left .get (
89
- "decorator" , status_line .get ("left_decorator" )
90
- )
79
+ self .decorator = status_left .get ("decorator" , status_line .get ("left_decorator" ))
91
80
self .style = get (status_left , "style" , status_line .get ("style" ))
92
81
super ().__init__ (
93
82
fg_format = self .fg_format ,
@@ -182,18 +171,10 @@ def __init__(self, theme_config):
182
171
"""Constructor."""
183
172
status_line = theme_config .get ("status_line" )
184
173
status_right = theme_config .get ("status_right" )
185
- self .fg_format = get (
186
- status_right , "fg_format" , status_line .get ("foreground" )
187
- )
188
- self .bg_format = get (
189
- status_right , "bg_format" , status_line .get ("background" )
190
- )
191
- self .fg_icon = get (
192
- status_right , "fg_icon" , status_line .get ("foreground" )
193
- )
194
- self .bg_icon = get (
195
- status_right , "bg_icon" , status_line .get ("background" )
196
- )
174
+ self .fg_format = get (status_right , "fg_format" , status_line .get ("foreground" ))
175
+ self .bg_format = get (status_right , "bg_format" , status_line .get ("background" ))
176
+ self .fg_icon = get (status_right , "fg_icon" , status_line .get ("foreground" ))
177
+ self .bg_icon = get (status_right , "bg_icon" , status_line .get ("background" ))
197
178
self .fg_decorator = get (
198
179
status_right , "fg_decorator" , status_line .get ("foreground" )
199
180
)
@@ -247,9 +228,7 @@ def produce_general_options_commands(self):
247
228
foreground = component .get ("fg" , self .terminal .get ("foreground" ))
248
229
background = component .get ("bg" , self .terminal .get ("background" ))
249
230
style = component .get ("style" , self .status_line .get ("style" ))
250
- style_command = self .get_style_command (
251
- foreground , background , style , name
252
- )
231
+ style_command = self .get_style_command (foreground , background , style , name )
253
232
if style_command is not None :
254
233
general .append (style_command )
255
234
@@ -280,12 +259,8 @@ def produce_status_left(self):
280
259
bg_format = component .get (
281
260
"bg_format" , self .theme .status_left .get ("bg_format" )
282
261
)
283
- fg_icon = component .get (
284
- "fg_icon" , self .theme .status_left .get ("fg_icon" )
285
- )
286
- bg_icon = component .get (
287
- "bg_icon" , self .theme .status_left .get ("bg_icon" )
288
- )
262
+ fg_icon = component .get ("fg_icon" , self .theme .status_left .get ("fg_icon" ))
263
+ bg_icon = component .get ("bg_icon" , self .theme .status_left .get ("bg_icon" ))
289
264
fg_decorator = component .get (
290
265
"fg_decorator" , self .theme .status_left .get ("fg_decorator" )
291
266
)
@@ -294,10 +269,10 @@ def produce_status_left(self):
294
269
)
295
270
style = component .get ("style" , self .theme .status_left .get ("style" ))
296
271
_format = component .get ("format" , EMPTY )
297
- format_style = f"{ self .get_style_for_option (fg_format , bg_format , style , _format )} "
298
- icon_style = (
299
- f"{ self .get_style_for_option (fg_icon , bg_icon , style , icon )} "
272
+ format_style = (
273
+ f"{ self .get_style_for_option (fg_format , bg_format , style , _format )} "
300
274
)
275
+ icon_style = f"{ self .get_style_for_option (fg_icon , bg_icon , style , icon )} "
301
276
decorator_style = f"{ self .get_style_for_option (fg_decorator , bg_decorator , style , decorator )} "
302
277
component_value = f"{ icon_style } { decorator_style } { format_style } "
303
278
status_left .append (component_value )
@@ -308,12 +283,8 @@ def produce_window(self):
308
283
"""Return tuple with active window and inactive window option strings."""
309
284
windows = {}
310
285
for name , component in self .window .items ():
311
- style = component .get (
312
- "style" , self .theme .window .get (name ).get ("style" )
313
- )
314
- icon = component .get (
315
- "icon" , self .theme .window .get (name ).get ("icon" )
316
- )
286
+ style = component .get ("style" , self .theme .window .get (name ).get ("style" ))
287
+ icon = component .get ("icon" , self .theme .window .get (name ).get ("icon" ))
317
288
window_name = component .get (
318
289
"window_name" , self .theme .window .get (name ).get ("window_name" )
319
290
)
@@ -358,13 +329,13 @@ def produce_window(self):
358
329
window_index_style = self .get_style_for_option (
359
330
fg_window_index , bg_window_index , style , window_index
360
331
)
361
- icon_style = self .get_style_for_option (
362
- fg_icon , bg_icon , style , icon
363
- )
332
+ icon_style = self .get_style_for_option (fg_icon , bg_icon , style , icon )
364
333
decorator_style = self .get_style_for_option (
365
334
fg_decorator , bg_decorator , style , decorator
366
335
)
367
- component_value = f"{ window_style } { window_index_style } { icon_style } { decorator_style } "
336
+ component_value = (
337
+ f"{ window_style } { window_index_style } { icon_style } { decorator_style } "
338
+ )
368
339
windows [name ] = component_value
369
340
370
341
return windows
@@ -386,12 +357,8 @@ def produce_status_right(self):
386
357
bg_format = options .get (
387
358
"bg_format" , self .theme .status_right .get ("bg_format" )
388
359
)
389
- fg_icon = options .get (
390
- "fg_icon" , self .theme .status_right .get ("fg_icon" )
391
- )
392
- bg_icon = options .get (
393
- "bg_icon" , self .theme .status_right .get ("bg_icon" )
394
- )
360
+ fg_icon = options .get ("fg_icon" , self .theme .status_right .get ("fg_icon" ))
361
+ bg_icon = options .get ("bg_icon" , self .theme .status_right .get ("bg_icon" ))
395
362
fg_decorator = options .get (
396
363
"fg_decorator" , self .theme .status_right .get ("fg_decorator" )
397
364
)
@@ -400,10 +367,10 @@ def produce_status_right(self):
400
367
)
401
368
style = options .get ("style" , self .theme .status_right .get ("style" ))
402
369
_format = options .get ("format" , EMPTY )
403
- format_style = f"{ self .get_style_for_option (fg_format , bg_format , style , _format )} "
404
- icon_style = (
405
- f"{ self .get_style_for_option (fg_icon , bg_icon , style , icon )} "
370
+ format_style = (
371
+ f"{ self .get_style_for_option (fg_format , bg_format , style , _format )} "
406
372
)
373
+ icon_style = f"{ self .get_style_for_option (fg_icon , bg_icon , style , icon )} "
407
374
decorator_style = f"{ self .get_style_for_option (fg_decorator , bg_decorator , style , decorator )} "
408
375
component_value = f"{ decorator_style } { icon_style } { format_style } "
409
376
status_right .append (component_value )
@@ -432,6 +399,20 @@ def get_style_for_option(self, foreground, background, style, option):
432
399
return f"{ _style } { _default_style } "
433
400
434
401
def get_style_command (self , foreground , background , style , style_name ):
402
+ """Return tmux set style option command.
403
+
404
+ Parameters:
405
+ foreground: The foreground color.
406
+ background: The background color.
407
+ style: The style.
408
+ style_name: The name of the style.
409
+ e.g. status-style, window-status-current-format, window-status-format
410
+
411
+ Return:
412
+ The tmux command string to set the style.
413
+ Example:
414
+ set-option -gq status-style 'fg=green,bg=black,italics'
415
+ """
435
416
style_content = None
436
417
if foreground and foreground .strip () != EMPTY :
437
418
style_content = f"fg={ foreground } ,"
@@ -454,21 +435,15 @@ def produce_option_commands(self):
454
435
window = self .produce_window ()
455
436
status_right = self .produce_status_right ()
456
437
457
- status_line_cmd = self .produce_option_command (
458
- "status-style" , status_line
459
- )
460
- status_left_cmd = self .produce_option_command (
461
- "status-left" , status_left
462
- )
438
+ status_line_cmd = self .produce_option_command ("status-style" , status_line )
439
+ status_left_cmd = self .produce_option_command ("status-left" , status_left )
463
440
active_window_cmd = self .produce_option_command (
464
441
"window-status-current-format" , window ["active" ]
465
442
)
466
443
inactive_window_cmd = self .produce_option_command (
467
444
"window-status-format" , window ["inactive" ]
468
445
)
469
- status_right_cmd = self .produce_option_command (
470
- "status-right" , status_right
471
- )
446
+ status_right_cmd = self .produce_option_command ("status-right" , status_right )
472
447
general_commands = self .produce_general_options_commands ()
473
448
option_commands = []
474
449
option_commands .append (general_commands )
@@ -484,9 +459,7 @@ def init(config_file="eutmux.yaml"):
484
459
"""Load config file, overwrite options by value from tmux.conf."""
485
460
486
461
# user can set customized config file under EUTMUX_CONFIG_HOME
487
- xdg_config_home = os .getenv (
488
- "XDG_CONFIG_HOME" , f'{ os .getenv ("HOME" )} /.config'
489
- )
462
+ xdg_config_home = os .getenv ("XDG_CONFIG_HOME" , f'{ os .getenv ("HOME" )} /.config' )
490
463
eutmux_config_home = f"{ xdg_config_home } /eutmux"
491
464
_config_file = f"{ eutmux_config_home } /{ config_file } "
492
465
if os .path .exists (_config_file ):
@@ -507,9 +480,7 @@ def init(config_file="eutmux.yaml"):
507
480
theme_name = eutmux .get ("theme" , "eutmux" )
508
481
509
482
# if dynamic theme is set, then use dynamic theme.
510
- dynamic_theme_name = get_tmux_option (
511
- "@eutmux_dynamic_theme_name" , theme_name
512
- )
483
+ dynamic_theme_name = get_tmux_option ("@eutmux_dynamic_theme_name" , theme_name )
513
484
theme_filename = f"{ dynamic_theme_name } .theme.yaml"
514
485
515
486
# if dynamic theme file doesn't exist under project, then check if it
0 commit comments