ka-puna / comfyui-yanc

MIT License
7 stars 1 forks source link

[Node Suggestion] String Word Warp #1

Open pto2k opened 11 months ago

pto2k commented 11 months ago

Hello, Thanks for making and sharing these nodes. I've been using some of them, and they are helpful!

If I may, I'd like to suggest a new 'Word Warp' node for string operations. Like your Truncate String node, this 'Word Warp' node would take one string and one 'Length' var, and able to convert a long string into a multiline string.

My use case for that is for combining prompt text over an image. So I need to keep the text at a limited width.

Thank you for your consideration.

Have a nice day.

ka-puna commented 11 months ago

Hi pto2k,

I think I can use the textwrap module's wrap function to meet most of your needs. It can break a string by word into multiple strings, which I can join as separate lines in one string. I think I will call the node, "Word Wrap String." See https://docs.python.org/3/library/textwrap.html#textwrap.wrap for more information about the wrap function and its arguments.

Let me know how else you would like the Word Wrap String node to function, with examples. In particular, I would like to know what options should the node have as widgets in ComfyUI, and the default values for those widgets.

The image below demonstrates that the default wrap behavior is probably not desirable for an input with paragraphs. example I do not know why the screenshot collapses the input text in Multiline String.

The input text is the first 3 paragraphs of Frankenstein, with a line between the first two paragraphs and no line between the second and third paragraphs. Several words at the start of each paragraph are capitalized for emphasis.

pto2k commented 11 months ago

Thanks! The screenshot is good enough for what I need. I think I'll adjust the width according to the font size anyway. So the default value of 70 looks okay.

ka-puna commented 11 months ago

I have created a branch https://github.com/ka-puna/comfyui-yanc/tree/add-node-word-wrap-string that adds the node, with option widgets to keep the original lines or break on hyphen.

Let me know if this needs changes or not.