mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
A spot of refactoring
This commit is contained in:
parent
aa9c42dcaa
commit
7524b79d5a
@ -7,10 +7,10 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unicodedata
|
|
||||||
from textwrap import TextWrapper
|
from textwrap import TextWrapper
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
|
from calibre.db.utils import str_width
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
from calibre.utils.date import isoformat
|
from calibre.utils.date import isoformat
|
||||||
|
|
||||||
@ -172,12 +172,6 @@ def do_list(
|
|||||||
output_table = prepare_output_table(fields, book_ids, data, metadata)
|
output_table = prepare_output_table(fields, book_ids, data, metadata)
|
||||||
widths = list(map(lambda x: 0, fields))
|
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 record in output_table:
|
||||||
for j in range(len(fields)):
|
for j in range(len(fields)):
|
||||||
widths[j] = max(widths[j], str_width(record[j]))
|
widths[j] = max(widths[j], str_width(record[j]))
|
||||||
|
17
src/calibre/db/cli/utils.py
Normal file
17
src/calibre/db/cli/utils.py
Normal 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))
|
Loading…
x
Reference in New Issue
Block a user