7
7
from .widechar import cjklen , PY3
8
8
#from os import get_terminal_size
9
9
10
+ import locale
11
+ locale .setlocale (locale .LC_ALL , '' ) # set your locale
12
+
10
13
logger = logging .getLogger (__name__ )
11
14
12
15
@@ -320,44 +323,19 @@ def format_station_line(self, id_in_list, pad, width):
320
323
empty string
321
324
"""
322
325
323
- if PY3 :
324
- info = ('' ,
325
- ' {0} {1}kb' ,
326
- ' {0}{1} v│{2} cl│{3}kb' ,
327
- ' {0} {1}│ {2}│ {3}kb' ,
328
- ' {0} {1}│ {2}│ {3}kb│{4}' ,
329
- ' {0} {1}│ {2}│ {3}kb│{4}│{5}' ,
330
- )
331
- else :
332
- info = ('' ,
333
- ' {0} {1}kb' ,
334
- ' {0}{1} v|{2} cl|{3}kb' ,
335
- ' {0} {1}| {2}| {3}kb' ,
336
- ' {0} {1}| {2}| {3}kb|{4}' ,
337
- ' {0} {1}| {2}| {3}kb|{4}|{5}' ,
338
- )
339
- # now_width = get_terminal_size().columns - 2
340
- now_width = width
341
- if now_width <= 45 :
342
- self ._output_format = 0
343
- elif now_width <= 55 :
344
- self ._output_format = 1
345
- elif now_width <= 78 :
346
- self ._output_format = 2
347
- elif now_width <= 100 :
348
- self ._output_format = 3
349
- elif now_width <= 125 :
350
- self ._output_format = 4
351
- else :
352
- self ._output_format = 5
353
-
326
+ info = (u'' ,
327
+ u' {0} {1}kb' ,
328
+ u' {0} {1}│ {2}kb' ,
329
+ u' {0} {1}│ {2}│ {3}kb' ,
330
+ u' {0} {1}│ {2}│ {3}kb│{4}' ,
331
+ u' {0} {1}│ {2}│ {3}kb│{4}│{5}' ,
332
+ )
333
+ self ._get_output_format (width )
334
+ #logger.error('DE self._output_format = {}'.format(self._output_format))
354
335
out = ['{0}. ' .format (str (id_in_list + 1 ).rjust (pad )), '' , '' ]
355
336
356
337
# format info field
357
- if PY3 :
358
- pl = u'┼' if self ._raw_stations [id_in_list ]['played' ] else u'│'
359
- else :
360
- pl = '+' if self ._raw_stations [id_in_list ]['played' ] else '|'
338
+ pl = u'├' if self ._raw_stations [id_in_list ]['played' ] else u'│'
361
339
if self ._output_format == 5 :
362
340
# full with state
363
341
out [2 ] = ' ' + info [self ._output_format ].format (
@@ -377,7 +355,13 @@ def format_station_line(self, id_in_list, pad, width):
377
355
self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ],
378
356
self ._raw_stations [id_in_list ]['country' ].ljust (14 )[:14 ]
379
357
)
380
- elif self ._output_format in (2 , 3 ):
358
+ elif self ._output_format == 2 :
359
+ out [2 ] = ' ' + info [self ._output_format ].format (
360
+ pl ,
361
+ self ._raw_stations [id_in_list ]['votes' ].rjust (self ._max_len [0 ]),
362
+ self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ]
363
+ )
364
+ elif self ._output_format == 3 :
381
365
out [2 ] = ' ' + info [self ._output_format ].format (
382
366
pl ,
383
367
self ._raw_stations [id_in_list ]['votes' ].rjust (self ._max_len [0 ]),
@@ -394,13 +378,17 @@ def format_station_line(self, id_in_list, pad, width):
394
378
name_width = width - len (out [0 ])- len (out [2 ])
395
379
out [1 ] = self ._fix_cjk_string_width (self ._raw_stations [id_in_list ]['name' ].ljust (name_width )[:name_width ], name_width )
396
380
if PY3 :
397
- return '{0}{1}{2}' .format (* out )
381
+ # if pl == '╞':
382
+ # out[2] += '╡'
383
+ return (self ._raw_stations [id_in_list ]['played' ],
384
+ '{0}{1}{2}' .format (* out ))
398
385
else :
399
386
# on python 2, strings are already in utf-8
400
- return '{0}{1}{2}' .format (
387
+ return (self ._raw_stations [id_in_list ]['played' ],
388
+ '{0}{1}{2}' .format (
401
389
out [0 ].encode ('utf-8' , 'replace' ),
402
390
out [1 ].encode ('utf-8' , 'replace' ),
403
- out [2 ].encode ('utf-8' , 'replace' ))
391
+ out [2 ].encode ('utf-8' , 'replace' )))
404
392
405
393
def set_encoding (self , id_in_list , new_encoding ):
406
394
if id_in_list < len (self ._raw_stations ):
@@ -439,20 +427,16 @@ def _get_max_len(self, votes, clicks):
439
427
440
428
Parameters
441
429
----------
442
- string_data
443
- A tuple (name, country) - (uses cjklen)
444
- country
445
- A string (uses cjklen)
430
+ votes
431
+ Number of station's vote
432
+ clicks
433
+ Number of station's clicks
446
434
numeric_data
447
- A tuple (bitrate, votes, clickcount)
448
435
449
436
Returns
450
437
-------
451
438
self._max_len
452
- A list [max name length (max is 50),
453
- max country length (max is 14),
454
- max bitrate length,
455
- max votes length,
439
+ A list [max votes length,
456
440
max clickcount length]
457
441
"""
458
442
@@ -462,6 +446,65 @@ def _get_max_len(self, votes, clicks):
462
446
if len (n ) > self ._max_len [i ]:
463
447
self ._max_len [i ] = len (n ) if len (n ) > min_data [i ] else min_data [i ]
464
448
449
+ def _get_output_format (self , width ):
450
+ """ Return output format based on window width
451
+
452
+ Paramaters
453
+ ----------
454
+ width
455
+ Window width
456
+
457
+ Returns
458
+ -------
459
+ self._output_format
460
+ A number 0..5
461
+ """
462
+
463
+ # now_width = get_terminal_size().columns - 2
464
+ if width <= 50 :
465
+ self ._output_format = 0
466
+ elif width < 57 :
467
+ self ._output_format = 1
468
+ elif width < 65 :
469
+ self ._output_format = 2
470
+ elif width < 80 :
471
+ self ._output_format = 3
472
+ elif width < 95 :
473
+ self ._output_format = 4
474
+ else :
475
+ self ._output_format = 5
476
+
477
+ def get_columns_separators (self , width , force_py2 = False ):
478
+ if not force_py2 and not PY3 :
479
+ return []
480
+ self ._get_output_format (width )
481
+ if self ._output_format == 0 :
482
+ return []
483
+ elif self ._output_format == 1 :
484
+ return [ width - 10 ]
485
+ elif self ._output_format == 2 :
486
+ return [width - 18 ,
487
+ width - 10
488
+ ]
489
+ elif self ._output_format == 3 :
490
+ return [width - 27 ,
491
+ width - 19 ,
492
+ width - 10
493
+ ]
494
+ elif self ._output_format == 4 :
495
+ return [width - 42 ,
496
+ width - 34 ,
497
+ width - 25 ,
498
+ width - 14
499
+ ]
500
+ elif self ._output_format == 5 :
501
+ return [width - 58 ,
502
+ width - 50 ,
503
+ width - 41 ,
504
+ width - 30 ,
505
+ width - 15
506
+ ]
507
+
465
508
466
509
class PyRadioBrowserInfoData (object ):
467
510
""" Read search parameters for radio.browser.info service
0 commit comments