客户端显示格式化的字符串
This commit is contained in:
@@ -47,6 +47,7 @@ class StringFormatter:
|
||||
|
||||
# Format string using f-string style with the arguments dictionary
|
||||
result = eval(f"f'''{template}'''", args_dict)
|
||||
return (result,)
|
||||
return {"ui": {"formatted_string": (result,)}, "result": (result,)}
|
||||
except Exception as e:
|
||||
return (f"Format Error: {str(e)}",)
|
||||
error_msg = f"Format Error: {str(e)}"
|
||||
return {"ui": {"formatted_string": (error_msg,)}, "result": (error_msg,)}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { ComfyWidgets } from "../../../scripts/widgets.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "ComfyUI-String-Helper.StringFormatter",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "StringFormatter") {
|
||||
const onExecuted = nodeType.prototype.onExecuted;
|
||||
nodeType.prototype.onExecuted = function (message) {
|
||||
onExecuted?.apply(this, arguments);
|
||||
|
||||
if (this.widgets) {
|
||||
const pos = this.widgets.findIndex((w) => w.name === "formatted_text");
|
||||
if (pos !== -1) {
|
||||
for (let i = pos; i < this.widgets.length; i++) {
|
||||
this.widgets[i].onRemove?.();
|
||||
}
|
||||
this.widgets.length = pos;
|
||||
}
|
||||
}
|
||||
|
||||
const widget = ComfyWidgets["STRING"](this, "formatted_text", ["STRING", { multiline: true }], app).widget;
|
||||
widget.inputEl.readOnly = true;
|
||||
widget.inputEl.style.opacity = 0.6;
|
||||
widget.value = message.formatted_string?.[0] ?? "";
|
||||
|
||||
this.onResize?.(this.size);
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user