File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import re
22import json
3+ import string
34from typing_extensions import override
45
56from comfy_api .latest import ComfyExtension , io
67
78
9+ class StringFormat (io .ComfyNode ):
10+ @classmethod
11+ def define_schema (cls ) -> io .Schema :
12+ autogrow = io .Autogrow .TemplateNames (
13+ input = io .AnyType .Input ("value" ),
14+ names = list (string .ascii_lowercase ),
15+ min = 0 ,
16+ )
17+ return io .Schema (
18+ node_id = "StringFormat" ,
19+ display_name = "Format Text" ,
20+ category = "text" ,
21+ search_aliases = ["string" , "format" ],
22+ description = "Same as Python's string format method. Supports all of Python's format options and features." ,
23+ inputs = [
24+ io .Autogrow .Input ("values" , template = autogrow ),
25+ io .String .Input ("f_string" , default = "{a}" , multiline = True ),
26+ ],
27+ outputs = [
28+ io .String .Output (),
29+ ],
30+ )
31+
32+ @classmethod
33+ def execute (
34+ cls , values : io .Autogrow .Type , f_string : str
35+ ) -> io .NodeOutput :
36+ return io .NodeOutput (f_string .format (** values ))
37+
38+
839class StringConcatenate (io .ComfyNode ):
940 @classmethod
1041 def define_schema (cls ):
@@ -413,6 +444,7 @@ class StringExtension(ComfyExtension):
413444 @override
414445 async def get_node_list (self ) -> list [type [io .ComfyNode ]]:
415446 return [
447+ StringFormat ,
416448 StringConcatenate ,
417449 StringSubstring ,
418450 StringLength ,
You can’t perform that action at this time.
0 commit comments