le717 / PatchIt

PatchIt! The simple way to package and install LEGO® Racers mods

Home Page:https://le717.github.io/PatchIt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add new lines in Patch Description

le717 opened this issue · comments

Feature

For a while now, I've wanted to add a way to insert new lines in the Patch Description. Right now, it is an absolute WYSIWYG deal: if a word is not completed by the end of the line, you just have to keep typing, and however the word is cut off is how it is displayed during Installation.

Comments

I would need to use some character to designate a new line, one that would not force character escaping, but is still easy to type. Further more, it should be one that can typed on any keyboard, laptop, desktop, or tablet, full-size or not.

The Implementation

I know exactly how I will implement this feature, and the character I will use. I'll use an horizontal bar (|) to denote a new line, as it can be typed on any keyboard, and many gaming utilities already use it to denote a new line, so it wouldn't be a special-case thing. As for the code, I just have to detect the presence of any bars, replace them with the new line symbol (\n) using the built-in replace function, then write the description to the PiP File. This does not edit the PiP File Format, as it it already designed and coded to exist on however many lines are left in the PiP.
The following code and it's interpretation shows exactly how it works.

desc = input("Description: ")
print(desc)

# Check for the presence of | in the input,
# and replace it with a new line
if "|" in desc:
    newdesc = desc.replace("|", "\n")

# Print the updated text
print(newdesc)

# Display iin a list to show a diagram of the new text
print([newdesc])

# Now, let's write the description
with open("MyPatch.txt", "wt") as f:
    f.write(desc)   

# ...And read it back
with open("MyPatch.txt", "rt") as f:
    lines = f.read()

# And display the reading   
print(lines)

# Again, display in a list so we can see the diagram of the text
print([lines])
# Tada! The new lines are preserved. :)

And the code, when run

Description: MyPatch is an example PatchIt! Patch whose description spans multiple lines.|It uses an horizontal bar to denote a new line. Before it is written, the bar is replaced with the new line|symbol so new lines are written||Hey, look! I am | three lines before the last paragraph!
"MyPatch is an example PatchIt! Patch whose description spans multiple lines.
It uses an horizontal bar to denote a new line. Before it is written, the bar is replaced with the new line
symbol so new lines are written"

Hey, look! I am 
 three lines before the last paragraph!"
['"MyPatch is an example PatchIt! Patch whose description spans multiple lines.\nIt uses an horzintal bar to denote a new line. Before it is written, the bar is replaced with the new line\nsymbol so new lines are written\n\nHey, look! I am \n three lines before the last paragraph!"']

This feature was added in commit 9d86695. You can now add new lines in a Patch Description! 😀