Skip to main content

A module to format strings. Length and alignment of lines can be specified. In the new version is resolved the issue that caused the string to be splitted in single characters rather than in words. Also a check has been added to establish if the input is a list or a string in order to perform the correct splitting method.

Project description

Textlinebreaker

PyPI - Version PyPI - Python Version Downloads PyPI - License

Description

Text Line Breaker is a Python script that takes a string of text and breaks it into lines of a specified maximum width. This tool is particularly useful for formatting and displaying text in a terminal.

Features

  • Split text lines to fit within a specified maximum width.
  • Choose alignment options for the text (left, center, right).
  • Adjust the maximum width (default value is the terminal width).

Latest Version 0.2.0

  • Added new parameters ("min", "2words", "max") to set different lines width.
  • Improved algorithm to better split the input in the desired lenght lines.

Table of Contents

Getting Started

Prerequisites

This script relies on the Python standard library and does not require any additional dependencies.

Installation

  • Install the package with pip
  pip install textlinebreaker
  • or upgrade it with
  pip install --upgrade textlinebreaker
  • Import the package in your program
  from textlinebreaker import split_line

Usage

This function takes a long string of text as input and breaks it into lines according to the specified maximum width. The default length is the width of the terminal.

Parameters

The split_line function accepts the following parameters:

  • line: is the main argument, it's the text that needs to be broken down.
    • allowed values: strings, list of strings
  • max_width: allows to set the max length of text on a line.
    • allowed values: integers, "min", "2words", "max"
    • default value = "max" (terminal width)
  • alignment: allows to change the alignment of the text inside the frame.
    • allowed values: "left", "centre", "center", "right"
    • default value = "left"

Examples

Here's an example of how to use the split_line function:

from textlinebreaker import split_line

text = "This is an example of text line breaking using the Text Line Breaker script."
lines = split_line(text, max_width=30, alignment="center")

for line in lines:
  print(line)

Output:

 This is an example of text 
line breaking using the Text 
    Line Breaker script.     

Contributing

If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository on GitHub.
  2. Clone the fork to your local machine.
  3. Create a new branch for your feature or bug fix.
  4. Make your changes and commit them.
  5. Push the changes to your fork on GitHub.
  6. Create a pull request to the original repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textlinebreaker-0.2.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

textlinebreaker-0.2.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file textlinebreaker-0.2.0.tar.gz.

File metadata

  • Download URL: textlinebreaker-0.2.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for textlinebreaker-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b5bf513fe7f37561605526527c28886ac372a0226b7c3c7fef8dcb6e26184382
MD5 f52975f678e6f0c2d27ca73b9a543a5f
BLAKE2b-256 6f2d7ec969244487b0e039e5369d08a642c0c0a414983676641ac728b8e75422

See more details on using hashes here.

File details

Details for the file textlinebreaker-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for textlinebreaker-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bcfa36e58e409928b6f1810d9157e0b14cd697c42f940ece42d8c73017013ca1
MD5 6af2f0cfe228a0994ac8fdc8ef7085b7
BLAKE2b-256 9530bf04569feb2efafc0ee7523f034f4b2d13a1858ab29d6aea60edafdc5bb8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page