Skip to content

Commit

Permalink
0.2.1 - unicode, string improvements, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LabRicecat committed Sep 21, 2023
1 parent de47f20 commit d659e05
Show file tree
Hide file tree
Showing 17 changed files with 330 additions and 88 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.9)

set(VERS 0.2.0)
set(VERS 0.2.1)

project(catui
VERSION ${VERS}
Expand All @@ -9,7 +9,6 @@ project(catui

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_library(catui STATIC
src/base/buffer.cpp
Expand Down Expand Up @@ -38,6 +37,9 @@ add_library(catui STATIC
src/container/horizontal.cpp

src/renderer/fit.cpp

src/window/inputfield.cpp
src/window/textfield.cpp
)

target_compile_features(catui PRIVATE cxx_std_20)
Expand All @@ -46,6 +48,11 @@ set_target_properties(catui PROPERTIES SOVERSION 0)

set_target_properties(catui PROPERTIES VERSION ${VERS})

if(DEBUG)
target_compile_options(catui PUBLIC -g)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif(DEBUG)

target_include_directories(catui PRIVATE .)

include(GNUInstallDirs)
Expand Down
4 changes: 2 additions & 2 deletions inc/base/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Window;

class Buffer {
protected:
std::string raw;
CatString raw;
Window* assoc_window = nullptr;

Composer i_composer = [](const Composer::param_type& data, Buffer*) { return (Composer::return_type)data; };
Expand All @@ -95,7 +95,7 @@ class Buffer {

virtual Buffer& set(const std::string& raw);
virtual Buffer& append(const std::string& raw);
virtual std::string& get_raw();
virtual CatString& get_raw();

virtual Buffer& clear();

Expand Down
3 changes: 3 additions & 0 deletions inc/base/signals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace cat {

namespace signals {

using signal = uint64_t;
using tag_type = uint64_t;
struct SignalData;
Expand Down Expand Up @@ -54,9 +55,11 @@ namespace signals {
std::string msg;
MessageData(const std::string& msg): msg(msg) { }
};

} // namespace signals

void error(const std::string& msg);
void emit(signals::signal sig, const signals::SignalData* data = nullptr, bool clean = true);

} // namespace cat

Expand Down
16 changes: 11 additions & 5 deletions inc/base/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ class CatString {
string_src = src;
}


CatString& push_back(const CatString& s);

CatString& push_back(const std::string& s);
CatString& push_back(const event::fn_type& fn);

CatString& push_front(const std::string& s);
CatString& push_front(const event::fn_type& fn);
CatString& push_front(const CatString& s);

event pop();

Expand All @@ -62,8 +60,16 @@ class CatString {
const std::list<event>& entries() const;

size_t size() const;
size_t length() const;

CatString& erase(size_t pos, size_t n = 1);
CatString& insert(size_t pos, const CatString& s);
CatString& insert(size_t pos, char c);

CatString& append(const CatString& c);

CatString substr(size_t pos);
CatString substr(size_t pos, size_t n);

CatString& operator+=(const std::string& s);
CatString& operator+=(const event::fn_type& fn);
Expand Down
7 changes: 6 additions & 1 deletion inc/base/string_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ struct CatStringIterator {
CatStringIterator& set_end();

bool operator==(const CatStringIterator& i);
bool operator!=(const CatStringIterator& i);
bool operator!=(const CatStringIterator& i);

CatStringIterator& operator+=(size_t n);
CatStringIterator operator+(size_t n);
};

struct ConstCatStringIterator {
Expand All @@ -47,6 +50,8 @@ struct ConstCatStringIterator {
bool operator==(const ConstCatStringIterator& i);
bool operator!=(const ConstCatStringIterator& i);

ConstCatStringIterator& operator+=(size_t n);
ConstCatStringIterator operator+(size_t n);
};

}
Expand Down
149 changes: 92 additions & 57 deletions inc/base/unicode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,98 @@ namespace cat {
// using UNICODE Codepage 437
namespace uc {

inline const CatString smile1 = "";
inline const CatString smile2 = "";
inline const CatString heart = "";
inline const CatString diamond = "";
inline const CatString club = "";
inline const CatString spade = "";
inline const CatString spot1 = "";
inline const CatString spot2 = "";
inline const CatString male = "";
inline const CatString female = "";
inline const CatString note1 = "";
inline const CatString note2 = "";
inline const CatString solar = "";
inline const CatString pointer_right = "";
inline const CatString pointer_left = "";
inline const CatString arrow_up_down = "";
inline const CatString double_exlam = "";
inline const CatString pilcrow = "";
inline const CatString section = "";
inline const CatString rectangle = "";
inline const CatString arrow_up_down_b = "";
inline const CatString arrow_up = "";
inline const CatString arrow_down = "";
inline const CatString arrow_right = "";
inline const CatString arrow_left = "";
inline const CatString right_angle = "";
inline const CatString arrow_left_right = "";
inline const CatString triangle_up = "";
inline const CatString triangle_down = "";
inline const CatString house = "";
inline const CatString cent = "";
inline const CatString pound = "";
inline const CatString yen = "";
inline const CatString yuan = yen;
inline const CatString f_hook = "";
inline const CatString questionmark_inv = "";
inline const CatString negation_right = "";
inline const CatString negation_left = "";
inline const CatString half = "";
inline const CatString quater = "";
inline const CatString exclamation_inv = "";
inline const CatString double_arrowleft = "";
inline const CatString double_arrowright= "";
inline const CatString light_shade = "";
inline const CatString medium_shade = "";
inline const CatString dark_shade = "";
inline const CatString vertical_l = "";
inline const CatString crossing_ll_left = "";
inline const CatString crossing_hl_left = "";
inline const CatString crossing_lh_left = "";
inline const CatString corner_lh_left = "";
inline const CatString corner_hl_left = "";
inline const CatString crossing_hh_left = "";
inline const CatString vertical_h = "";
inline const CatString corner_hh_left = "";
inline const CatString square = "";

inline const CatString smile1 = "";
inline const CatString smile2 = "";
inline const CatString heart = "";
inline const CatString diamond = "";
inline const CatString club = "";
inline const CatString spade = "";
inline const CatString spot1 = "";
inline const CatString spot2 = "";
inline const CatString bullet1 = "";
inline const CatString bullet2 = "";
inline const CatString mars = "";
inline const CatString venus = "";
inline const CatString note1 = "";
inline const CatString note2 = "";
inline const CatString solar = "";
inline const CatString pointer_right = "";
inline const CatString pointer_left = "";
inline const CatString arrow_up_down = "";
inline const CatString double_exlam = "";
inline const CatString pilcrow = "";
inline const CatString section = "§";
inline const CatString rectangle = "";
inline const CatString arrow_up_down_2 = "";
inline const CatString arrow_up = "";
inline const CatString arrow_down = "";
inline const CatString arrow_right = "";
inline const CatString arrow_left = "";
inline const CatString right_angle = "";
inline const CatString arrow_left_right = "";
inline const CatString pointer_up = "";
inline const CatString pointer_down = "";
inline const CatString house = "";
inline const CatString f_hook = "ƒ";
inline const CatString questionmark_inv = "¿";
inline const CatString negation_right = "";
inline const CatString negation_left = "¬";
inline const CatString half = "½";
inline const CatString quater = "¼";
inline const CatString exclamationmark_inv = "¡";
inline const CatString double_arrow_left = "«";
inline const CatString double_arrow_right = "»";
inline const CatString light_shade = "";
inline const CatString medium_shade = "";
inline const CatString dark_shade = "";
inline const CatString vertical_l = "";
inline const CatString crossing_ll_left = "";
inline const CatString crossing_hl_left = "";
inline const CatString crossing_lh_left = "";
inline const CatString corner_lh_left_down = "";
inline const CatString corner_hl_left_down = "";
inline const CatString crossing_hh_left_down= "";
inline const CatString vertical_h = "";
inline const CatString corner_hh_left_down = "";
inline const CatString corner_hh_left_up = "";
inline const CatString corner_lh_left_up = "";
inline const CatString corner_hl_left_up = "";
inline const CatString corner_ll_left_down = "";
inline const CatString corner_ll_right_up = "";
inline const CatString crossing_ll_up = "";
inline const CatString crossing_ll_down = "";
inline const CatString crossing_ll_right = "";
inline const CatString horizontal_l = "";
inline const CatString cross_ll = "";
inline const CatString crossing_hl_right = "";
inline const CatString crossing_lh_right = "";
inline const CatString corner_hh_right_up = "";
inline const CatString corner_hh_right_down = "";
inline const CatString crossing_hh_up = "";
inline const CatString crossing_hh_down = "";
inline const CatString crossing_hh_right = "";
inline const CatString horizontal_h = "";
inline const CatString cross_hh = "";
inline const CatString crossing_lh_up = "";
inline const CatString crossing_hl_up = "";
inline const CatString crossing_lh_down = "";
inline const CatString crossing_hl_down = "";
inline const CatString corner_lh_right_up = "";
inline const CatString corner_hl_right_up = "";
inline const CatString corner_hl_right_down = "";
inline const CatString corner_lh_right_down = "";
inline const CatString cross_lh = "";
inline const CatString cross_hl = "";
inline const CatString corner_ll_left_up = "";
inline const CatString corner_ll_right_down = "";
inline const CatString square = "";
inline const CatString square_down = "";
inline const CatString square_left = "";
inline const CatString square_right = "";
inline const CatString square_up = "";
inline const CatString infinity = "";
inline const CatString check = "";
inline const CatString block = "";

} // namespace uc

Expand Down
2 changes: 1 addition & 1 deletion inc/base/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Window : public Positional {
return *this;
}

virtual Window& draw_buffer(const Vector2& offset = {0,0});
virtual Window& draw_buffer();

virtual Window& on_redraw(const redraw_event& event);
virtual Window& on_focus(const focus_event& event);
Expand Down
3 changes: 2 additions & 1 deletion inc/cat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* the whole TUI framework */

#define CAT_VERSION 000200
#define CAT_VERSION 000201

// requires C++20
#if __cplusplus >= 202002
Expand All @@ -22,6 +22,7 @@
#include "renderer/fit.hpp"

#include "window/inputfield.hpp"
#include "window/textfield.hpp"

#endif

Expand Down
35 changes: 35 additions & 0 deletions inc/window/textfield.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef CAT_WINDOW_TEXTFIELD_HPP
#define CAT_WINDOW_TEXTFIELD_HPP

#include "../base/window.hpp"

namespace cat {

class TextField : public Window {
Vector2 curs_position;
size_t idx = 0;

public:
TextField(const Vector2& position, const Vector2& resolution)
: Window::Window(position,resolution) {
key_check = [](const key& k) { return isprint(k); };
key_handler = [&](const key& k) {
buffer->get_raw().append(std::string(1,(char)k));
++idx;
curs_position += Vector2{1,0};

clear();
draw_buffer();
redraw();
};
}

virtual TextField& append(const CatString& str);
virtual TextField& clear_text();
virtual CatString& get();

};

} // namespace cat

#endif
2 changes: 1 addition & 1 deletion src/base/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Buffer& Buffer::append(const std::string& raw) {
return *this;
}

std::string& Buffer::get_raw() {
CatString& Buffer::get_raw() {
return raw;
}

Expand Down
5 changes: 4 additions & 1 deletion src/base/signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace signals {

size_t SignalData::id() const { return typeid(*this).hash_code(); }


signal tag(signal sig, tag_type tag) {
tags[tag].push_back(sig);
rtags_map[sig].push_back(tag);
Expand Down Expand Up @@ -58,4 +57,8 @@ void error(const std::string& msg) {
signals::emit_tag(signals::error_tag, new signals::MessageData(msg));
}

void emit(signals::signal sig, const signals::SignalData* data, bool clean) {
signals::emit(sig, data, clean);
}

} // namespace cat
Loading

0 comments on commit d659e05

Please sign in to comment.