txtwrap 2.3.0__tar.gz → 2.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {txtwrap-2.3.0/txtwrap.egg-info → txtwrap-2.3.1}/PKG-INFO +18 -9
- {txtwrap-2.3.0 → txtwrap-2.3.1}/README.md +6 -7
- {txtwrap-2.3.0 → txtwrap-2.3.1}/setup.py +1 -1
- {txtwrap-2.3.0 → txtwrap-2.3.1}/txtwrap/__init__.pyi +5 -4
- {txtwrap-2.3.0 → txtwrap-2.3.1}/txtwrap/_txtwrap.py +115 -97
- {txtwrap-2.3.0 → txtwrap-2.3.1/txtwrap.egg-info}/PKG-INFO +18 -9
- {txtwrap-2.3.0 → txtwrap-2.3.1}/MANIFEST.in +0 -0
- {txtwrap-2.3.0 → txtwrap-2.3.1}/setup.cfg +0 -0
- {txtwrap-2.3.0 → txtwrap-2.3.1}/txtwrap/__init__.py +0 -0
- {txtwrap-2.3.0 → txtwrap-2.3.1}/txtwrap.egg-info/SOURCES.txt +0 -0
- {txtwrap-2.3.0 → txtwrap-2.3.1}/txtwrap.egg-info/dependency_links.txt +0 -0
- {txtwrap-2.3.0 → txtwrap-2.3.1}/txtwrap.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: txtwrap
|
3
|
-
Version: 2.3.
|
3
|
+
Version: 2.3.1
|
4
4
|
Summary: A tool for wrapping and filling text.
|
5
5
|
Home-page: https://github.com/azzammuhyala/txtwrap
|
6
6
|
Author: azzammuhyala
|
@@ -12,6 +12,16 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
12
12
|
Classifier: License :: OSI Approved :: MIT License
|
13
13
|
Requires-Python: >=3.3
|
14
14
|
Description-Content-Type: text/markdown
|
15
|
+
Dynamic: author
|
16
|
+
Dynamic: author-email
|
17
|
+
Dynamic: classifier
|
18
|
+
Dynamic: description
|
19
|
+
Dynamic: description-content-type
|
20
|
+
Dynamic: home-page
|
21
|
+
Dynamic: keywords
|
22
|
+
Dynamic: license
|
23
|
+
Dynamic: requires-python
|
24
|
+
Dynamic: summary
|
15
25
|
|
16
26
|
# TxTWrap🔡
|
17
27
|
A tool for wrapping and filling text.🔨
|
@@ -19,13 +29,12 @@ A tool for wrapping and filling text.🔨
|
|
19
29
|
- `LOREM_IPSUM_WORDS`
|
20
30
|
- `LOREM_IPSUM_SENTENCES`
|
21
31
|
- `LOREM_IPSUM_PARAGRAPHS`
|
22
|
-
- `TextWrapper` (
|
23
|
-
- `sanitize`
|
24
|
-
- `wrap`
|
25
|
-
- `align`
|
26
|
-
- `fillstr`
|
27
|
-
- `
|
28
|
-
- `shorten` (✅ Updated)
|
32
|
+
- `TextWrapper` (❇️ Fixed)
|
33
|
+
- `sanitize`
|
34
|
+
- `wrap`
|
35
|
+
- `align`
|
36
|
+
- `fillstr`
|
37
|
+
- `shorten`
|
29
38
|
|
30
39
|
# Documents📄
|
31
40
|
This module is inspired by the [`textwrap`](https://docs.python.org/3/library/textwrap.html) module, which provides
|
@@ -4,13 +4,12 @@ A tool for wrapping and filling text.🔨
|
|
4
4
|
- `LOREM_IPSUM_WORDS`
|
5
5
|
- `LOREM_IPSUM_SENTENCES`
|
6
6
|
- `LOREM_IPSUM_PARAGRAPHS`
|
7
|
-
- `TextWrapper` (
|
8
|
-
- `sanitize`
|
9
|
-
- `wrap`
|
10
|
-
- `align`
|
11
|
-
- `fillstr`
|
12
|
-
- `
|
13
|
-
- `shorten` (✅ Updated)
|
7
|
+
- `TextWrapper` (❇️ Fixed)
|
8
|
+
- `sanitize`
|
9
|
+
- `wrap`
|
10
|
+
- `align`
|
11
|
+
- `fillstr`
|
12
|
+
- `shorten`
|
14
13
|
|
15
14
|
# Documents📄
|
16
15
|
This module is inspired by the [`textwrap`](https://docs.python.org/3/library/textwrap.html) module, which provides
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# This stub
|
1
|
+
# This stub file supports in Python 3.8+
|
2
2
|
|
3
3
|
from typing import overload, Callable, Dict, Iterable, List, Literal, Optional, Set, Tuple, Union
|
4
4
|
|
@@ -35,7 +35,7 @@ class TextWrapper:
|
|
35
35
|
minimum_width: bool = True,
|
36
36
|
justify_last_line: bool = False,
|
37
37
|
break_on_hyphens: bool = True,
|
38
|
-
sizefunc: Optional[Callable[[str], Union[Tuple[Union[int, float], Union[int, float]], int, float]]] = None
|
38
|
+
sizefunc: Optional[Callable[[str], Union[Tuple[Union[int, float], Union[int, float]], int, float]]] = None
|
39
39
|
) -> None: ...
|
40
40
|
def __repr__(self) -> str: ...
|
41
41
|
def __str__(self) -> str: ...
|
@@ -51,7 +51,7 @@ class TextWrapper:
|
|
51
51
|
@property
|
52
52
|
def method(self) -> Literal['mono', 'word']: ...
|
53
53
|
@property
|
54
|
-
def alignment(self) -> Literal['left', 'center', 'right', 'fill
|
54
|
+
def alignment(self) -> Literal['left', 'center', 'right', 'fill-left', 'fill-center', 'fill-right']: ...
|
55
55
|
@property
|
56
56
|
def placeholder(self) -> str: ...
|
57
57
|
@property
|
@@ -69,7 +69,8 @@ class TextWrapper:
|
|
69
69
|
@property
|
70
70
|
def break_on_hyphens(self) -> bool: ...
|
71
71
|
@property
|
72
|
-
def sizefunc(self) -> Callable[[str], Union[Tuple[Union[int, float], Union[int, float]],
|
72
|
+
def sizefunc(self) -> Union[Callable[[str], Union[Tuple[Union[int, float], Union[int, float]],
|
73
|
+
int, float]], None]: ...
|
73
74
|
|
74
75
|
# Setters ----------------------------------------------------------------------------------------------------------
|
75
76
|
|
@@ -3,9 +3,22 @@ from re import compile, escape
|
|
3
3
|
|
4
4
|
# Tools ----------------------------------------------------------------------------------------------------------------
|
5
5
|
|
6
|
+
pdict = type('pdict', (dict,), {
|
7
|
+
'__repr__': lambda self : '{}({{\n {}\n}})'.format(
|
8
|
+
self.__class__.__name__,
|
9
|
+
',\n '.join(
|
10
|
+
'{!r}: {!r}'.format(key, value)
|
11
|
+
for key, value in self.items()
|
12
|
+
)
|
13
|
+
) if self else self.__class__.__name__ + '()',
|
14
|
+
'__setattr__': dict.__setitem__,
|
15
|
+
'__getattr__': lambda self, key: self.get(key, None),
|
16
|
+
'__delattr__': dict.__delitem__
|
17
|
+
})
|
18
|
+
|
6
19
|
split_hyphenated = compile(r'(?<=-)(?=(?!-).)').split
|
7
20
|
|
8
|
-
def mono(text, width,
|
21
|
+
def mono(text, width, _0, _1, lenfunc, sanitize, _2):
|
9
22
|
wrapped = []
|
10
23
|
current_char = ''
|
11
24
|
|
@@ -38,8 +51,7 @@ def word(text, width, fillchar, break_on_hyphens, lenfunc, sanitize, split_separ
|
|
38
51
|
|
39
52
|
if break_on_hyphens:
|
40
53
|
for part in split_hyphenated(word):
|
41
|
-
for wrapped_part in mono(part, width,
|
42
|
-
split_separator):
|
54
|
+
for wrapped_part in mono(part, width, 0, 0, lenfunc, sanitize, 0):
|
43
55
|
if lenfunc(current_line + wrapped_part) <= width:
|
44
56
|
current_line += wrapped_part
|
45
57
|
else:
|
@@ -47,7 +59,7 @@ def word(text, width, fillchar, break_on_hyphens, lenfunc, sanitize, split_separ
|
|
47
59
|
wrapped.append(current_line)
|
48
60
|
current_line = wrapped_part
|
49
61
|
else:
|
50
|
-
for part in mono(word, width,
|
62
|
+
for part in mono(word, width, 0, 0, lenfunc, sanitize, 0):
|
51
63
|
if lenfunc(current_line + part) <= width:
|
52
64
|
current_line += part
|
53
65
|
else:
|
@@ -60,7 +72,7 @@ def word(text, width, fillchar, break_on_hyphens, lenfunc, sanitize, split_separ
|
|
60
72
|
|
61
73
|
return wrapped
|
62
74
|
|
63
|
-
def jusitfy_align_left(aligned_positions, text,
|
75
|
+
def jusitfy_align_left(aligned_positions, text, _0, _1, offset_y):
|
64
76
|
aligned_positions.append((0, offset_y, text))
|
65
77
|
|
66
78
|
def justify_align_center(aligned_positions, text, width, text_width, offset_y):
|
@@ -82,7 +94,7 @@ def justify_fillstr_right(justified_lines, text, width, text_width, fillchar):
|
|
82
94
|
|
83
95
|
# Identities -----------------------------------------------------------------------------------------------------------
|
84
96
|
|
85
|
-
__version__ = '2.3.
|
97
|
+
__version__ = '2.3.1'
|
86
98
|
__author__ = 'azzammuhyala'
|
87
99
|
__license__ = 'MIT'
|
88
100
|
|
@@ -138,13 +150,12 @@ class TextWrapper:
|
|
138
150
|
[PyPi](https://pypi.org/project/txtwrap) for details.
|
139
151
|
"""
|
140
152
|
|
141
|
-
self._d =
|
153
|
+
self._d = pdict() # dictionary to store a metadata and private variables
|
142
154
|
|
143
155
|
self.width = width
|
144
156
|
self.line_padding = line_padding
|
145
157
|
self.method = method
|
146
158
|
self.alignment = alignment
|
147
|
-
self.sizefunc = sizefunc
|
148
159
|
self.placeholder = placeholder
|
149
160
|
self.fillchar = fillchar
|
150
161
|
self.separator = separator
|
@@ -153,14 +164,24 @@ class TextWrapper:
|
|
153
164
|
self.minimum_width = minimum_width
|
154
165
|
self.justify_last_line = justify_last_line
|
155
166
|
self.break_on_hyphens = break_on_hyphens
|
167
|
+
self.sizefunc = sizefunc
|
156
168
|
|
157
169
|
def __repr__(self):
|
158
|
-
return '
|
159
|
-
|
160
|
-
|
170
|
+
return '{}({})'.format(
|
171
|
+
self.__class__.__name__,
|
172
|
+
', '.join(
|
173
|
+
'{}={!r}'.format(name, getattr(self, name))
|
174
|
+
for name in self.__init__.__code__.co_varnames
|
175
|
+
if name != 'self'
|
176
|
+
)
|
177
|
+
)
|
161
178
|
|
162
179
|
def __str__(self):
|
163
|
-
return '<{}.
|
180
|
+
return '<{}.{} object at 0x{}>'.format(
|
181
|
+
self.__class__.__module__,
|
182
|
+
self.__class__.__name__,
|
183
|
+
hex(id(self))[2:].upper().zfill(16)
|
184
|
+
)
|
164
185
|
|
165
186
|
def __copy__(self):
|
166
187
|
return self.copy()
|
@@ -172,55 +193,55 @@ class TextWrapper:
|
|
172
193
|
|
173
194
|
@property
|
174
195
|
def width(self):
|
175
|
-
return self._d
|
196
|
+
return self._d.width
|
176
197
|
|
177
198
|
@property
|
178
199
|
def line_padding(self):
|
179
|
-
return self._d
|
200
|
+
return self._d.line_padding
|
180
201
|
|
181
202
|
@property
|
182
203
|
def method(self):
|
183
|
-
return self._d
|
204
|
+
return self._d.method
|
184
205
|
|
185
206
|
@property
|
186
207
|
def alignment(self):
|
187
|
-
return self._d
|
208
|
+
return self._d.alignment
|
188
209
|
|
189
210
|
@property
|
190
211
|
def placeholder(self):
|
191
|
-
return self._d
|
212
|
+
return self._d.placeholder
|
192
213
|
|
193
214
|
@property
|
194
215
|
def fillchar(self):
|
195
|
-
return self._d
|
216
|
+
return self._d.fillchar
|
196
217
|
|
197
218
|
@property
|
198
219
|
def separator(self):
|
199
|
-
return self._d
|
220
|
+
return self._d.separator
|
200
221
|
|
201
222
|
@property
|
202
223
|
def max_lines(self):
|
203
|
-
return self._d
|
224
|
+
return self._d.max_lines
|
204
225
|
|
205
226
|
@property
|
206
227
|
def preserve_empty(self):
|
207
|
-
return self._d
|
228
|
+
return self._d.preserve_empty
|
208
229
|
|
209
230
|
@property
|
210
231
|
def minimum_width(self):
|
211
|
-
return self._d
|
232
|
+
return self._d.minimum_width
|
212
233
|
|
213
234
|
@property
|
214
235
|
def justify_last_line(self):
|
215
|
-
return self._d
|
236
|
+
return self._d.justify_last_line
|
216
237
|
|
217
238
|
@property
|
218
239
|
def break_on_hyphens(self):
|
219
|
-
return self._d
|
240
|
+
return self._d.break_on_hyphens
|
220
241
|
|
221
242
|
@property
|
222
243
|
def sizefunc(self):
|
223
|
-
return self._d
|
244
|
+
return self._d._sizefunc
|
224
245
|
|
225
246
|
# Setters ----------------------------------------------------------------------------------------------------------
|
226
247
|
|
@@ -230,9 +251,7 @@ class TextWrapper:
|
|
230
251
|
raise TypeError("width must be an integer or float")
|
231
252
|
if new <= 0:
|
232
253
|
raise ValueError("width must be greater than 0")
|
233
|
-
|
234
|
-
raise ValueError("width must be greater than length of the placeholder")
|
235
|
-
self._d['width'] = new
|
254
|
+
self._d.width = new
|
236
255
|
|
237
256
|
@line_padding.setter
|
238
257
|
def line_padding(self, new):
|
@@ -240,7 +259,7 @@ class TextWrapper:
|
|
240
259
|
raise TypeError("line_padding must be a integer or float")
|
241
260
|
if new < 0:
|
242
261
|
raise ValueError("line_padding must be equal to or greater than 0")
|
243
|
-
self._d
|
262
|
+
self._d.line_padding = new
|
244
263
|
|
245
264
|
@method.setter
|
246
265
|
def method(self, new):
|
@@ -249,11 +268,11 @@ class TextWrapper:
|
|
249
268
|
new = new.strip().lower()
|
250
269
|
if new not in {'mono', 'word'}:
|
251
270
|
raise ValueError("method={!r} is invalid, must be 'mono' or 'word'".format(new))
|
252
|
-
self._d
|
271
|
+
self._d.method = new
|
253
272
|
if new == 'mono':
|
254
|
-
self._d
|
273
|
+
self._d.wrapfunc = mono
|
255
274
|
elif new == 'word':
|
256
|
-
self._d
|
275
|
+
self._d.wrapfunc = word
|
257
276
|
|
258
277
|
@alignment.setter
|
259
278
|
def alignment(self, new):
|
@@ -263,33 +282,30 @@ class TextWrapper:
|
|
263
282
|
if new not in {'left', 'center', 'right', 'fill', 'fill-left', 'fill-center', 'fill-right'}:
|
264
283
|
raise ValueError("alignment={!r} is invalid, must be 'left', 'center', 'right', 'fill', 'fill-left', "
|
265
284
|
"'fill-center', or 'fill-right'".format(new))
|
266
|
-
self._d
|
285
|
+
self._d.alignment = new = 'fill-left' if new == 'fill' else new
|
267
286
|
if new.endswith('left'):
|
268
|
-
self._d
|
269
|
-
self._d
|
287
|
+
self._d.align_justify = jusitfy_align_left
|
288
|
+
self._d.fillstr_justify = justify_fillstr_left
|
270
289
|
elif new.endswith('center'):
|
271
|
-
self._d
|
272
|
-
self._d
|
290
|
+
self._d.align_justify = justify_align_center
|
291
|
+
self._d.fillstr_justify = justify_fillstr_center
|
273
292
|
elif new.endswith('right'):
|
274
|
-
self._d
|
275
|
-
self._d
|
293
|
+
self._d.align_justify = justify_align_right
|
294
|
+
self._d.fillstr_justify = justify_fillstr_right
|
276
295
|
|
277
296
|
@placeholder.setter
|
278
297
|
def placeholder(self, new):
|
279
298
|
if not isinstance(new, str):
|
280
299
|
raise TypeError("placeholder must be a string")
|
281
|
-
self._d
|
282
|
-
self._d['length_placeholder'] = length = self._d['lenfunc'](new)
|
283
|
-
if self._d.get('max_lines', None) is not None and self._d['width'] < length:
|
284
|
-
raise ValueError("width must be greater than length of the placeholder")
|
300
|
+
self._d.placeholder = new
|
285
301
|
|
286
302
|
@fillchar.setter
|
287
303
|
def fillchar(self, new):
|
288
304
|
if not isinstance(new, str):
|
289
305
|
raise TypeError("fillchar must be a string")
|
290
|
-
self._d
|
306
|
+
self._d.fillchar = new
|
291
307
|
split = compile(escape(new)).split
|
292
|
-
self._d
|
308
|
+
self._d.split_fillchar = lambda string : [s for s in split(string) if s]
|
293
309
|
|
294
310
|
@separator.setter
|
295
311
|
def separator(self, new):
|
@@ -297,15 +313,15 @@ class TextWrapper:
|
|
297
313
|
raise TypeError("separator must be a string, iterable, or None")
|
298
314
|
if isinstance(new, Iterable) and not all(isinstance(s, str) for s in new):
|
299
315
|
raise ValueError("separator must be an iterable containing of strings")
|
300
|
-
self._d
|
316
|
+
self._d.separator = new
|
301
317
|
if new is None:
|
302
|
-
self._d
|
318
|
+
self._d.split_separator = lambda s : s.split()
|
303
319
|
return
|
304
320
|
elif isinstance(new, str):
|
305
321
|
split = compile(escape(new)).split
|
306
322
|
else:
|
307
323
|
split = compile('|'.join(map(escape, new))).split
|
308
|
-
self._d
|
324
|
+
self._d.split_separator = lambda string : [s for s in split(string) if s]
|
309
325
|
|
310
326
|
@max_lines.setter
|
311
327
|
def max_lines(self, new):
|
@@ -314,31 +330,30 @@ class TextWrapper:
|
|
314
330
|
if new is not None:
|
315
331
|
if new <= 0:
|
316
332
|
raise ValueError("max_lines must be greater than 0")
|
317
|
-
|
318
|
-
raise ValueError("width must be greater than length of the placeholder")
|
319
|
-
self._d['max_lines'] = new
|
333
|
+
self._d.max_lines = new
|
320
334
|
|
321
335
|
@preserve_empty.setter
|
322
336
|
def preserve_empty(self, new):
|
323
|
-
self._d
|
337
|
+
self._d.preserve_empty = bool(new)
|
324
338
|
|
325
339
|
@minimum_width.setter
|
326
340
|
def minimum_width(self, new):
|
327
|
-
self._d
|
341
|
+
self._d.minimum_width = bool(new)
|
328
342
|
|
329
343
|
@justify_last_line.setter
|
330
344
|
def justify_last_line(self, new):
|
331
|
-
self._d
|
345
|
+
self._d.justify_last_line = bool(new)
|
332
346
|
|
333
347
|
@break_on_hyphens.setter
|
334
348
|
def break_on_hyphens(self, new):
|
335
|
-
self._d
|
349
|
+
self._d.break_on_hyphens = bool(new)
|
336
350
|
|
337
351
|
@sizefunc.setter
|
338
352
|
def sizefunc(self, new):
|
353
|
+
self._d._sizefunc = new
|
339
354
|
if new is None:
|
340
|
-
self._d
|
341
|
-
self._d
|
355
|
+
self._d.sizefunc = lambda s : (len(s), 1)
|
356
|
+
self._d.lenfunc = len
|
342
357
|
return
|
343
358
|
if not callable(new):
|
344
359
|
raise TypeError("sizefunc must be a callable")
|
@@ -354,53 +369,56 @@ class TextWrapper:
|
|
354
369
|
raise ValueError("sizefunc returned width must be equal to or greater than 0")
|
355
370
|
if test[1] < 0:
|
356
371
|
raise ValueError("sizefunc returned height must be equal to or greater than 0")
|
357
|
-
self._d
|
358
|
-
self._d
|
372
|
+
self._d.sizefunc = new
|
373
|
+
self._d.lenfunc = lambda s : new(s)[0]
|
359
374
|
elif isinstance(test, (int, float)):
|
360
375
|
if test < 0:
|
361
376
|
raise ValueError("sizefunc (length) must be equal to or greater than 0")
|
362
|
-
self._d
|
363
|
-
self._d
|
377
|
+
self._d.sizefunc = None
|
378
|
+
self._d.lenfunc = new
|
364
379
|
else:
|
365
380
|
raise TypeError("sizefunc must be returned a tuple for size or a single value for width (length)")
|
366
381
|
|
367
382
|
# Methods ----------------------------------------------------------------------------------------------------------
|
368
383
|
|
369
384
|
def copy(self):
|
370
|
-
return TextWrapper(width=self._d
|
371
|
-
alignment=self._d
|
372
|
-
|
373
|
-
preserve_empty=self._d
|
374
|
-
justify_last_line=self._d
|
375
|
-
sizefunc=self._d
|
385
|
+
return TextWrapper(width=self._d.width, line_padding=self._d.line_padding, method=self._d.method,
|
386
|
+
alignment=self._d.alignment, placeholder=self._d.placeholder, fillchar=self._d.fillchar,
|
387
|
+
separator=self._d.separator, max_lines=self._d.max_lines,
|
388
|
+
preserve_empty=self._d.preserve_empty, minimum_width=self._d.minimum_width,
|
389
|
+
justify_last_line=self._d.justify_last_line, break_on_hyphens=self._d.break_on_hyphens,
|
390
|
+
sizefunc=self._d._sizefunc)
|
376
391
|
|
377
392
|
def sanitize(self, text):
|
378
393
|
if not isinstance(text, str):
|
379
394
|
raise TypeError("text must be a string")
|
380
395
|
|
381
|
-
return self._d
|
396
|
+
return self._d.fillchar.join(self._d.split_separator(text))
|
382
397
|
|
383
398
|
def wrap(self, text, return_details=False, *, _one_line=False):
|
384
399
|
if not isinstance(text, str):
|
385
400
|
raise TypeError("text must be a string")
|
386
401
|
|
387
|
-
wrapfunc = self._d
|
388
|
-
width = self._d
|
389
|
-
placeholder = self._d
|
390
|
-
fillchar = self._d
|
391
|
-
split_separator = self._d
|
392
|
-
max_lines = self._d
|
393
|
-
preserve_empty = self._d
|
394
|
-
break_on_hyphens = self._d
|
395
|
-
lenfunc = self._d
|
402
|
+
wrapfunc = self._d.wrapfunc
|
403
|
+
width = self._d.width
|
404
|
+
placeholder = self._d.placeholder
|
405
|
+
fillchar = self._d.fillchar
|
406
|
+
split_separator = self._d.split_separator
|
407
|
+
max_lines = self._d.max_lines
|
408
|
+
preserve_empty = self._d.preserve_empty
|
409
|
+
break_on_hyphens = self._d.break_on_hyphens
|
410
|
+
lenfunc = self._d.lenfunc
|
396
411
|
|
397
412
|
if _one_line:
|
398
413
|
max_lines = 1
|
399
414
|
else:
|
400
|
-
max_lines = self._d
|
415
|
+
max_lines = self._d.max_lines
|
401
416
|
|
402
417
|
set_max_lines = max_lines is not None
|
403
418
|
|
419
|
+
if set_max_lines and width < lenfunc(placeholder):
|
420
|
+
raise ValueError("width must be greater than length of the placeholder")
|
421
|
+
|
404
422
|
wrapped = []
|
405
423
|
indiced = set()
|
406
424
|
|
@@ -440,12 +458,12 @@ class TextWrapper:
|
|
440
458
|
if not isinstance(text, str):
|
441
459
|
raise TypeError("text must be a string")
|
442
460
|
|
443
|
-
width = self._d
|
444
|
-
line_padding = self._d
|
445
|
-
alignment = self._d
|
446
|
-
justify = self._d
|
447
|
-
minimum_width = self._d
|
448
|
-
sizefunc = self._d
|
461
|
+
width = self._d.width
|
462
|
+
line_padding = self._d.line_padding
|
463
|
+
alignment = self._d.alignment
|
464
|
+
justify = self._d.align_justify
|
465
|
+
minimum_width = self._d.minimum_width
|
466
|
+
sizefunc = self._d.sizefunc
|
449
467
|
|
450
468
|
if sizefunc is None:
|
451
469
|
raise TypeError("sizefunc must be a size")
|
@@ -471,8 +489,8 @@ class TextWrapper:
|
|
471
489
|
offset_y += height_line + line_padding
|
472
490
|
|
473
491
|
else:
|
474
|
-
split_fillchar = self._d
|
475
|
-
no_fill_last_line = not self._d
|
492
|
+
split_fillchar = self._d.split_fillchar
|
493
|
+
no_fill_last_line = not self._d.justify_last_line
|
476
494
|
lines_word = [split_fillchar(line) for line in wrapped]
|
477
495
|
|
478
496
|
if minimum_width and any(
|
@@ -505,8 +523,8 @@ class TextWrapper:
|
|
505
523
|
offset_y += height_line + line_padding
|
506
524
|
|
507
525
|
if return_details:
|
508
|
-
return {'aligned': aligned, 'wrapped': wrapped, 'indiced': indiced,
|
509
|
-
|
526
|
+
return {'aligned': aligned, 'wrapped': wrapped, 'indiced': indiced,
|
527
|
+
'size': (use_width, offset_y - line_padding)}
|
510
528
|
|
511
529
|
return aligned
|
512
530
|
|
@@ -514,13 +532,13 @@ class TextWrapper:
|
|
514
532
|
if not isinstance(text, str):
|
515
533
|
raise TypeError("text must be a string")
|
516
534
|
|
517
|
-
width = self._d
|
518
|
-
line_padding = self._d
|
519
|
-
alignment = self._d
|
520
|
-
fillchar = self._d
|
521
|
-
justify = self._d
|
522
|
-
minimum_width = self._d
|
523
|
-
lenfunc = self._d
|
535
|
+
width = self._d.width
|
536
|
+
line_padding = self._d.line_padding
|
537
|
+
alignment = self._d.alignment
|
538
|
+
fillchar = self._d.fillchar
|
539
|
+
justify = self._d.fillstr_justify
|
540
|
+
minimum_width = self._d.minimum_width
|
541
|
+
lenfunc = self._d.lenfunc
|
524
542
|
|
525
543
|
wrapped_info = self.wrap(text, True)
|
526
544
|
wrapped = wrapped_info['wrapped']
|
@@ -545,8 +563,8 @@ class TextWrapper:
|
|
545
563
|
justified_lines.append(fill_line_padding)
|
546
564
|
|
547
565
|
else:
|
548
|
-
split_fillchar = self._d
|
549
|
-
no_fill_last_line = not self._d
|
566
|
+
split_fillchar = self._d.split_fillchar
|
567
|
+
no_fill_last_line = not self._d.justify_last_line
|
550
568
|
lines_word = [split_fillchar(line) for line in wrapped]
|
551
569
|
|
552
570
|
if minimum_width and any(
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: txtwrap
|
3
|
-
Version: 2.3.
|
3
|
+
Version: 2.3.1
|
4
4
|
Summary: A tool for wrapping and filling text.
|
5
5
|
Home-page: https://github.com/azzammuhyala/txtwrap
|
6
6
|
Author: azzammuhyala
|
@@ -12,6 +12,16 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
12
12
|
Classifier: License :: OSI Approved :: MIT License
|
13
13
|
Requires-Python: >=3.3
|
14
14
|
Description-Content-Type: text/markdown
|
15
|
+
Dynamic: author
|
16
|
+
Dynamic: author-email
|
17
|
+
Dynamic: classifier
|
18
|
+
Dynamic: description
|
19
|
+
Dynamic: description-content-type
|
20
|
+
Dynamic: home-page
|
21
|
+
Dynamic: keywords
|
22
|
+
Dynamic: license
|
23
|
+
Dynamic: requires-python
|
24
|
+
Dynamic: summary
|
15
25
|
|
16
26
|
# TxTWrap🔡
|
17
27
|
A tool for wrapping and filling text.🔨
|
@@ -19,13 +29,12 @@ A tool for wrapping and filling text.🔨
|
|
19
29
|
- `LOREM_IPSUM_WORDS`
|
20
30
|
- `LOREM_IPSUM_SENTENCES`
|
21
31
|
- `LOREM_IPSUM_PARAGRAPHS`
|
22
|
-
- `TextWrapper` (
|
23
|
-
- `sanitize`
|
24
|
-
- `wrap`
|
25
|
-
- `align`
|
26
|
-
- `fillstr`
|
27
|
-
- `
|
28
|
-
- `shorten` (✅ Updated)
|
32
|
+
- `TextWrapper` (❇️ Fixed)
|
33
|
+
- `sanitize`
|
34
|
+
- `wrap`
|
35
|
+
- `align`
|
36
|
+
- `fillstr`
|
37
|
+
- `shorten`
|
29
38
|
|
30
39
|
# Documents📄
|
31
40
|
This module is inspired by the [`textwrap`](https://docs.python.org/3/library/textwrap.html) module, which provides
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|