Skip to content
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

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft

Conversation

p4vook
Copy link
Contributor

@p4vook p4vook commented Dec 7, 2020

This PR also adds the abstract classes which are intended to be a base classes for futher text windows and windows' contents (buffers)

p4vook and others added 4 commits December 7, 2020 11:16
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>
@p4vook p4vook marked this pull request as draft December 7, 2020 08:31
@p4vook p4vook requested a review from leha-bot December 7, 2020 09:47
Copy link
Contributor

@leha-bot leha-bot left a 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

CMakeLists.txt Outdated Show resolved Hide resolved
include/buffer.hpp Show resolved Hide resolved

target_include_directories(rang PUBLIC ${CURSES_INCLUDE_DIRS})
target_link_libraries(rang PUBLIC ${CURSES_LIBRARIES})
Copy link
Contributor

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}).

src/console_io/include/window.hpp Outdated Show resolved Hide resolved
src/rang.cpp Outdated Show resolved Hide resolved
@leha-bot leha-bot self-assigned this Dec 14, 2020
@leha-bot leha-bot changed the title component: UI UI: Simple ncurses window with ls-like output Dec 14, 2020
p4vook and others added 6 commits December 16, 2020 12:00
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>
Signed-off-by: Pavel Kalugin <pavel@pavelthebest.me>
@p4vook p4vook requested a review from leha-bot December 31, 2020 12:47
Copy link
Contributor

@leha-bot leha-bot left a 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
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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) {
Copy link
Contributor

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).

Copy link
Contributor Author

@p4vook p4vook Jan 11, 2021

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 */
Copy link

Choose a reason for hiding this comment

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

everty?

Copy link
Contributor

@leha-bot leha-bot left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants