Skip to main content

Fluent string builder for micron markup

Project description

micron-builder

micron-builder is a small Python library for building micron markup strings programmatically.
It provides a fluent API for composing text fragments, headers, separators, and styles without manually handling all the Micron markup symbols.


✨ Features

  • Fluent API for building Micron markup strings
  • Support for:
    • Text fragments with color, background color, and formatting (bold, italic, underline)
    • Headers with indent levels
    • Separators and line breaks
    • Links (address + page)
    • Alignment (center, right)
    • Padding around text
  • Works with raw strings or the built-in Color enum
  • Easy to extend and compose

📦 Installation

pip install micron-builder

🚀 Usage

Here’s a quick example of how to use MicronBuilder:

from micron import MicronBuilder
from micron.colors import Color

builder = (
    MicronBuilder()
    .header("Welcome!", indent_level=1)
    .text(
        "This is bold red text",
        bold=True,
        color=Color.RED,
    )
    .breakline()
    .text("Centered and underlined", center=True, underline=True)
    .separator("=")
    .text(
        "Clickable link",
        address_link="aaabbbcccddd",
        page_link="index.mu",
        italic=True,
    )
)

print(builder.build())

This would output Micron markup like:


>Welcome!
`Ff00`!This is bold red text`!`f

`c
`_Centered and underlined`_
`a
-=

`*`[Clickable link`aaabbbcccddd:/page/index.mu]`*

Which renders appropriately in Micron-compatible renderers.

New: use the raw(...) method to insert unescaped Micron markup directly

from micron import MicronBuilder
from micron.colors import Color

builder = (
    MicronBuilder()
    .text("Some text", color=Color.GREEN)
    # raw() inserts the provided string exactly as-is into the output,
    # useful for injecting already-formed Micron markup.
    .raw("`!`Ff00This is raw micron markup`f`!")
)

print(builder.build())

This will include the raw markup verbatim in the output:

`F070Some text`f
`!`Ff00This is raw micron markup`f`!

🎨 Colors

Colors can be specified as:

  • A 3-digit hex string (e.g. "f00", "0ff")

  • A Color enum value:

    from micron.colors import Color
    
    MicronBuilder().text("Hello", color=Color.AQUA)
    

🛠 Development

Clone the repo and install in editable mode:

git clone https://github.com/neoemit/micron-builder.git
cd micron-builder
pip install -e .

Run tests (if you add them later):

pytest

📜 License

MIT License.

Feel free to use in your own projects.

🙌 Contributing

Pull requests, bug reports, and suggestions are welcome!

Open an issue or submit a PR on GitHub.

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

micron_builder-0.1.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

micron_builder-0.1.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file micron_builder-0.1.3.tar.gz.

File metadata

  • Download URL: micron_builder-0.1.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for micron_builder-0.1.3.tar.gz
Algorithm Hash digest
SHA256 313b239a0a9f7d17ad7a83a01cef09503f6f21dedd4d52a9f1b7efe4a5e052a4
MD5 2092b982459c9c624c2c3dc494477fb3
BLAKE2b-256 590ea924b49a158c9bc8d9de6d7774d747b7dbf6709d1d40997691e2da50c300

See more details on using hashes here.

File details

Details for the file micron_builder-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: micron_builder-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for micron_builder-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 adba20a06d3ccacae9c9e2a2f6560a277cc45fd5cb752dd35912b10324a5e5fa
MD5 2a98551f38c1f6a75716606bd6b12c79
BLAKE2b-256 f85234012994b084feae6bc374676700ec7a88e5ff8db66f2847cff1c8558208

See more details on using hashes here.

Supported by

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