New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trailing line break dropped from function output #49
Comments
This is by design. The command runs in a subshell and one trailing newline will be stripped automatically by Bash. I didn't employ any techniques to preserve the trailing newline, so it would remain similar to what others would experience if they used
... and then use it in a template.
With the trailing newline preserved, this function would not produce what you would expect. Closing because this is an intentional design decision, even though it is certainly awkward for your scenario. |
It is problematic that all functions are forced into the assumption that trailing new lines should be dropped. It might be helpful to support a static table providing rules over processing for individual functions, or to supply a decorator that adjusts the behavior of a function. Presently, even additional line breaks are dropped entirely as a sequence. Changing the definition of the function appears to offer no means to work around the quirk. Additionally, the example of the inline function is confusing when given as a counterexample. In this case, the invoking text has no line breaks, in contrast to the original example in which a line break immediately follows the closing of the template section. Even if the line break would be dropped from the function output, one may still be applied separating the template and literal sections of the input. A decorator might work as follows:
|
I've been pondering this one as well. What if you want newlines in some instances and no newlines in another? Do you need to make The spec allows for I currently have three options:
My preference is to use option #2 because the functions are somewhat a niche market due to their complexity. I'm not completely sold on the idea yet, so I haven't taken action on it. |
I'm not understanding your question. The central issue I identify in my example is that the template footer and the following literal word are separated by a line break, but the output expresses no line break nor any space nor even any characters between the template substitution and the following word. You had expressed concern over the case in which a function output ends with a line break but no line break is desired in the output, with the template element appearing inline. I suggested that you might provide library support for this distinction through a decorator that strips the trailing line break, so that users easily may construct a function not outputting a trailing line break based on a pre-existing function outputting a trailing line break. The particular matter of function definition, however, I think is not central to the original issue. The central concern is understood by observing that the template may be divided into three sections, two literal and one template. The three sections of the template are as follows:
In the current implementation, template substitution of the middle section, for If the output currently created were desired, then the following might the appropriate template:
|
I have come around to your viewpoint and will always preserve whatever output the function provides. This has been fixed on the rewrite-parser branch and will make its way to the next release. |
After obtaining
mo
, I run a few commands, and capture their output, as follows:Expected is the following final output:
The terminating line break of the function output appears to be lost. The result not only is undesirable formatting for text intended to be human readable, but breakage for certain configuration files interpreted by tools with strict rules regarding parsing white space.
The text was updated successfully, but these errors were encountered: