commit 1fd6bc822ebe3e6007c25007c7734305ce48b827
parent d0bd51c29c05b227b28d71c59c6caf7f9742df8d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 28 Feb 2024 16:29:00 +0000
Improved consistency, minor fix-ups
* Namespace is now lowercase
* Enums are now capitalized
* Improved consistency when naming functions
* Added functions to toggle bracketed paste mode
* Better commends in generated file
* Fix RGB foreground/background color mode bug
Diffstat:
5 files changed, 55 insertions(+), 40 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -3,7 +3,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(
Alec
- VERSION 0.0.11
+ VERSION 0.0.12
DESCRIPTION "Abstraction Layer for Escape Codes"
HOMEPAGE_URL https://git.dimitrijedobrota.com/alec.git
LANGUAGES C CXX
diff --git a/demo/demo.cpp b/demo/demo.cpp
@@ -1,12 +1,12 @@
#include "alec.hpp"
#include <iostream>
-using namespace ALEC;
-using enum COLOR;
-using enum DECOR;
+using namespace alec;
+using enum Color;
+using enum Decor;
int main(void) {
- std::cout << abuf_show_v << cursor_hide_v;
+ std::cout << abuf_enable_v << cursor_hide_v;
std::cout << cursor_position_v<1, 1> << foreground_v<91> << "HELLO!\n";
@@ -18,11 +18,11 @@ int main(void) {
std::cout << cursor_up_v<5> << "Hello there!" << cursor_save_v;
std::cout << cursor_down_v<10> << "General Kenobi!";
- std::cout << cursor_position_v<10, 40> << "no pain no gain" << cursor_load_v << cursor_show_v;
+ std::cout << cursor_position_v<10, 40> << "no pain no gain" << cursor_restore_v << cursor_show_v;
getchar();
- std::cout << abuf_hide_v;
+ std::cout << abuf_disable_v;
return 0;
}
diff --git a/demo/demo_runtime.cpp b/demo/demo_runtime.cpp
@@ -1,28 +1,28 @@
#include "alec.hpp"
#include <iostream>
-using namespace ALEC;
-using enum COLOR;
-using enum DECOR;
+using namespace alec;
+using enum Color;
+using enum Decor;
int main(void) {
- std::cout << abuf_show() << cursor_hide();
+ std::cout << abuf_enable() << cursor_hide();
std::cout << cursor_position(1, 1) << foreground(91) << "HELLO!\n";
std::cout << cursor_down(3);
- std::cout << foreground(30) << background(196, 53, 64) << "WORLD!\n";
+ std::cout << foreground(30) << background(96, 53, 64) << "WORLD!\n";
std::cout << background(DEFAULT) << "testing 1...\n" << foreground(DEFAULT);
std::cout << decor_set(INVERSE) << "testing 2...\n" << decor_reset(INVERSE);
std::cout << cursor_up(5) << "Hello there!" << cursor_save();
std::cout << cursor_down(10) << "General Kenobi!";
- std::cout << cursor_position(10, 40) << "no pain no gain" << cursor_load() << cursor_show();
+ std::cout << cursor_position(10, 40) << "no pain no gain" << cursor_restore() << cursor_show();
getchar();
- std::cout << abuf_hide();
+ std::cout << abuf_disable();
return 0;
}
diff --git a/src/alec.rules.hpp b/src/alec.rules.hpp
@@ -7,9 +7,11 @@
#include <cstdint>
#include <string>
#include <type_traits>
-namespace ALEC {
-enum CTRL {
+
+namespace alec {
+
+enum Ctrl {
BELL = 0x07,
BS = 0x08,
HT = 0x09,
@@ -21,7 +23,7 @@ enum CTRL {
DEL = 0x7F,
};
-enum class COLOR {
+enum class Color {
BLACK = 0,
RED = 1,
GREEN = 2,
@@ -33,7 +35,7 @@ enum class COLOR {
DEFAULT = 9,
};
-enum class DECOR {
+enum class Decor {
RESET = 0,
BOLD = 1,
DIM = 2,
@@ -45,7 +47,7 @@ enum class DECOR {
STRIKE = 9,
};
-enum class MOTION {
+enum class Motion {
END = 0,
BEGIN = 1,
WHOLE = 2,
@@ -94,7 +96,7 @@ struct helper {
static const std::string make(auto... args) {
std::size_t len = (helper::size(args) + ... + 2);
std::string res(len, 'a');
- res[0] = CTRL::ESC, res[1] = '[';
+ res[0] = Ctrl::ESC, res[1] = '[';
auto map = [ptr = res.data() + 2](auto const &s) mutable { ptr = helper::append(ptr, s); };
(map(args), ...);
res[len] = 0;
@@ -105,7 +107,7 @@ struct helper {
template <auto... Args> struct escape_t {
static constexpr const auto value = []() {
constexpr std::size_t len = (helper::size(Args) + ... + 2);
- std::array<char, len + 1> arr{CTRL::ESC, '[', 0};
+ std::array<char, len + 1> arr{Ctrl::ESC, '[', 0};
auto map = [ptr = arr.data() + 2](auto const &s) mutable { ptr = helper::append(ptr, s); };
(map(Args), ...);
arr[len] = 0;
@@ -175,12 +177,12 @@ static inline bool limit_256(int n) { return n >= 0 && n < 256; };
// Erase functions
erase_display
- MOTION m
+ Motion m
|
(int)m, 'J'
erase_line
- MOTION m
+ Motion m
|
(int)m, 'K'
@@ -208,12 +210,12 @@ static inline bool limit_256(int n) { return n >= 0 && n < 256; };
// palet colors
foreground
- COLOR color
+ Color color
|
(int)color + 30, 'm'
background
- COLOR color
+ Color color
|
(int)color + 40, 'm'
@@ -234,33 +236,33 @@ static inline bool limit_256(int n) { return n >= 0 && n < 256; };
foreground
int R, int G, int B
limit_256
- 38, ';', 5, ';', R, ';', G, ';', B, 'm'
+ 38, ';', 2, ';', R, ';', G, ';', B, 'm'
background
int R, int G, int B
limit_256
- 48, ';', 5, ';', R, ';', G, ';', B, 'm'
+ 48, ';', 2, ';', R, ';', G, ';', B, 'm'
// Set/reset text decorators
decor_set
- DECOR decor
+ Decor decor
|
(int)decor, 'm'
decor_reset
- DECOR decor
+ Decor decor
|
(int)decor + 20, 'm'
-// Save/load cursor position;
+// Save/restore cursor position;
cursor_save
|
|
's'
- cursor_load
+ cursor_restore
|
|
'u'
@@ -279,14 +281,14 @@ static inline bool limit_256(int n) { return n >= 0 && n < 256; };
// Private screen modes supported by most terminals
-// Save/load screen
+// Save/restore screen
- screen_show
+ screen_save
|
|
"?47h"
- screen_hide
+ screen_restore
|
|
"?47l"
@@ -303,18 +305,30 @@ static inline bool limit_256(int n) { return n >= 0 && n < 256; };
|
"?25l"
-// Show/hide alternate buffer
+// Enable/disable alternate buffer
- abuf_show
+ abuf_enable
|
|
"?1049h"
- abuf_hide
+ abuf_disable
|
|
"?1049l"
+// Enable/disable bracketed paste mode
+
+ paste_enable
+ |
+ |
+ "?2004h"
+
+ paste_disable
+ |
+ |
+ "?2004l"
+
%%
// Keyboard string TODO
diff --git a/src/parser.y b/src/parser.y
@@ -90,15 +90,15 @@ int main(const int argc, char *argv[]) {
}
struct list *dupes = record_dupes(records);
- record_print_dupes(dupes);
- printf("\n/* Template compile-time variables */\n");
+ printf("\n/* Template compile-time variables */\n\n");
+ record_print_dupes(dupes);
for(struct list *p = records; p; p = p->next) {
const struct record * r = (const struct record *)p->data;
record_print_template(r, list_find(dupes, r->name, scmp));
}
- printf("\n/* Run-time functions */\n");
+ printf("\n/* Run-time functions */\n\n");
for(struct list *p = records; p; p = p->next) {
const struct record * r = (const struct record *)p->data;
record_print_function(r);
@@ -181,6 +181,7 @@ void record_print_dupes(const struct list *l) {
printf("template <auto... val> static const char *%s_v;\n", l->data);
l = l->next;
}
+ printf("\n");
}
void record_print_function(const struct record *r) {