Skip to content

ANSI String editing and formatting library for MU*'s, in Python

License

Notifications You must be signed in to change notification settings

strikaco/mudstring-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Volund's MudString library for Python

CONTACT INFO

Name: Volund

Email: volundmush@gmail.com

PayPal: volundmush@gmail.com

Discord: Volund#1206

Patreon: https://www.patreon.com/volund

Home Repository: https://github.com/volundmush/mudstring-python

TERMS AND CONDITIONS

MIT license. In short: go nuts, but give credit where credit is due.

Please see the included LICENSE.txt for the legalese.

INTRO

MUD (Multi-User Dungeon) games and their brethren like MUSH, MUX, MUCK, and MOO (look 'em up!) use various ANSI features to provide colors to clients. Sadly there aren't many libraries out there which allow advanced manipulation of such text which preserve the formatting already applied to it. This attempts to address this problem.

mudstring is built upon the existing library, rich, using monkey-patching to hack in support for MXP (Mud eXtension Protocol). So, in order to use this library effectively, one must familiarize themselves with Rich. Rich is awesome, so be sure and do that soon.

FEATURES

  • Everything Rich can do. Seriously, check it out...
  • MXP Support.
  • Encodings library, containing fully-working examples for how to implement various ANSI systems used by existing games.

OKAY, BUT HOW DO I USE IT?

Glad you asked.

Early on in your program, you should...

import mudstring
mudstring.install()

This will monkey-patch Rich for this process, replacing a few classes with ones from MudString in a way that will still allow Rich to do everything it normally does. From here on out, though, importing from Rich will net you the patched versions of classes like Style, Text, and Console.

Afterwards, instantiating a MudConsole and directing some output to an output buffer is this easy.

# this will get the MudCOnsole and MudText if install() has been run!
from rich import Console
from rich.text import Text
from mudstring.util import OutBuffer

buffer = bytearray()

out = OutBuffer(buffer)

con = Console(color_system="256", mxp=True, soft_wrap=True, file=out)

con.print(Text("Have some red text!", style="red"))

Afterwards, buffer will contain the formatted red text.

Note that MudString's Text class for Rich implements a great deal more of the Python String API than Rich's original version, allowing for advanced text formatting - though, unfortunately, no f-strings or str.format() - it won't preserve the styling...

FAQ

Q: This is cool! How can I help?
A: Patreon support is always welcome. If you can code and have cool ideas or bug fixes, feel free to fork, edit, and pull request!

Q: I found a bug! What do I do?
A: Post it on this GitHub's Issues tracker. I'll see what I can do when I have time. ... or you can try to fix it yourself and submit a Pull Request. That's cool too.

Q: But... I want a MUD! Where do I start making a MUD?
A: Coming soon...

Special Thanks

  • The absolutely awesome lunatics who wrote PennMUSH's ANSI library.
  • The Evennia Project.
  • All of my Patrons on Patreon.
  • Anyone who contributes to this project or my other ones.
  • The Rich devs. That library is a godsend.

About

ANSI String editing and formatting library for MU*'s, in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%