txtwrap 2.3.2__tar.gz → 3.0.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.
@@ -1,19 +1,20 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: txtwrap
3
- Version: 2.3.2
3
+ Version: 3.0.1
4
4
  Summary: A tool for wrapping and filling text.
5
5
  Home-page: https://github.com/azzammuhyala/txtwrap
6
6
  Author: azzammuhyala
7
7
  Author-email: azzammuhyala@gmail.com
8
8
  License: MIT
9
+ Project-URL: Source, https://github.com/azzammuhyala/txtwrap
10
+ Project-URL: Bug Tracker, https://github.com/azzammuhyala/txtwrap/issues
9
11
  Keywords: wrap,wrapper,wrapping,wrapped,text wrap,text wrapper,text wrapping,text wrapped
10
12
  Classifier: Programming Language :: Python
11
13
  Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.3
13
14
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
15
  Classifier: Topic :: Text Processing
15
16
  Classifier: Topic :: Text Processing :: Filters
16
- Requires-Python: >=3.3
17
+ Requires-Python: >=3.0
17
18
  Description-Content-Type: text/markdown
18
19
  Dynamic: author
19
20
  Dynamic: author-email
@@ -23,25 +24,28 @@ Dynamic: description-content-type
23
24
  Dynamic: home-page
24
25
  Dynamic: keywords
25
26
  Dynamic: license
27
+ Dynamic: project-url
26
28
  Dynamic: requires-python
27
29
  Dynamic: summary
28
30
 
29
31
  # TxTWrap🔡
30
32
  A tool for wrapping and filling text.🔨
31
33
 
32
- Version: **2.3.2** <br>
33
- Python requires version: **3.3.0+** <br>
34
- Python stub file requires version: **3.8.0+**
34
+ Package version: **3.0.1** <br>
35
+ Python requires version: **>=3.0.0** <br>
36
+ Python stub file requires version: **>=3.5.0** <br>
35
37
 
