Metadata-Version: 2.4
Name: sectiprint
Version: 2.0.1
Summary: Makes printing pretty & easier to follow
Author: Owen Cocjin
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# SectiPrint
A custom terminal printing library, making printing prettier. Tries to make tracing which function/object did what easier.

---

# Installation

Install using Pip:

```
pip install sectiprint
```

## Usage

### Basic Printing

To use the `sectiprint` library, you need to first create a `RootPrinter()` instance:

```python3
import sectiprint

#"name" is arbitrary
#"level" is the minimum level to print
say = sectiprint.RootPrinter(name="main", level=printer.DEBUG)
```

Once you have a printer instance, you will have access to the default print levels:

- debug [level=0]
- info [level=10]
- warning [level=20]
- error [level=30]

Each print level has a unique colour. To add your own print level, see [Advanced: Adding Custom Print Layers](#adding-custom-print-layers)

Now you can call each print layer as required:

```python3
say.debug("This is a debug statement")
say("This is the default layer, which is 'info'")
```

Notice how you can directly call the Printer object? This is because when it's called it passes the message to the default print layer, which is "info".

The default layer can be changed by pointing
`Printer.default` to another print layer:

```python3
#This does not affect the print level
say.default = say.error

say("This will print as an error!")
```

### Printing In Other Scopes

The power of this lib comes from how printing inside other scopes works. If you wrap a function or class method with `@sectiprint.SubLayer` it will add a header to the output that shows the path that was takes to get to the current scope:

```python3
import sectiprint

@sectiprint.SubLayer
def funcScope():
	say("This is in another scope!")

say = sectiprint.RootPrinter(name="scopes", level=sectiprint.INFO)

say("This is in the top scope!")
funcScope()
```

This outputs:

![Scope example output](./ReadmeImgs/scope_output.bmp)

---

## Advanced:

Below are some advanced use cases of the Printer lib

### Adding Custom Print Layers

There can be cases where you'll want to add your own print layers. This can be easily done by creating a new `PrintLevel` object and assigning it to a new attribute in the Root Printer object. You would then call this attribute similar to `Printer.info` and other calls:

```python
import sectiprint

say = sectiprint.RootPrinter("main", level=5)
say.ok = sectiprint.PrintLayer(
	printer = say,
	level = 5,
	colour = print.GREEN
)

say.ok("This is our new print layer!")
```

In this case, we create the layer "ok" which prints text as green on layer 5. The `GREEN` var already exists in the `sectiprint` library, but you can use [ANSI Escape Codes](https://gist.github.com/JBlond/2fea43a3049b38287e5e9cefc87b2124) to generate your own colours or designs. For example, pass the string `'\033[95m'` as the `colour` to produce purple output!

### Sections:
You can add "sections" which prints an additional metadata-like label to help clarify where in the code you are. This is useful when you want to separate your code by logical sections, but don't want them as separate functions

```
import sectiprint
say = sectiprint.RootPrinter("main")

say("Root print")

say.section("New Section")
say("In the new section")
```
This produces the following output:
![Section example output](./ReadmeImgs/section_example.png)
