A spot of refactoring

This commit is contained in:
Kovid Goyal 2017-05-02 12:03:22 +05:30
parent aa9c42dcaa
commit 7524b79d5a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 7 deletions

View File

@ -7,10 +7,10 @@ from __future__ import absolute_import, division, print_function, unicode_litera
import json
import os
import sys
import unicodedata
from textwrap import TextWrapper
from calibre import prints
from calibre.db.utils import str_width
from calibre.ebooks.metadata import authors_to_string
from calibre.utils.date import isoformat
@ -172,12 +172,6 @@ def do_list(
output_table = prepare_output_table(fields, book_ids, data, metadata)
widths = list(map(lambda x: 0, fields))
def chr_width(x):
return 1 + unicodedata.east_asian_width(x).startswith('W')
def str_width(x):
return sum(map(chr_width, x))
for record in output_table:
for j in range(len(fields)):
widths[j] = max(widths[j], str_width(record[j]))

View File

@ -0,0 +1,17 @@
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import absolute_import, division, print_function, unicode_literals
import unicodedata
eaw = unicodedata.east_asian_width
def chr_width(x):
return 1 + eaw(x).startswith('W')
def str_width(x):
return sum(map(chr_width, x))