Skip to content

feat(linenoise): Add linenoise library (IEC-328) #526

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

SoucheSouche
Copy link
Collaborator

Checklist

  • Component contains License
  • Component contains README.md
  • Component contains idf_component.yml file with url field defined
  • Component was added to upload job
  • Optional: Component contains unit tests
  • CI passing

Change description

Add linenoise to the list of extra components. The library is used in the console component of esp-idf that is going through refactoring. One part of the refactoring is to move third party libraries outside of the console component. Eventually, the console component itself will be removed from esp-idf, reason why this PR adds the linenoise lib to the idf-extra-components.

@SoucheSouche SoucheSouche changed the title Feat/add linenoise library Feat(linenoise): Add linenoise library Jul 4, 2025
@SoucheSouche SoucheSouche changed the title Feat(linenoise): Add linenoise library feat(linenoise): Add linenoise library Jul 4, 2025
@suda-morris suda-morris requested a review from o-marshmallow July 4, 2025 07:34
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch from 859aa9c to af22955 Compare July 4, 2025 07:39
@github-actions github-actions bot changed the title feat(linenoise): Add linenoise library feat(linenoise): Add linenoise library (IEC-328) Jul 4, 2025
@suda-morris
Copy link
Collaborator

There was a PR about the linenoise library: espressif/esp-idf#10526
WDYT? @SoucheSouche

@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch 4 times, most recently from 019e413 to b4d3a0c Compare July 8, 2025 12:07
@SoucheSouche
Copy link
Collaborator Author

SoucheSouche commented Jul 8, 2025

There was a PR about the linenoise library: espressif/esp-idf#10526 WDYT? @SoucheSouche

@suda-morris
Yes, I am aware of it. I took into account Ivan's comment left in the PR when implementing this version of linenoise. The author of the PR you mentioned is aware that I will take over and continue the work on improving the console component (linenoise and more generally the list of idea he listed here espressif/esp-idf#9986)

* @param param Pointer to the configuration parameters for the instance.
* @return Handle to the created instance, or NULL on failure.
*/
linenoise_handle_t linenoise_create_instance(linenoise_instance_param_t *param);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
linenoise_handle_t linenoise_create_instance(linenoise_instance_param_t *param);
esp_err_t linenoise_create_instance(const linenoise_instance_param_t *param, linenoise_handle_t* out_handle);
  1. Configuration structure can be a const pointer
  2. You may need to return different types of errors (out of RAM, invalid argument in the config structure, etc), which simply returning NULL doesn't allow. Hence, return esp_err_t and get the instance handle as an output argument.

* @param handle Handle to the instance to delete.
* @return ESP_OK on success, or error code on failure.
*/
esp_err_t linenoise_delete_instance(linenoise_handle_t handle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should the caller do if the "delete instance" function has returned an error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only way the function returns an error is if the handle is invalid. I understand the question but then I would also expect that it is also valid for the comment above. So either I update the linenoise_create_instance to return error values and I leave this function as it is now or I update linenoise_delete_instance to abort when the handle is invalid and I keep the function linenoise_create_insance as it is now.

Because I am not sure what the caller can do if linenoise_create_instance returns e.g., no memory error.

* @param empty_line true to allow empty lines, false to disallow.
* @return ESP_OK on success, or error code on failure.
*/
esp_err_t linenoise_set_empty_line(linenoise_handle_t handle, bool empty_line);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a use case for changing these settings (empty_line, multi_line, dumb_mode, max_cmd_line_length) once the instance is already created? If there is no concrete use case, it might be simpler to not implement these getters and setters.

Copy link
Collaborator Author

@SoucheSouche SoucheSouche Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user might want to repurpose an existing linenoise instance, instead of deleting the instance and creating a new one. In that case it might be useful to keep the getters and setters

@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch 7 times, most recently from e2dc2cc to 0a0b3e9 Compare July 14, 2025 13:59
@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch 4 times, most recently from 68556ce to 4530c52 Compare July 16, 2025 08:37
@SoucheSouche
Copy link
Collaborator Author

@igrr, I updated the component based on your input. I left a few comments open for discussion.

I added a bunch of tests for the basic functionality of linenoise when escape sequences are supported by the terminal.

@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch 3 times, most recently from f564777 to bca4fd1 Compare July 22, 2025 07:19
@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch 8 times, most recently from d1158a1 to fb1f7f8 Compare July 23, 2025 09:10
@SoucheSouche
Copy link
Collaborator Author

SoucheSouche commented Jul 23, 2025

@igrr, I incorporated your second round of review (see 6e3c7a0). Please also check the comments I left below your comments from the first round of review.

@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch from fb1f7f8 to a8e73ef Compare July 23, 2025 09:23
@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch from a8e73ef to 6e3c7a0 Compare July 31, 2025 08:16
The check that the user added the component to the bug-report.yml
file ius missing in the list of condition to meet for the PR to be
receivable.
@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch 3 times, most recently from c210664 to b0f7a27 Compare August 4, 2025 07:07
@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch from b0f7a27 to 8ca437b Compare August 5, 2025 07:55
@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch from 8ca437b to c4b9cb9 Compare August 5, 2025 10:35
@SoucheSouche SoucheSouche force-pushed the feat/add-linenoise-library branch from c4b9cb9 to b3c5ebb Compare August 5, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants