Add function to just return string output instead of echoing it.
myleshyson opened this issue · 1 comments
TL;DR: Would you be ok with an added function, maybe something like asString
or something that just returns the final formatted string instead of echoing it (like render
)?
I created a function similar to Laravel prompts task
in CraftCms that shows either a check or an x depending on whether the task completed or not. However what I ran into was needing to know how many actual lines are output to the terminal, so I could move the cursor up that many lines and replace the text with an appended checkmark.
I ended up just directly using the HtmlRender
class like so to accomplish what I needed to.
$html = (new HtmlRenderer())->parse('<div>hi!</div>')->toString();
// count the lines
// replace the line with an appended check or x.
It's marked as internal and crossed out in my ide however. Not a huge deal, but I think just having a function similar to render
that just does the above would be a nice QoL improvement. So instead if people needed the raw string for whatever reason they could do
$string = asString('<div>hi!</div>');
instead of having to code dive.
I don't mind doing the pull request if you're ok with this.
Hey @myleshyson thanks for that, I would love to review your PR, and probably the name of the function should be parse
.