/csutils

Collection of Python modules to ease some basic tasks like dealing with textfiles.

Primary LanguagePythonMIT LicenseMIT

👀 csutils - Package for Python 3.8+

This repository contains a collection of handy Python modules to ease some basic tasks like operating on textfiles or to modify colors and cursor position of the Windows terminal. The package is provided as is and may or may not be updated and extended in the future depending on available resources and needs.

Installation (Linux/Windows WSL)

The setup below assumes that Python 3, PIP and venv are already installed on your Linux or Windows WSL system.

mkdir csutils
cd ./csutils
python3 -m venv .venv
source .venv/bin/activate
pip install https://github.com/cwsoft/csutils/archive/main.zip
clear

Basic usage

Create a test.py file in the csutils virtual environment folder and paste in the following Python code. Then invoke the script as python3 ./test.py.

from csutils.textparser import Textparser
from csutils.cterm import Colors, Styles, Cursor, Terminal

if __name__ == "__main__":
    try:
        # Initialize terminal (clear screen, set cursor position to row=1, col=1.)
        Terminal.initialize(forecolor=Colors.RESET, backcolor=Colors.RESET)
        
        # Hide cursor.
        Cursor.disable()
        input("Press ENTER to continue (the cursor is disabled).")

        # Change foreground color to GREEN and text style to bold and underline.
        Terminal.set_color(forecolor=Colors.GREEN)
        Terminal.set_style(Styles.BOLD, Styles.UNDERLINE)
        print("All text outputs below are green, bold and underline.")

        # Initiate textpareser object with specified textfile.
        tp = Textparser(r"./your_input_file.txt")
        print(tp)

    except KeyboardInterrupt:
        pass

    finally:
        Cursor.enable()
        Terminal.set_style(Styles.RESET)
        print("\nCursor enabled and colors and styles reset to default values.")

For details, please have a look into the API documentation and the examples files in the docs folder of this repository. To check your system compatibility, you may want to run the unittests provided in the tests folder.

Have fun cwsoft