8000 GitHub - st4ll1/CPPurses: C++14 Terminal User Interface framework with NCurses.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

st4ll1/CPPurses

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terminal User Interface Library

CPPurses is a widget framework for NCurses inspired by Qt. It comes from a desire for a simple and modern approach to building terminal applications. Through a set of abstractions built on top of NCurses, CPPurses enables quick development of complex TUIs, without getting in the way of program logic.

Usage

Defining a New Widget

#include <cppurses/cppurses.hpp>
#include <signals/signals.hpp>
#include <cstdint>
#include <utility>
using namespace cppurses;

// Button Widget that emits a signal when clicked.
class Button : public Widg
9A8A
et {
   public:
    Button(Glyph_string title) : title_{std::move(title)} {}

    void set_title(Glyph_string title) {
        title_ = std::move(title);
        this->update();  // Post a Paint_event to the event queue.
    }

    // Signals
    sig::Signal<void()> clicked;

   protected:
    bool mouse_press_event(Mouse_button button,
                           Point global,
                           Point local,
                           std::uint8_t device_id) override {
        // Emit Signal if Left Button Pressed
        if (button == Mouse_button::Left) {
            clicked();
        }
        return Widget::mouse_press_event(button, global, local, device_id);
    }

    bool paint_event() override {
        // Calculate Center Position
        std::size_t x{(this->width() / 2) - (title_.length() / 2)};
        std::size_t y{this->height() / 2};
        Point position{x, y};

        // Put Title to Screen
        Painter p{this};
        p.put(title_, position);

        return Widget::paint_event();
    }

   private:
    Glyph_string title_;
};

Using Existing Widgets

struct Side_pane : public Vertical_layout {
    Textbox& tbox_mirror{this->make_child<Textbox>("Mirror")};
    Button& exit_btn{
        this->make_child<Button>(Glyph_string{"Exit", Attribute::Bold})};

    Side_pane() {
        enable_border(tbox_mirror);
        set_background(tbox_mirror, Color::Light_gray);
        set_foreground(tbox_mirror, Color::Dark_blue);

        exit_btn.height_policy.type(Size_policy::Fixed);
        exit_btn.height_policy.hint(3);
        set_background(exit_btn, Color::Dark_blue);
        set_foreground(exit_btn, Color::Light_gray);

        exit_btn.clicked.connect(System::quit);
    }
};

// Two Textboxes and Button to exit.
struct Two_boxes : public Horizontal_layout {
    Textbox& tbox{this->make_child<Textbox>()};
    Side_pane& side_pane{this->make_child<Side_pane>()};

    Two_boxes() {
        tbox.width_policy.stretch(2);
        tbox.text_changed.connect(slot::set_text(side_pane.tbox_mirror));
    }
};

int main() {
    System sys;

    Two_boxes main_widget;
    sys.set_head(&main_widget);
    Focus::set_focus_to(&main_widget.tbox);

    return sys.run();
}

alt text

Modules

Event System: Event loop, widget drawing, and user input.

Signals and Slots: Widget to widget communication.

Widget Library: Pre-made Widgets for reuse.

Features

  • UTF-8 support without the need for wide characters
  • Extensible Color Palettes
  • Mouse and Keyboard Input
  • Simple and configurable layout system
  • Easy border drawing and manipulation
  • Vanilla C++ Signals and Slots implementation
  • Fully featured Textbox widget with cursor movement and scrolling

Widgets

  • Textbox
  • Text_display
  • Checkbox
  • Push_button
  • Confirm_button
  • Cycle_box
  • Cycle_stack
  • Titlebar
  • Horizontal_scrollbar
  • Vertical_scrollbar
  • Color_select
  • Glyph_select
  • Label
  • Labeled_cycle_box
  • Line_edit
  • List
  • Log
  • Menu
  • Matrix_display
  • Open_file
  • Save_file
  • Slider
  • Status_bar
  • Widget_stack
  • Widget_stack_menu
  • Horizontal_layout
  • Vertical_layout

Future Features

  • Animation
  • Mouse Move Events
  • Tabs Widget
  • Hovering Widget Layout
  • Dialog Box Widget
  • Documentation

Installation

CPPurses depends on two header only libraries, this repo includes them as git submodules. After cloning CPPurses, run git submodule update --init -- recursive --remote to pull in the external libraries. Generated build files from CMake will handle installation of each library and building of tests. For Unix based installs: sudo make install

Documentation

Doxygen documentation can be found here.

Demo Screenshots

alt text Glyph Paint Demo

alt text Notepad Demo

alt text alt text Chess Demo

Tests

CPPurses uses google test and has support for ctest.

License

This software is distributed under the MIT License.

About

C++14 Terminal User Interface framework with NCurses.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 98.0%
  • CMake 2.0%
0