def filter(self, context): max_width = context['max_abbr_width'] footer_width = max_width / 3 for candidate in context['candidates']: candidate['abbr'] = truncate_skipping( candidate.get('abbr', candidate['word']), max_width, '..', footer_width) return context['candidates']
def filter(self, context): max_width = context['max_info_width'] if not context['candidates'] or max_width <= 0: return context['candidates'] footer_width = 1 for candidate in context['candidates']: candidate['info'] = truncate_skipping(candidate.get('info', ''), max_width, '..', footer_width) return context['candidates']
def filter(self, context): if not context['candidates'] or 'menu' not in context['candidates'][0]: return context['candidates'] max_width = context['max_menu_width'] footer_width = max_width / 3 for candidate in context['candidates']: candidate['menu'] = truncate_skipping(candidate.get('menu', ''), max_width, '..', footer_width) return context['candidates']
def filter(self, context): max_width = context['max_abbr_width'] if max_width < 0: return context['candidates'] footer_width = max_width / 3 for candidate in context['candidates']: candidate['abbr'] = truncate_skipping( candidate.get('abbr', candidate['word']), max_width, '..', footer_width) return context['candidates']
def filter(self, context): max_width = context['max_info_width'] if not context['candidates'] or max_width <= 0: return context['candidates'] footer_width = 1 for candidate in context['candidates']: candidate['info'] = truncate_skipping( candidate.get('info', ''), max_width, '..', footer_width) return context['candidates']
def filter(self, context): max_width = context['max_menu_width'] if not context['candidates'] or 'menu' not in context[ 'candidates'][0] or max_width <= 0: return context['candidates'] footer_width = max_width / 3 for candidate in context['candidates']: candidate['menu'] = truncate_skipping( candidate.get('menu', ''), max_width, '..', footer_width) return context['candidates']
def filter(self, context: UserContext) -> Candidates: max_width = context['max_kind_width'] if not context['candidates'] or 'kind' not in context['candidates'][ 0] or max_width <= 0: return list(context['candidates']) footer_width = max_width / 3 for candidate in context['candidates']: candidate['kind'] = truncate_skipping(candidate.get('kind', ''), max_width, '..', footer_width) return list(context['candidates'])
def filter(self, context: UserContext) -> Candidates: max_width = context['max_menu_width'] if not context['candidates'] or 'menu' not in context['candidates'][ 0] or max_width <= 0: return context['candidates'] # type: ignore footer_width = max_width / 3 for candidate in context['candidates']: candidate['menu'] = truncate_skipping(candidate.get('menu', ''), max_width, '..', footer_width) return context['candidates'] # type: ignore
def test_skipping(self): eq_(truncate_skipping('foo bar', 3, '..', 3), '..bar') eq_(truncate_skipping('foo bar', 6, '..', 3), 'f..bar') eq_(truncate_skipping('fooあい', 5, '..', 3), 'f..い') eq_(truncate_skipping('あいうえ', 6, '..', 2), 'あ..え')
def test_skipping(): assert util.truncate_skipping('foo bar', 3, '..', 3) == '..bar' assert util.truncate_skipping('foo bar', 6, '..', 3) == 'f..bar' assert util.truncate_skipping('fooあい', 5, '..', 3) == 'f..い' assert util.truncate_skipping('あいうえ', 6, '..', 2) == 'あ..え'