36
38
  - [`LOREM_IPSUM_WORDS`](#lorem-ipsum)
37
39
  - [`LOREM_IPSUM_SENTENCES`](#lorem-ipsum)
38
40
  - [`LOREM_IPSUM_PARAGRAPHS`](#lorem-ipsum)
39
- - [`TextWrapper`](#textwrapper) (🔨 Fixed)
40
- - [`sanitize`](#sanitizetext)
41
- - [`wrap`](#wraptext-return_detailsfalse)
42
- - [`align`](#aligntext-return_detailsfalse)
43
- - [`fillstr`](#fillstrtext)
44
- - [`shorten`](#shortentext)
41
+ - [`SEPARATOR_WHITESPACE`](#separators)
42
+ - [`SEPARATOR_ESCAPE`](#separators)
43
+ - [`TextWrapper`](#textwrapper) (🛠️ Fixed)
44
+ - [`sanitize`](#sanitizetext) (🛠️ Fixed)
45
+ - [`wrap`](#wraptext-return_detailsfalse) (🛠️ Fixed)
46
+ - [`align`](#aligntext-return_detailsfalse) (🛠️ Fixed)
47
+ - [`fillstr`](#fillstrtext) (🛠️ Fixed)
48
+ - [`shorten`](#shortentext) (🛠️ Fixed)
45
49
 
46
50
  # Documents📄
47
51
  This module is inspired by the [`textwrap`](https://docs.python.org/3/library/textwrap.html) module, which provides
@@ -53,7 +57,10 @@ filling _monospace fonts_ but also for other font types, such as _Arial_, _Times
53
57
 
54
58
  <h1></h1>
55
59
 
56
- ## Lorem ipsum
60
+ ## Constants
61
+ _File: **txtwrap.constants**_
62
+
63
+ ### Lorem ipsum
57
64
  ```py
58
65
  LOREM_IPSUM_WORDS
59
66
  LOREM_IPSUM_SENTENCES
@@ -66,24 +73,41 @@ A _Lorem Ipsum_ collection of words, sentences, and paragraphs that can be used
66
73
 
67
74
  <h1></h1>
68
75
 
76
+ ### Separators
77
+ ```py
78
+ SEPARATOR_WHITESPACE
79
+ SEPARATOR_ESCAPE
80
+ ```
81
+ A collection of separators that can be used to separate text.
82
+ - `SEPARATOR_WHITESPACE` contains whitespace characters.
83
+ - `SEPARATOR_ESCAPE` contains whitespace characters including `'\0'`, `'\a'`, and `'\b'`.
84
+
85
+ To use this, assign this constant to the [`separator`](#separator) parameter.
86
+
87
+ <h1></h1>
88
+
69
89
  ## `TextWrapper`
90
+ _File: **txtwrap.wrapper**_
91
+
70
92
  ```py
71
93
  class TextWrapper:
94
+
72
95
  def __init__(
73
96
  self,
74
97
  width: Union[int, float] = 70,
75
98
  line_padding: Union[int, float] = 0,
76
- method: Literal['mono', 'word'] = 'word',
99
+ mode: Literal['mono', 'word'] = 'word',
77
100
  alignment: Literal['left', 'center', 'right', 'fill', 'fill-left', 'fill-center', 'fill-right'] = 'left',
78
101
  placeholder: str = '...',
79
102
  fillchar: str = ' ',
80
103
  separator: Optional[Union[str, Iterable[str]]] = None,
81
104
  max_lines: Optional[int] = None,
82
- preserve_empty: bool = True,
105
+ preserve_empty_lines: bool = True,
83
106
  minimum_width: bool = True,
107
+ drop_separator: bool = False,
84
108
  justify_last_line: bool = False,
85
109
  break_on_hyphens: bool = True,
86
- sizefunc: Optional[Callable[[str], Union[Tuple[Union[int, float], Union[int, float]], int, float]]] = None,
110
+ sizefunc: Optional[Callable[[str], Union[Tuple[Union[int, float], Union[int, float]], int, float]]] = None
87
111
  ) -> None
88
112
  ```
89
113
  A class that handles all functions available in this module. Each keyword argument corresponds to its attribute.
@@ -116,10 +140,10 @@ as each attribute has type checking, which may reduce performance.
116
140
 
117
141
  <h1></h1>
118
142
 
119
- #### **`method`**
120
- (Default: `'word'`) The wrapping method. Available options:
121
- - `'mono'` method wraps text character by character.
122
- - `'word'` method wraps text word by word.
143
+ #### **`mode`**
144
+ (Default: `'word'`) The wrapping mode. Available options:
145
+ - `'mono'` make text wraps character by character.
146
+ - `'word'` make text wraps word by word.
123
147
 
124
148
  <h1></h1>
125
149
 
@@ -161,7 +185,7 @@ as each attribute has type checking, which may reduce performance.
161
185
 
162
186
  <h1></h1>
163
187
 
164
- #### **`preserve_empty`**
188
+ #### **`preserve_empty_lines`**
165
189
  (Default: `True`) Retains empty lines in the wrapped text.
166
190
 
167
191
  <h1></h1>
@@ -172,6 +196,11 @@ enabling this attribute removes unnecessary empty space.
172
196
 
173
197
  <h1></h1>
174
198
 
199
+ #### **`drop_separator`**
200
+ (Default: `False`) Removes excess separators from between words one at a time.
201
+
202
+ <h1></h1>
203
+
175
204
  #### **`justify_last_line`**
176
205
  (Default: `False`) Determines whether the last line should also be justified
177
206
  (applies only to `fill-...` alignments).
@@ -198,20 +227,29 @@ If the function calculates only the width, it must return a single value of type
198
227
 
199
228
  > Note: All methods can be called outside the [`TextWrapper`](#textwrapper) like external functions.
200
229
 
230
+ For example:
231
+ ```py
232
+ >>> txtwrap.TextWrapper(20, placeholder='[...]').shorten("Hello World!")
233
+ ```
234
+ is equivalent to:
235
+ ```py
236
+ >>> txtwrap.shorten("Hello World!", 20, placeholder='[...]')
237
+ ```
238
+
201
239
  <h1></h1>
202
240
 
203
241
  #### **`copy`**
204
- Creates and returns a copy of the [`TextWrapper`](#textwrapper) object.
242
+ Creates and returns a copy of the [`TextWrapper`](#textwrapper) object. (External function using `copy.copy`)
205
243
 
206
244
  <h1></h1>
207
245
 
208
246
  #### **`sanitize(text)`**
209
247
  Removes excessive characters from [`separator`](#separator) and replaces them with the [`fillchar`](#fillchar)
210
- character.
248
+ character. (It doesn't matter whether [`drop_separator`](#drop_separator) is `False` or `True`)
211
249
 
212
250
  For example:
213
251
  ```py
214
- >>> TextWrapper().sanitize("\tHello \nWorld!\r ")
252
+ >>> txtwrap.sanitize("\tHello \nWorld!\r ")
215
253
  'Hello World!'
216
254
  ```
217
255
 
@@ -220,48 +258,64 @@ For example:
220
258
  #### **`wrap(text, return_details=False)`**
221
259
  Returns a list of wrapped text strings. If `return_details=True`, returns a dictionary containing:
222
260
  - `'wrapped'`: A list of wrapped text fragments.
223
- - `'indiced'`: A set of indices marking the end of line (starting from `0`, like programming indices).
261
+ - `'start_lines'`: A list of indices marking the start of line.
262
+ - `'end_lines'`: A list of indices marking the end of line.
224
263
 
225
264
  For example:
226
265
  ```py
227
- >>> TextWrapper(width=15).wrap(LOREM_IPSUM_WORDS)
228
- ['Lorem ipsum', 'odor amet,', 'consectetuer', 'adipiscing', 'elit.']
229
- >>> TextWrapper(width=15).wrap(LOREM_IPSUM_WORDS, return_details=True)
230
- {'wrapped': ['Lorem ipsum', 'odor amet,', 'consectetuer', 'adipiscing', 'elit.'], 'indiced': {4}}
266
+ >>> txtwrap.wrap(txtwrap.LOREM_IPSUM_WORDS, width=20)
267
+ ['Lorem ipsum odor', 'amet, consectetuer', 'adipiscing elit.']
268
+ >>> wrapped_info = txtwrap.wrap(txtwrap.LOREM_IPSUM_WORDS, width=20, return_details=True)
269
+ >>> start_lines = wrapped_info['start_lines']
270
+ >>> end_lines = wrapped_info['end_lines']
271
+ >>> wrapped_info
272
+ {'wrapped': ['Lorem ipsum odor', 'amet, consectetuer', 'adipiscing elit.'], 'start_lines': [1], 'end_lines': [3]}
273
+ >>> wrapped_info['wrapped'][start_lines[0] - 1]
274
+ 'Lorem ipsum odor'
275
+ >>> wrapped_info['wrapped'][end_lines[0] - 1]
276
+ 'adipiscing elit.'
231
277
  ```
232
278
 
233
279
  <h1></h1>
234
280
 
235
281
  #### **`align(text, return_details=False)`**
236
- Returns a list of tuples, where each tuple contains `(xPosition, yPosition, text)`, representing the wrapped text along with its
237
- coordinates.
282
+ Returns a list of tuples, where each tuple contains `(xPosition, yPosition, text)`, representing the wrapped text along
283
+ with its coordinates.
238
284
  > Note: [`sizefunc`](#sizefunc) must return both width and height.
239
285
 
240
286
  If `return_details=True`, returns a dictionary containing:
241
287
  - `'aligned'`: A list of wrapped text with coordinate data.
242
- - `'wrapped'`: The result from wrap.
243
- - `'indiced'`: The indices of line breaks.
244
- - `'size'`: The calculated text size.
288
+ - `'wrapped'`: A list of wrapped text fragments.
289
+ - `'start_lines'`: A list of indices marking the start of line.
290
+ - `'end_lines'`: A list of indices marking the end of line.
291
+ - `'size'`: A calculated text size.
245
292
 
246
293
  For example:
247
294
  ```py
248
- >>> TextWrapper(width=20).align(LOREM_IPSUM_WORDS)
295
+ >>> txtwrap.align(txtwrap.LOREM_IPSUM_WORDS, width=20)
249
296
  [(0, 0, 'Lorem ipsum odor'), (0, 1, 'amet, consectetuer'), (0, 2, 'adipiscing elit.')]
250
- >>> TextWrapper(width=20).align(LOREM_IPSUM_WORDS, return_details=True)
297
+ >>> aligned_info = txtwrap.align(txtwrap.LOREM_IPSUM_WORDS, width=20, return_details=True)
298
+ >>> start_lines = aligned_info['start_lines']
299
+ >>> end_lines = aligned_info['end_lines']
300
+ >>> aligned_info
251
301
  {'aligned': [(0, 0, 'Lorem ipsum odor'), (0, 1, 'amet, consectetuer'), (0, 2, 'adipiscing elit.')], 'wrapped': [
252
- 'Lorem ipsum odor', 'amet, consectetuer', 'adipiscing elit.'], 'indiced': {2}, 'size': (18, 3)}
302
+ 'Lorem ipsum odor', 'amet, consectetuer', 'adipiscing elit.'], 'start_lines': [1], 'end_lines': [3], 'size': (18, 3)}
303
+ >>> aligned_info['wrapped'][start_lines[0] - 1]
304
+ 'Lorem ipsum odor'
305
+ >>> aligned_info['wrapped'][end_lines[0] - 1]
306
+ 'adipiscing elit.'
253
307
  ```
254
308
 
255
309
  <h1></h1>
256
310
 
257
311
  #### **`fillstr(text)`**
258
312
  Returns a string with wrapped text formatted for monospace fonts.
259
- > Note: [`width`](#width), [`line_padding`](#line_padding), and the output of [`sizefunc`](#sizefunc) (size or just length) must return `int`,
260
- not `float`!
313
+ > Note: [`width`](#width), [`line_padding`](#line_padding), and the output of [`sizefunc`](#sizefunc)
314
+ (size or just length) must return `int`, not `float`!
261
315
 
262
316
  For example:
263
317
  ```py
264
- >>> s = TextWrapper(width=20).fillstr(LOREM_IPSUM_WORDS)
318
+ >>> s = txtwrap.fillstr(txtwrap.LOREM_IPSUM_WORDS, width=20)
265
319
  >>> s
266
320
  'Lorem ipsum odor \namet, consectetuer\nadipiscing elit. '
267
321
  >>> print(s)
@@ -278,7 +332,7 @@ if truncated.
278
332
 
279
333
  For example:
280
334
  ```py
281
- >>> TextWrapper(width=20).shorten(LOREM_IPSUM_WORDS)
335
+ >>> txtwrap.shorten(txtwrap.LOREM_IPSUM_WORDS, width=20)
282
336
  'Lorem ipsum odor...'
283
337
  ```
284
338
 
@@ -301,12 +355,13 @@ def render_wrap(
301
355
  color: pygame.Color,
302
356
  background: Optional[pygame.Color] = None,
303
357
  line_padding: int = 0,
304
- method: Literal['word', 'mono'] = 'word',
358
+ wrap_mode: Literal['word', 'mono'] = 'word',
305
359
  alignment: Literal['left', 'center', 'right', 'fill', 'fill-left', 'fill-center', 'fill-right'] = 'left',
306
360
  placeholder: str = '...',
307
361
  max_lines: Optional[int] = None,
308
- preserve_empty: bool = True,
362
+ preserve_empty_lines: bool = True,
309
363
  minimum_width: bool = True,
364
+ drop_separator: bool = False,
310
365
  justify_last_line: bool = False,
311
366
  break_on_hyphens: bool = True
312
367
 
@@ -316,12 +371,13 @@ def render_wrap(
316
371
  text=text,
317
372
  width=width,
318
373
  line_padding=line_padding,
319
- method=method,
374
+ mode=wrap_mode,
320
375
  alignment=alignment,
321
376
  placeholder=placeholder,
322
377
  max_lines=max_lines,
323
- preserve_empty=preserve_empty,
378
+ preserve_empty_lines=preserve_empty_lines,
324
379
  minimum_width=minimum_width,
380
+ drop_separator=drop_separator,
325
381
  justify_last_line=justify_last_line,
326
382
  break_on_hyphens=break_on_hyphens,
327
383
  return_details=True,
@@ -1,19 +1,21 @@
1
1
  # TxTWrap🔡
2
2
  A tool for wrapping and filling text.🔨
3
3
 
4
- Version: **2.3.2** <br>
5
- Python requires version: **3.3.0+** <br>
6
- Python stub file requires version: **3.8.0+**
4
+ Package version: **3.0.1** <br>
5
+ Python requires version: **>=3.0.0** <br>
6
+ Python stub file requires version: **>=3.5.0** <br>
7
7
 
8
8
  - [`LOREM_IPSUM_WORDS`](#lorem-ipsum)
9
9
  - [`LOREM_IPSUM_SENTENCES`](#lorem-ipsum)
10
10
  - [`LOREM_IPSUM_PARAGRAPHS`](#lorem-ipsum)
11
- - [`TextWrapper`](#textwrapper) (🔨 Fixed)
12
- - [`sanitize`](#sanitizetext)
13
- - [`wrap`](#wraptext-return_detailsfalse)
14
- - [`align`](#aligntext-return_detailsfalse)
15
- - [`fillstr`](#fillstrtext)
16
- - [`shorten`](#shortentext)
11
+ - [`SEPARATOR_WHITESPACE`](#separators)
12
+ - [`SEPARATOR_ESCAPE`](#separators)
13
+ - [`TextWrapper`](#textwrapper) (🛠️ Fixed)
14
+ - [`sanitize`](#sanitizetext) (🛠️ Fixed)
15
+ - [`wrap`](#wraptext-return_detailsfalse) (🛠️ Fixed)
16
+ - [`align`](#aligntext-return_detailsfalse) (🛠️ Fixed)
17
+ - [`fillstr`](#fillstrtext) (🛠️ Fixed)
18
+ - [`shorten`](#shortentext) (🛠️ Fixed)
17
19
 
18
20
  # Documents📄
19
21
  This module is inspired by the [`textwrap`](https://docs.python.org/3/library/textwrap.html) module, which provides
@@ -25,7 +27,10 @@ filling _monospace fonts_ but also for other font types, such as _Arial_, _Times
25
27
 
26
28
  <h1></h1>
27
29
 
28
- ## Lorem ipsum
30
+ ## Constants
31
+ _File: **txtwrap.constants**_
32
+
33
+ ### Lorem ipsum
29
34
  ```py
30
35
  LOREM_IPSUM_WORDS
31
36
  LOREM_IPSUM_SENTENCES
@@ -38,24 +43,41 @@ A _Lorem Ipsum_ collection of words, sentences, and paragraphs that can be used
38
43
 
39
44
  <h1></h1>
40
45
 
46
+ ### Separators
47
+ ```py
48
+ SEPARATOR_WHITESPACE
49
+ SEPARATOR_ESCAPE
50
+ ```
51
+ A collection of separators that can be used to separate text.
52
+ - `SEPARATOR_WHITESPACE` contains whitespace characters.
53
+ - `SEPARATOR_ESCAPE` contains whitespace characters including `'\0'`, `'\a'`, and `'\b'`.
54
+
55
+ To use this, assign this constant to the [`separator`](#separator) parameter.
56
+
57
+ <h1></h1>
58
+
41
59
  ## `TextWrapper`
60
+ _File: **txtwrap.wrapper**_
61
+
42
62
  ```py
43
63
  class TextWrapper:
64
+
44
65
  def __init__(
45
66
  self,
46
67
  width: Union[int, float] = 70,
47
68
  line_padding: Union[int, float] = 0,
48
- method: Literal['mono', 'word'] = 'word',
69
+ mode: Literal['mono', 'word'] = 'word',
49
70
  alignment: Literal['left', 'center', 'right', 'fill', 'fill-left', 'fill-center', 'fill-right'] = 'left',
50
71
  placeholder: str = '...',
51
72
  fillchar: str = ' ',
52
73
  separator: Optional[Union[str, Iterable[str]]] = None,
53
74
  max_lines: Optional[int] = None,
54
- preserve_empty: bool = True,
75
+ preserve_empty_lines: bool = True,
55
76
  minimum_width: bool = True,
77
+ drop_separator: bool = False,
56
78
  justify_last_line: bool = False,
57
79
  break_on_hyphens: bool = True,
58
- sizefunc: Optional[Callable[[str], Union[Tuple[Union[int, float], Union[int, float]], int, float]]] = None,
80
+ sizefunc: Optional[Callable[[str], Union[Tuple[Union[int, float], Union[int, float]], int, float]]] = None
59
81
  ) -> None
60
82
  ```
61
83
  A class that handles all functions available in this module. Each keyword argument corresponds to its attribute.
@@ -88,10 +110,10 @@ as each attribute has type checking, which may reduce performance.
88
110
 
89
111
  <h1></h1>
90
112
 
91
- #### **`method`**
92
- (Default: `'word'`) The wrapping method. Available options:
93
- - `'mono'` method wraps text character by character.
94
- - `'word'` method wraps text word by word.
113
+ #### **`mode`**
114
+ (Default: `'word'`) The wrapping mode. Available options:
115
+ - `'mono'` make text wraps character by character.
116
+ - `'word'` make text wraps word by word.
95
117
 
96
118
  <h1></h1>
97
119
 
@@ -133,7 +155,7 @@ as each attribute has type checking, which may reduce performance.
133
155
 
134
156
  <h1></h1>
135
157
 
136
- #### **`preserve_empty`**
158
+ #### **`preserve_empty_lines`**
137
159
  (Default: `True`) Retains empty lines in the wrapped text.
138
160
 
139
161
  <h1></h1>
@@ -144,6 +166,11 @@ enabling this attribute removes unnecessary empty space.
144
166
 
145
167
  <h1></h1>
146
168
 
169
+ #### **`drop_separator`**
170
+ (Default: `False`) Removes excess separators from between words one at a time.
171
+
172
+ <h1></h1>
173
+
147
174
  #### **`justify_last_line`**
148
175
  (Default: `False`) Determines whether the last line should also be justified
149
176
  (applies only to `fill-...` alignments).
@@ -170,20 +197,29 @@ If the function calculates only the width, it must return a single value of type
170
197
 
171
198
  > Note: All methods can be called outside the [`TextWrapper`](#textwrapper) like external functions.
172
199
 
200
+ For example:
201
+ ```py
202
+ >>> txtwrap.TextWrapper(20, placeholder='[...]').shorten("Hello World!")
203
+ ```
204
+ is equivalent to:
205
+ ```py
206
+ >>> txtwrap.shorten("Hello World!", 20, placeholder='[...]')
207
+ ```
208
+
173
209
  <h1></h1>
174
210
 
175
211
  #### **`copy`**
176
- Creates and returns a copy of the [`TextWrapper`](#textwrapper) object.
212
+ Creates and returns a copy of the [`TextWrapper`](#textwrapper) object. (External function using `copy.copy`)
177
213
 
178
214
  <h1></h1>
179
215
 
180
216
  #### **`sanitize(text)`**
181
217
  Removes excessive characters from [`separator`](#separator) and replaces them with the [`fillchar`](#fillchar)
182
- character.
218
+ character. (It doesn't matter whether [`drop_separator`](#drop_separator) is `False` or `True`)
183
219
 
184
220
  For example:
185
221
  ```py
186
- >>> TextWrapper().sanitize("\tHello \nWorld!\r ")
222
+ >>> txtwrap.sanitize("\tHello \nWorld!\r ")
187
223
  'Hello World!'
188
224
  ```
189
225
 
@@ -192,48 +228,64 @@ For example:
192
228
  #### **`wrap(text, return_details=False)`**
193
229
  Returns a list of wrapped text strings. If `return_details=True`, returns a dictionary containing:
194
230
  - `'wrapped'`: A list of wrapped text fragments.
195
- - `'indiced'`: A set of indices marking the end of line (starting from `0`, like programming indices).
231
+ - `'start_lines'`: A list of indices marking the start of line.
232
+ - `'end_lines'`: A list of indices marking the end of line.
196
233
 
197
234
  For example:
198
235
  ```py
199
- >>> TextWrapper(width=15).wrap(LOREM_IPSUM_WORDS)
200
- ['Lorem ipsum', 'odor amet,', 'consectetuer', 'adipiscing', 'elit.']
201
- >>> TextWrapper(width=15).wrap(LOREM_IPSUM_WORDS, return_details=True)
202
- {'wrapped': ['Lorem ipsum', 'odor amet,', 'consectetuer', 'adipiscing', 'elit.'], 'indiced': {4}}
236
+ >>> txtwrap.wrap(txtwrap.LOREM_IPSUM_WORDS, width=20)
237
+ ['Lorem ipsum odor', 'amet, consectetuer', 'adipiscing elit.']
238
+ >>> wrapped_info = txtwrap.wrap(txtwrap.LOREM_IPSUM_WORDS, width=20, return_details=True)
239
+ >>> start_lines = wrapped_info['start_lines']
240
+ >>> end_lines = wrapped_info['end_lines']
241
+ >>> wrapped_info
242
+ {'wrapped': ['Lorem ipsum odor', 'amet, consectetuer', 'adipiscing elit.'], 'start_lines': [1], 'end_lines': [3]}
243
+ >>> wrapped_info['wrapped'][start_lines[0] - 1]
244
+ 'Lorem ipsum odor'
245
+ >>> wrapped_info['wrapped'][end_lines[0] - 1]
246
+ 'adipiscing elit.'
203
247
  ```
204
248
 
205
249
  <h1></h1>
206
250
 
207
251
  #### **`align(text, return_details=False)`**
208
- Returns a list of tuples, where each tuple contains `(xPosition, yPosition, text)`, representing the wrapped text along with its
209
- coordinates.
252
+ Returns a list of tuples, where each tuple contains `(xPosition, yPosition, text)`, representing the wrapped text along
253
+ with its coordinates.
210
254
  > Note: [`sizefunc`](#sizefunc) must return both width and height.
211
255
 
212
256
  If `return_details=True`, returns a dictionary containing:
213
257
  - `'aligned'`: A list of wrapped text with coordinate data.
214
- - `'wrapped'`: The result from wrap.
215
- - `'indiced'`: The indices of line breaks.
216
- - `'size'`: The calculated text size.
258
+ - `'wrapped'`: A list of wrapped text fragments.
259
+ - `'start_lines'`: A list of indices marking the start of line.
260
+ - `'end_lines'`: A list of indices marking the end of line.
261
+ - `'size'`: A calculated text size.
217
262
 
218
263
  For example:
219
264
  ```py
220
- >>> TextWrapper(width=20).align(LOREM_IPSUM_WORDS)
265
+ >>> txtwrap.align(txtwrap.LOREM_IPSUM_WORDS, width=20)
221
266
  [(0, 0, 'Lorem ipsum odor'), (0, 1, 'amet, consectetuer'), (0, 2, 'adipiscing elit.')]
222
- >>> TextWrapper(width=20).align(LOREM_IPSUM_WORDS, return_details=True)
267
+ >>> aligned_info = txtwrap.align(txtwrap.LOREM_IPSUM_WORDS, width=20, return_details=True)
268
+ >>> start_lines = aligned_info['start_lines']
269
+ >>> end_lines = aligned_info['end_lines']
270
+ >>> aligned_info
223
271
  {'aligned': [(0, 0, 'Lorem ipsum odor'), (0, 1, 'amet, consectetuer'), (0, 2, 'adipiscing elit.')], 'wrapped': [
224
- 'Lorem ipsum odor', 'amet, consectetuer', 'adipiscing elit.'], 'indiced': {2}, 'size': (18, 3)}
272
+ 'Lorem ipsum odor', 'amet, consectetuer', 'adipiscing elit.'], 'start_lines': [1], 'end_lines': [3], 'size': (18, 3)}
273
+ >>> aligned_info['wrapped'][start_lines[0] - 1]
274
+ 'Lorem ipsum odor'
275
+ >>> aligned_info['wrapped'][end_lines[0] - 1]
276
+ 'adipiscing elit.'
225
277
  ```
226
278
 
227
279
  <h1></h1>
228
280
 
229
281
  #### **`fillstr(text)`**
230
282
  Returns a string with wrapped text formatted for monospace fonts.
231
- > Note: [`width`](#width), [`line_padding`](#line_padding), and the output of [`sizefunc`](#sizefunc) (size or just length) must return `int`,
232
- not `float`!
283
+ > Note: [`width`](#width), [`line_padding`](#line_padding), and the output of [`sizefunc`](#sizefunc)
284
+ (size or just length) must return `int`, not `float`!
233
285
 
234
286
  For example:
235
287
  ```py
236
- >>> s = TextWrapper(width=20).fillstr(LOREM_IPSUM_WORDS)
288
+ >>> s = txtwrap.fillstr(txtwrap.LOREM_IPSUM_WORDS, width=20)
237
289
  >>> s
238
290
  'Lorem ipsum odor \namet, consectetuer\nadipiscing elit. '
239
291
  >>> print(s)
@@ -250,7 +302,7 @@ if truncated.
250
302
 
251
303
  For example:
252
304
  ```py
253
- >>> TextWrapper(width=20).shorten(LOREM_IPSUM_WORDS)
305
+ >>> txtwrap.shorten(txtwrap.LOREM_IPSUM_WORDS, width=20)
254
306
  'Lorem ipsum odor...'
255
307
  ```
256
308
 
@@ -273,12 +325,13 @@ def render_wrap(
273
325
  color: pygame.Color,
274
326
  background: Optional[pygame.Color] = None,
275
327
  line_padding: int = 0,
276
- method: Literal['word', 'mono'] = 'word',
328
+ wrap_mode: Literal['word', 'mono'] = 'word',
277
329
  alignment: Literal['left', 'center', 'right', 'fill', 'fill-left', 'fill-center', 'fill-right'] = 'left',
278
330
  placeholder: str = '...',
279
331
  max_lines: Optional[int] = None,
280
- preserve_empty: bool = True,
332
+ preserve_empty_lines: bool = True,
281
333
  minimum_width: bool = True,
334
+ drop_separator: bool = False,
282
335
  justify_last_line: bool = False,
283
336
  break_on_hyphens: bool = True
284
337
 
@@ -288,12 +341,13 @@ def render_wrap(
288
341
  text=text,
289
342
  width=width,
290
343
  line_padding=line_padding,
291
- method=method,
344
+ mode=wrap_mode,
292
345
  alignment=alignment,
293
346
  placeholder=placeholder,
294
347
  max_lines=max_lines,
295
- preserve_empty=preserve_empty,
348
+ preserve_empty_lines=preserve_empty_lines,
296
349
  minimum_width=minimum_width,
350
+ drop_separator=drop_separator,
297
351
  justify_last_line=justify_last_line,
298
352
  break_on_hyphens=break_on_hyphens,
299
353
  return_details=True,
@@ -1,26 +1,29 @@
1
1
  from setuptools import find_packages, setup
2
2
 
3
- with open('README.md', encoding='utf-8') as readme:
4
- long_description = readme.read()
3
+ with open('README.md', 'r', encoding='utf-8') as file:
4
+ long_description = file.read()
5
5
 
6
6
  setup(
7
7
  name='txtwrap',
8
- version='2.3.2',
8
+ version='3.0.1',
9
9
  description='A tool for wrapping and filling text.',
10
10
  long_description=long_description,
11
11
  long_description_content_type='text/markdown',
12
12
  author='azzammuhyala',
13
13
  author_email='azzammuhyala@gmail.com',
14
14
  url='https://github.com/azzammuhyala/txtwrap',
15
+ project_urls={
16
+ 'Source': 'https://github.com/azzammuhyala/txtwrap',
17
+ 'Bug Tracker': 'https://github.com/azzammuhyala/txtwrap/issues'
18
+ },
15
19
  license='MIT',
16
- python_requires='>=3.3',
20
+ python_requires='>=3.0',
17
21
  packages=find_packages(),
18
22
  include_package_data=True,
19
23
  keywords=['wrap', 'wrapper', 'wrapping', 'wrapped', 'text wrap', 'text wrapper', 'text wrapping', 'text wrapped'],
20
24
  classifiers=[
21
25
  'Programming Language :: Python',
22
26
  'Programming Language :: Python :: 3',
23
- 'Programming Language :: Python :: 3.3',
24
27
  'Topic :: Software Development :: Libraries :: Python Modules',
25
28
  'Topic :: Text Processing',
26
29
  'Topic :: Text Processing :: Filters'
@@ -0,0 +1,38 @@
1
+ """
2
+ A tool for wrapping and filling text.
3
+
4
+ See txtwrap module documentation on [GitHub](https://github.com/azzammuhyala/txtwrap) or on
5
+ [PyPi](https://pypi.org/project/txtwrap) for details.
6
+ """
7
+
8
+ # Supports only in Python>=3.0.0
9
+
10
+ from . import constants as constants
11
+ from . import identities as identities
12
+ from . import wrapper as wrapper
13
+
14
+ from .identities import __version__, __author__, __license__
15
+
16
+ from .constants import (
17
+ LOREM_IPSUM_WORDS, LOREM_IPSUM_SENTENCES, LOREM_IPSUM_PARAGRAPHS,
18
+ SEPARATOR_WHITESPACE, SEPARATOR_ESCAPE
19
+ )
20
+
21
+ from .wrapper import (
22
+ TextWrapper,
23
+ sanitize, wrap, align, fillstr, shorten
24
+ )
25
+
26
+ __all__ = [
27
+ 'LOREM_IPSUM_WORDS',
28
+ 'LOREM_IPSUM_SENTENCES',
29
+ 'LOREM_IPSUM_PARAGRAPHS',
30
+ 'SEPARATOR_WHITESPACE',
31
+ 'SEPARATOR_ESCAPE',
32
+ 'TextWrapper',
33
+ 'sanitize',
34
+ 'wrap',
35
+ 'align',
36
+ 'fillstr',
37
+ 'shorten'
38
+ ]