mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-21 22:47:30 +08:00
Adding new StringFormat node (#13997)
This commit is contained in:
parent
6887165a9d
commit
7ec7b6ffe9
@ -1,10 +1,41 @@
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
import string
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
from comfy_api.latest import ComfyExtension, io
|
from comfy_api.latest import ComfyExtension, io
|
||||||
|
|
||||||
|
|
||||||
|
class StringFormat(io.ComfyNode):
|
||||||
|
@classmethod
|
||||||
|
def define_schema(cls) -> io.Schema:
|
||||||
|
autogrow = io.Autogrow.TemplateNames(
|
||||||
|
input=io.AnyType.Input("value"),
|
||||||
|
names=list(string.ascii_lowercase),
|
||||||
|
min=0,
|
||||||
|
)
|
||||||
|
return io.Schema(
|
||||||
|
node_id="StringFormat",
|
||||||
|
display_name="Format Text",
|
||||||
|
category="text",
|
||||||
|
search_aliases=["string", "format"],
|
||||||
|
description="Same as Python's string format method. Supports all of Python's format options and features.",
|
||||||
|
inputs=[
|
||||||
|
io.Autogrow.Input("values", template=autogrow),
|
||||||
|
io.String.Input("f_string", default="{a}", multiline=True),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
io.String.Output(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def execute(
|
||||||
|
cls, values: io.Autogrow.Type, f_string: str
|
||||||
|
) -> io.NodeOutput:
|
||||||
|
return io.NodeOutput(f_string.format(**values))
|
||||||
|
|
||||||
|
|
||||||
class StringConcatenate(io.ComfyNode):
|
class StringConcatenate(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def define_schema(cls):
|
def define_schema(cls):
|
||||||
@ -413,6 +444,7 @@ class StringExtension(ComfyExtension):
|
|||||||
@override
|
@override
|
||||||
async def get_node_list(self) -> list[type[io.ComfyNode]]:
|
async def get_node_list(self) -> list[type[io.ComfyNode]]:
|
||||||
return [
|
return [
|
||||||
|
StringFormat,
|
||||||
StringConcatenate,
|
StringConcatenate,
|
||||||
StringSubstring,
|
StringSubstring,
|
||||||
StringLength,
|
StringLength,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user