-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Shell: Remove unnecessary new lines at startup #77280
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
Shell: Remove unnecessary new lines at startup #77280
Conversation
What makes you think those newlines are unnecessary? The code was added for a reason. |
The fact that there is no documentation nor any tests. I checked the PR that introduced the behavior (#9362) and did not find any arguments. If you can think of how it could be useful, please let me know. And if possible, add a test to demonstrate the usefulness of it or at least some documentation. |
|
Thank you for your feedback. I understand the importance of tests and documentation, but in this case, the functionality is straightforward and doesn’t require them. The code’s purpose is clear and adding tests or detailed documentation might not add much value. However, I do see the benefit of making the intent clearer, so I'm happy to add a comment above the code to explain its purpose. This should help anyone reading the code in the future. If you have further concerns or suggestions, I’m open to discussing them, but I believe a concise comment should suffice. |
|
Hi @jakub-uC, thanks for taking the time to explain things to me, it's much appreciated! That said, the way it is implemented looks a bit hacky to me. You said that this functionality is straightforward but is it? At first, I did not understand why there was a condition on the length of the prompt. From what I saw elsewhere when playing with other shells and terminal programs, the usual way would rather be to move the cursor position for this kind of thing. So, I investigated a bit more, and I now understand why there is that The function zephyr/subsys/shell/shell_ops.c Lines 75 to 80 in 6b6c433
Seems to make sense: the line is full, we move the cursor to the next line. Now let's look at the documentation of Seems odd, the docstring says that the function does a bit more than the comment at the call-site. Let's take a look at the implementation: zephyr/subsys/shell/shell_ops.c Lines 41 to 48 in 6b6c433
Indeed, the function does more than what the comment in We now understand why there is that condition on the prompt size in My point writing that is to highlight how something that may seem trivial isn't. I don't mind having two lines when I start my shell. But I definitely care about the code complexity and readability. And having code like that is not helpful for future contributors. Here are my suggestions:
|
|
@theob-pro If you remove these two new lines, the result after the reset will be as shown in the picture, and it will have the following consequences until the command is executed (press Enter): The prompt will be printed on the same line, in the same place where it was before the reset. This does not look neat. After the command: In the place marked in the screenshot |
|
@jakub-uC, I understand your concern about the reset, and I agree with you. My point here is that the way it's done is not correct and hard to understand. Was it clear to you why the there was that What I am proposing is fixing EDIT: I pushed my proposed change here so it's maybe easier to understand what I am proposing. |
3b9996b to
b0f8ef9
Compare
|
I'm not entirely sure if I fully understand how you want to modify the Replacing There is indeed an inconsistency in the comments for the Thank you for your patience with the explanations, but each of us have a different context in mind, which leads to misunderstandings. Adding a commit with the proposed change would greatly improve communication. |
|
Ahh you did it already! :) |
Could you please provide more information? Is there a specific reason for that? As I understand the reason for adding a new line at the shell startup, it's hard for me to find a good reason to add a second one. To be honest, if this is a personal preference I would prefer to tell users that they can configure the prompt however they want using one of the |
|
I won't insist on making the change. The reasoning at the time was that with 2 lines, you can see the device reset, and it's possible to distinguish it from the regular execution of the command. |
The fact that the function was returning `true` for empty line was an unexpected behavior according to the name of the function itself and how it was used elsewhere. Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
When the shell start, it will print two lines. The reason for that behavior is not documented. Remove that to make the code simpler and shorter one line at a time. Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
Update `shell_backend_uart` to take into account the new line print by `z_cursor_next_line_move`. Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
b0f8ef9 to
117cda8
Compare
|
Rebased to fix failing test. |

When the shell start, it will print two lines. The reason for that behavior is not documented. Remove that to make the code simpler and shorter one line at a time.