[Feature Request/Issue] Preserve or Allow Customization of Line Endings in formatCinToCout for Cross-Platform Consistency
Description:
Hello Artistic Style developers,
I hope this message finds you well. I am reaching out to report an issue/feature request regarding the handling of line endings in the ASConsole::formatCinToCout function, specifically when using astyle within an MSYS2 environment on Windows.
Background:
In the pursuit of maintaining consistent code formatting across platforms, I've encountered a behavior in astyle (version: 3.4.10) that seems to override the desired line ending format when processing input via pipes or redirection under MSYS2. The code snippet in question is located in ASConsole::formatCinToCout, where it unconditionally sets the line ending format to Windows style (\r\n) on Windows platforms:
// Windows pipe or redirection always outputs Windows line-ends.
// Linux pipe or redirection will output any line end.
#ifdef _WIN32
LineEndFormat lineEndFormat = LINEEND_DEFAULT; // Defaults to Windows style
#else
LineEndFormat lineEndFormat = formatter.getLineEndFormat();
#endif // _WIN32
Issue:
My objective is to format my codebase consistently with Unix-style line endings (\n) regardless of the operating system, as my project is cross-platform and we use Git which prefers Unix-style endings. Despite specifying the --lineend=linux option, the output from astyle when used in conjunction with MSYS2 still results in files with Windows-style line endings. This discrepancy hinders our workflow and forces us to perform additional steps to normalize line endings post-formatting.
Proposal: It would be immensely beneficial if the astyle tool could respect the --lineend setting even when processing input through pipes or redirection in a Windows environment, ensuring cross-platform consistency. Ideally, users should have control over the line ending format even when not directly writing to files, especially in development environments like MSYS2 that often require adherence to Unix conventions.
Potential Solutions:
Modify the conditional block: Adjust the code to consider the --lineend option's value even under _WIN32, allowing for customized line ending behavior. Introduce a new flag: Consider introducing a command-line option to explicitly enforce the specified line ending behavior in all scenarios, overriding platform-specific defaults. I understand this may involve design considerations and potentially backward compatibility implications, but I believe enhancing cross-platform flexibility is crucial for a tool like astyle. I am more than willing to contribute further details or assist in any way possible.
Thank you for considering this improvement. I look forward to your thoughts and any potential solutions or workarounds you might suggest.
Environment:
OS: Windows Environment: MSYS2 astyle Version: 3.4.10 Best regards, Yunus