Skip to content

Refactor/line reader#13330

Open
aollier wants to merge 2 commits into
keepassxreboot:developfrom
aollier:refactor/lineReader
Open

Refactor/line reader#13330
aollier wants to merge 2 commits into
keepassxreboot:developfrom
aollier:refactor/lineReader

Conversation

@aollier
Copy link
Copy Markdown
Contributor

@aollier aollier commented May 9, 2026

These changes make the LineReader class a concrete class whose implementation depends on whether or not USE_READLINE is defined. This greatly simplifies keepassxc-cli.cpp.
The readline library's search and internal and public variables now conform to the CMake standard (https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html).

If the readline library is not found, the LineReader class then depends on the TextStream class. The cli library also depends on the TextStream class, but only for its implementation (Export.cpp).
These relationships are now expressed between the line_reader, text_stream, and cli libraries.
Also, by putting the code of LineReader in the line_reader library, we isolate the use of USE_READLINE into the single line_reader library. The cli library does not use anymore the USE_READLINE definition.

Finally, the new version of the search modules allows the use of CMake's modern library dependency syntax.

The FindReadline.cmake module was written with the help of Le Chat (https://chat.mistral.ai/chat).

Type of change

  • ✅ Refactor (significant modification to existing code)

@aollier aollier force-pushed the refactor/lineReader branch from 632992d to ab7924c Compare May 9, 2026 19:36
…ler way

The LineReader is made a concrete class whose declaration
is independent of the readline library.
Only its implementation depends on the presence or absence
of the readline library.
The LineReader code is embedded in a new library : line_reader,
to make the cli library independant of the USE_READLINE definition.
@aollier aollier force-pushed the refactor/lineReader branch from ab7924c to f2a3033 Compare May 9, 2026 20:53
@varjolintu varjolintu added the pr: ai-assisted Pull request contains significant contributions by generative AI label May 12, 2026
@varjolintu
Copy link
Copy Markdown
Member

Is the NCurses dependency really needed for this? I don't really get the idea behind this whole change.

@aollier
Copy link
Copy Markdown
Contributor Author

aollier commented May 13, 2026

Hello @varjolintu and thank you for reviewing my pull request.

Your question touches on two points:

  1. According to https://vcpkg.io/en/package/readline and https://vcpkg.io/en/package/readline-unix.html, the readline library depends on ncurses on Unix only. That's why I introduced the FindNcurses module. Traces of this dependency can be seen in the current code with the Ncurses_LIBRARY variable:
    if(Readline_INCLUDE_DIR AND Readline_LIBRARY AND Ncurses_LIBRARY)
    set(READLINE_FOUND TRUE)
  2. The idea behind this whole change is the simplification of src/cli/keepassxc-cli.cpp and the elimination of unnecessary classes SimpleLineReader and ReadlineLineReader. This also sets the USE_READLINE definition only where it is necessary: for the LineReader class only, which is now isolated. So the cli library does not carry the USE_READLINE definition anymore. By introducing two new libraries, these changes also clarify the dependency of the code: the keepassxc_core library does not require TextStream.cpp. cli library does with Export.cpp, and LineReader may depend on it if the readline library dependency is not found.

@aollier
Copy link
Copy Markdown
Contributor Author

aollier commented May 13, 2026

I've just realized that it is not necessary to introduce the FindNcurses module because it already exists one in the CMake modules library: https://cmake.org/cmake/help/latest/module/FindCurses.html.

On the other hand, I admit that I have not found any trace of the readline library's dependency on the ncurses library anywhere other than on vcpkg and the Ncurses_LIBRARY variable. What is your experience with this?

@aollier
Copy link
Copy Markdown
Contributor Author

aollier commented May 13, 2026

I finally found the repository of the readline library: git://git.git.savannah.gnu.org/readline.git.
In the INSTALL file, I can read this:

`--with-curses'
This tells readline that it can find the termcap library functions
(tgetent, et al.) in the curses library, rather than a separate
termcap library. Readline uses the termcap functions, but does not
usually link with the termcap or curses library itself, allowing
applications which link with readline the to choose an appropriate
library. This option tells readline to link the example programs with
the curses library rather than libtermcap.

This is an option passed to the configure script. So it seems that the (n)curses library may not be mandatory, if the --with-curses option is NOT passed to the configure script.

So what is your recommandation with this change? Should I let the FindReadline module unchanged even if on the vcpkg website we can see that the readline library requires the ncurses library?

@droidmonkey
Copy link
Copy Markdown
Member

droidmonkey commented May 13, 2026

We do not use vcpkg on linux. If ncurses is a dependency of readline on macOS then finding the readline library would be sufficient as that should also bring in the ncurses library as needed. If we dont directly utilize a library than we shouldn't need to "find" it and link to it directly.

@aollier aollier force-pushed the refactor/lineReader branch 2 times, most recently from e8e9876 to 4b8c0fb Compare May 13, 2026 18:20
@aollier
Copy link
Copy Markdown
Contributor Author

aollier commented May 13, 2026

Ok I've updated my change by removing the FindNcurses module and every reference to the ncurses library.
I think it is correct now.

The readline library is now searched with pkg-config first.
If pkg-config is not installed, the search is manual.
In both cases, the Readline::readline target is created,
embedding transitive requirements.

FindReadline module was written with the help of Le Chat AI (https://chat.mistral.ai/chat)
@aollier aollier force-pushed the refactor/lineReader branch from 4b8c0fb to 522cfe6 Compare May 13, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: ai-assisted Pull request contains significant contributions by generative AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants