77from .widechar import cjklen , PY3
88#from os import get_terminal_size
99
10+ import locale
11+ locale .setlocale (locale .LC_ALL , '' ) # set your locale
12+
1013logger = logging .getLogger (__name__ )
1114
1215
@@ -320,44 +323,19 @@ def format_station_line(self, id_in_list, pad, width):
320323 empty string
321324 """
322325
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))
354335 out = ['{0}. ' .format (str (id_in_list + 1 ).rjust (pad )), '' , '' ]
355336
356337 # 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'│'
361339 if self ._output_format == 5 :
362340 # full with state
363341 out [2 ] = ' ' + info [self ._output_format ].format (
@@ -377,7 +355,13 @@ def format_station_line(self, id_in_list, pad, width):
377355 self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ],
378356 self ._raw_stations [id_in_list ]['country' ].ljust (14 )[:14 ]
379357 )
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 :
381365 out [2 ] = ' ' + info [self ._output_format ].format (
382366 pl ,
383367 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):
394378 name_width = width - len (out [0 ])- len (out [2 ])
395379 out [1 ] = self ._fix_cjk_string_width (self ._raw_stations [id_in_list ]['name' ].ljust (name_width )[:name_width ], name_width )
396380 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 ))
398385 else :
399386 # 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 (
401389 out [0 ].encode ('utf-8' , 'replace' ),
402390 out [1 ].encode ('utf-8' , 'replace' ),
403- out [2 ].encode ('utf-8' , 'replace' ))
391+ out [2 ].encode ('utf-8' , 'replace' )))
404392
405393 def set_encoding (self , id_in_list , new_encoding ):
406394 if id_in_list < len (self ._raw_stations ):
@@ -439,20 +427,16 @@ def _get_max_len(self, votes, clicks):
439427
440428 Parameters
441429 ----------
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
446434 numeric_data
447- A tuple (bitrate, votes, clickcount)
448435
449436 Returns
450437 -------
451438 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,
456440 max clickcount length]
457441 """
458442
@@ -462,6 +446,65 @@ def _get_max_len(self, votes, clicks):
462446 if len (n ) > self ._max_len [i ]:
463447 self ._max_len [i ] = len (n ) if len (n ) > min_data [i ] else min_data [i ]
464448
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+
465508
466509class PyRadioBrowserInfoData (object ):
467510 """ Read search parameters for radio.browser.info service
0 commit comments