-
Notifications
You must be signed in to change notification settings - Fork 0
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
UI: Simple ncurses window with ls-like output #11
base: master
Are you sure you want to change the base?
Conversation
Basic ls in ncurses window - Require C++17 because of std::filesystem usage - Draw sorted listing of cwd in main window Signed-off-by: Pavel Kalugin <paul.kalug@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems OK, but we should fix some parts which I mentioned
|
||
target_include_directories(rang PUBLIC ${CURSES_INCLUDE_DIRS}) | ||
target_link_libraries(rang PUBLIC ${CURSES_LIBRARIES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should make a CMake module which will export the Curses imported target and use it (like
target_link_libraries(rang PUBLIC Curses::Curses)
. This approach is more clear and we could avoid the cumbersome adding of include_directories and libraries if we declare it as INTERFACE in our imported target: target_include_directories(Curses::Curses INTERFACE ${CURSES_INCLUDE_DIRS})
.
Signed-off-by: Pavel Kalugin <paul.kalug@gmail.com>
Signed-off-by: Pavel Kalugin <paul.kalug@gmail.com>
Signed-off-by: Pavel Kalugin <pavel@pavelthebest.me>
Signed-off-by: Pavel Kalugin <pavel@pavelthebest.me>
Signed-off-by: Pavel Kalugin <pavel@pavelthebest.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, it looks OK for me, but it is required some changes, refactors and git history rewrites.
virtual void update() = 0; | ||
}; | ||
|
||
class dummy : buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class does not contain any logic, therefore it remains abstract, so we couldn't use it as "dummy" class.
Seems it needs to implement the stub update()
method.
target_include_directories(rang PUBLIC ${CURSES_INCLUDE_DIRS}) | ||
target_link_libraries(rang PUBLIC ${CURSES_LIBRARIES}) | ||
target_link_libraries(rang PUBLIC ${CURSES_LIBRARIES} ${Boost_LIBRARIES} console_io) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also prefer the FindBoost's exported targets here: Boost::system Boost::thread.
#include "base.hpp" | ||
#include "window.hpp" | ||
|
||
#undef timeout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to add comment why this #undef
directive is here or drop it, if it doesn't use.
{ | ||
win_ptr = newwin(size_y, size_x, offset_y, offset_x); | ||
if (win_ptr == nullptr) { | ||
throw 1; // TODO errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use some type with exception information (maybe named like window_error
, or some similar name) derived from std::exception or std::runtime_error (or more semantic standard exception type). This exception type should contain an actual error info , implements the what()
method and possibly another information (std::error_code???).
#include <iostream> | ||
#include <ncurses.h> | ||
|
||
#undef timeout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also should be documented, why this undef is here.
using namespace rang; | ||
|
||
event_loop::event_loop() | ||
: signals(io_context, SIGINT, SIGTERM), // handle SIGINT and SIGTERM signals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As signals setup is a global operation, it should be mentioned in programmer's documentation to avoid some excessive case then we add a library (e.g. Google Breakpad for stacktraces and error reports) which could also set these signals' handlers.
void window::scroll_viewport(int shift) | ||
{ | ||
if (offset_y + shift >= tied_buf.contents.size() || offset_y + shift < 0) { | ||
throw 1; // todo errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same commend as in prev. "throw 1;" line.
int ch; | ||
main.refresh(); | ||
rang::event_loop loop; | ||
std::function<void(int)> reaction_func = [&](int ch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move this impl detail later to main window class (or some similar).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that there should be some "Cursor" class which manages what window is currently active and some "Reactor" class, which combines window's keybindings as a single handle function.
endwin(); /* End curses mode */ | ||
console_io::ncurses root; | ||
cbreak(); /* Line buffering disabled, Pass on | ||
*everty thing to me */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but some headers and classes seems to looks like the old POSIX names when the function identifiers were short and without some vovels. I suggest to change some names, but OK with current names.
This PR also adds the abstract classes which are intended to be a base classes for futher text windows and windows' contents (buffers)