Cleanup, comments, and making extra test aps.
This commit is contained in:
5
Makefile
5
Makefile
@@ -14,6 +14,7 @@ else
|
|||||||
ASAN_FLAGS=
|
ASAN_FLAGS=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
APPS = test sbf
|
||||||
BREW86_PREFIX := $(shell arch -x86_64 /usr/local/homebrew/bin/brew --prefix)
|
BREW86_PREFIX := $(shell arch -x86_64 /usr/local/homebrew/bin/brew --prefix)
|
||||||
BREW_PREFIX := $(shell brew --prefix)
|
BREW_PREFIX := $(shell brew --prefix)
|
||||||
INCLUDE_DIRS = sbf-cpp $(BREW_PREFIX)/opt/ncurses/include
|
INCLUDE_DIRS = sbf-cpp $(BREW_PREFIX)/opt/ncurses/include
|
||||||
@@ -41,7 +42,7 @@ MANDATORY_TARGETS = Makefile
|
|||||||
|
|
||||||
.Phony: all clean app test
|
.Phony: all clean app test
|
||||||
|
|
||||||
all: $(BUILD_DIR)/$(CLIAPPNAME) app
|
all: $(BUILD_DIR)/$(CLIAPPNAME) app $(patsubst %, $(BUILD_DIR)/%, $(APPS))
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
@@ -74,6 +75,8 @@ $(BUILD_DIR)/$(CLIAPPNAME): $(patsubst %, $(BUILD_DIR)/%, $(APP_OBJECTS)) $(pats
|
|||||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/*.h $(MANDATORY_TARGETS)
|
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/*.h $(MANDATORY_TARGETS)
|
||||||
$(CC) $(CCFLAGS) -c -o $@ $<
|
$(CC) $(CCFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
#$(BUILD_DIR)/$(APPS) are built by "magic" using good enough rules
|
||||||
|
|
||||||
# We make our own fat libs cause homebrew sucks
|
# We make our own fat libs cause homebrew sucks
|
||||||
$(BUILD_DIR)/lib/libncurses.a: $(BREW_PREFIX)/opt/ncurses/lib $(BREW86_PREFIX)/opt/ncurses/lib
|
$(BUILD_DIR)/lib/libncurses.a: $(BREW_PREFIX)/opt/ncurses/lib $(BREW86_PREFIX)/opt/ncurses/lib
|
||||||
lipo -create -output ./build/lib/libncurses.a $(BREW_PREFIX)/opt/ncurses/lib/libncurses.a $(BREW86_PREFIX)/opt/ncurses/lib/libncurses.a
|
lipo -create -output ./build/lib/libncurses.a $(BREW_PREFIX)/opt/ncurses/lib/libncurses.a $(BREW86_PREFIX)/opt/ncurses/lib/libncurses.a
|
||||||
|
|||||||
@@ -22,29 +22,8 @@ using namespace std;
|
|||||||
| ╬ | WACS_D_PLUS | WACS_DDDD |
|
| ╬ | WACS_D_PLUS | WACS_DDDD |
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int set_double_border(WINDOW* screen) {
|
||||||
setlocale(LC_ALL, "");
|
return wborder_set(screen,
|
||||||
wchar_t buffer[255] = {0};
|
|
||||||
|
|
||||||
// Load ncurses and initialize stdscr
|
|
||||||
initscr();
|
|
||||||
// Enable raw mode to give us direct access to extra keys.
|
|
||||||
raw();
|
|
||||||
// Disable echoing characters as they are typed.
|
|
||||||
noecho();
|
|
||||||
// Enable keypad characters (function keys, arrow keys, and numpad keys.)
|
|
||||||
keypad(stdscr, true);
|
|
||||||
|
|
||||||
// Create a window with width: 17, height: 15, startX: 10, startY: 2
|
|
||||||
// These dimensions include the window bounds so the window actually starts at column 11 and row 3
|
|
||||||
// The size of the window is actually 17 wide by 15 tall, but after drawing the border the usable
|
|
||||||
// area is only 15x13 instead of 17x15.
|
|
||||||
// WINDOW* newwin(nlines, ncols, begin_y, begin_x)
|
|
||||||
// WINDOW* pWindow = newwin(15, 17, 2, 10);
|
|
||||||
refresh();
|
|
||||||
|
|
||||||
// Draw a box around the window with default chars
|
|
||||||
wborder_set(stdscr,
|
|
||||||
WACS_D_VLINE/*left side*/,
|
WACS_D_VLINE/*left side*/,
|
||||||
WACS_D_VLINE/*right side*/,
|
WACS_D_VLINE/*right side*/,
|
||||||
WACS_D_HLINE/*top side*/,
|
WACS_D_HLINE/*top side*/,
|
||||||
@@ -53,26 +32,47 @@ int main(int argc, char* argv[]) {
|
|||||||
WACS_D_URCORNER/*top right corner*/,
|
WACS_D_URCORNER/*top right corner*/,
|
||||||
WACS_D_LLCORNER/*bottom left corner*/,
|
WACS_D_LLCORNER/*bottom left corner*/,
|
||||||
WACS_D_LRCORNER/*bottom right corner*/);
|
WACS_D_LRCORNER/*bottom right corner*/);
|
||||||
|
}
|
||||||
|
|
||||||
int width;
|
int main(int argc, char* argv[]) {
|
||||||
int height;
|
setlocale(LC_ALL, "");
|
||||||
getmaxyx(stdscr, height, width);
|
wchar_t buffer[255] = {0};
|
||||||
swprintf(buffer, sizeof(buffer), L"width: %i, height: %i", width, height);
|
WINDOW* pWindow = nullptr;
|
||||||
mvaddwstr(1, 2, buffer);
|
// Load ncurses and initialize stdscr.
|
||||||
//mvaddwstr(5,5, L"x\u2562╢x");
|
initscr();
|
||||||
//mvadd_wch(3,2, WACS_D_PLUS);
|
pWindow = stdscr;
|
||||||
refresh();
|
// Enable raw mode to give us direct access to extra keys.
|
||||||
|
raw();
|
||||||
// wrefresh(pWindow);
|
// Disable echoing characters as they are typed.
|
||||||
|
noecho();
|
||||||
|
// Enable keypad characters. (function keys, arrow keys, and numpad keys.)
|
||||||
|
keypad(pWindow, true);
|
||||||
|
// Remove the delay when pressing esc.
|
||||||
set_escdelay(0);
|
set_escdelay(0);
|
||||||
bool done = false;
|
|
||||||
while(!done) {
|
int key = KEY_RESIZE;
|
||||||
int key = getch();
|
while(key != KEY_ESCAPE) {
|
||||||
swprintf(buffer, sizeof(buffer), L"0x%04o pressed", key);
|
if (key == KEY_RESIZE) {
|
||||||
mvaddwstr(2, 2, buffer);
|
// Clear the screen.
|
||||||
if (key == KEY_ESCAPE) {
|
werase(pWindow);
|
||||||
done = true;
|
// Draw a box around the window with default chars.
|
||||||
|
set_double_border(pWindow);
|
||||||
|
// Display the event
|
||||||
|
mvwaddwstr(pWindow, 2, 2, L"Resized");
|
||||||
|
// Get the window width and height.
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
getmaxyx(pWindow, height, width);
|
||||||
|
// Display the width and height.
|
||||||
|
swprintf(buffer, sizeof(buffer), L"width: %i, height: %i", width, height);
|
||||||
|
mvwaddwstr(pWindow, 1, 2, buffer);
|
||||||
|
} else {
|
||||||
|
// Display the keycode of the key that was pressed in hex and octal.
|
||||||
|
swprintf(buffer, sizeof(buffer), L"0x%04X %04o pressed", key, key);
|
||||||
|
mvwaddwstr(pWindow,2, 2, buffer);
|
||||||
}
|
}
|
||||||
|
wrefresh(pWindow);
|
||||||
|
key = wgetch(pWindow);
|
||||||
}
|
}
|
||||||
endwin();
|
endwin();
|
||||||
|
|
||||||
|
|||||||
80
sbf-cpp/sbf.cpp
Normal file
80
sbf-cpp/sbf.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#define _XOPEN_SOURCE_EXTENDED
|
||||||
|
#include <ncursesw/curses.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define KEY_ESCAPE 0033
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/*
|
||||||
|
| ╔ | WACS_D_ULCORNER | WACS_BDDB |
|
||||||
|
| ╚ | WACS_D_LLCORNER | WACS_DDBB |
|
||||||
|
| ╗ | WACS_D_URCORNER | WACS_BBDD |
|
||||||
|
| ╝ | WACS_D_LRCORNER | WACS_DBBD |
|
||||||
|
| ╣ | WACS_D_RTEE | WACS_DBDD |
|
||||||
|
| ╠ | WACS_D_LTEE | WACS_DDDB |
|
||||||
|
| ╩ | WACS_D_BTEE | WACS_DDBD |
|
||||||
|
| ╦ | WACS_D_TTEE | WACS_BDDD |
|
||||||
|
| ═ | WACS_D_HLINE | WACS_BDBD |
|
||||||
|
| ║ | WACS_D_VLINE | WACS_DBDB |
|
||||||
|
| ╬ | WACS_D_PLUS | WACS_DDDD |
|
||||||
|
*/
|
||||||
|
|
||||||
|
int set_double_border(WINDOW* screen) {
|
||||||
|
return wborder_set(screen,
|
||||||
|
WACS_D_VLINE/*left side*/,
|
||||||
|
WACS_D_VLINE/*right side*/,
|
||||||
|
WACS_D_HLINE/*top side*/,
|
||||||
|
WACS_D_HLINE/*bottom side*/,
|
||||||
|
WACS_D_ULCORNER/*top left corner*/,
|
||||||
|
WACS_D_URCORNER/*top right corner*/,
|
||||||
|
WACS_D_LLCORNER/*bottom left corner*/,
|
||||||
|
WACS_D_LRCORNER/*bottom right corner*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
wchar_t buffer[255] = {0};
|
||||||
|
WINDOW* pWindow = nullptr;
|
||||||
|
// Load ncurses and initialize stdscr.
|
||||||
|
initscr();
|
||||||
|
pWindow = stdscr;
|
||||||
|
// Enable raw mode to give us direct access to extra keys.
|
||||||
|
raw();
|
||||||
|
// Disable echoing characters as they are typed.
|
||||||
|
noecho();
|
||||||
|
// Enable keypad characters. (function keys, arrow keys, and numpad keys.)
|
||||||
|
keypad(pWindow, true);
|
||||||
|
// Remove the delay when pressing esc.
|
||||||
|
set_escdelay(0);
|
||||||
|
|
||||||
|
int key = KEY_RESIZE;
|
||||||
|
while(key != KEY_ESCAPE) {
|
||||||
|
if (key == KEY_RESIZE) {
|
||||||
|
// Clear the screen.
|
||||||
|
werase(pWindow);
|
||||||
|
// Draw a box around the window with default chars.
|
||||||
|
set_double_border(pWindow);
|
||||||
|
// Display the event
|
||||||
|
mvwaddwstr(pWindow, 2, 2, L"Resized");
|
||||||
|
// Get the window width and height.
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
getmaxyx(pWindow, height, width);
|
||||||
|
// Display the width and height.
|
||||||
|
swprintf(buffer, sizeof(buffer), L"width: %i, height: %i", width, height);
|
||||||
|
mvwaddwstr(pWindow, 1, 2, buffer);
|
||||||
|
} else {
|
||||||
|
// Display the keycode of the key that was pressed in hex and octal.
|
||||||
|
swprintf(buffer, sizeof(buffer), L"0x%04X %04o pressed", key, key);
|
||||||
|
mvwaddwstr(pWindow,2, 2, buffer);
|
||||||
|
}
|
||||||
|
wrefresh(pWindow);
|
||||||
|
key = wgetch(pWindow);
|
||||||
|
}
|
||||||
|
endwin();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
80
sbf-cpp/test.cpp
Normal file
80
sbf-cpp/test.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#define _XOPEN_SOURCE_EXTENDED
|
||||||
|
#include <ncursesw/curses.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define KEY_ESCAPE 0033
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/*
|
||||||
|
| ╔ | WACS_D_ULCORNER | WACS_BDDB |
|
||||||
|
| ╚ | WACS_D_LLCORNER | WACS_DDBB |
|
||||||
|
| ╗ | WACS_D_URCORNER | WACS_BBDD |
|
||||||
|
| ╝ | WACS_D_LRCORNER | WACS_DBBD |
|
||||||
|
| ╣ | WACS_D_RTEE | WACS_DBDD |
|
||||||
|
| ╠ | WACS_D_LTEE | WACS_DDDB |
|
||||||
|
| ╩ | WACS_D_BTEE | WACS_DDBD |
|
||||||
|
| ╦ | WACS_D_TTEE | WACS_BDDD |
|
||||||
|
| ═ | WACS_D_HLINE | WACS_BDBD |
|
||||||
|
| ║ | WACS_D_VLINE | WACS_DBDB |
|
||||||
|
| ╬ | WACS_D_PLUS | WACS_DDDD |
|
||||||
|
*/
|
||||||
|
|
||||||
|
int set_double_border(WINDOW* screen) {
|
||||||
|
return wborder_set(screen,
|
||||||
|
WACS_D_VLINE/*left side*/,
|
||||||
|
WACS_D_VLINE/*right side*/,
|
||||||
|
WACS_D_HLINE/*top side*/,
|
||||||
|
WACS_D_HLINE/*bottom side*/,
|
||||||
|
WACS_D_ULCORNER/*top left corner*/,
|
||||||
|
WACS_D_URCORNER/*top right corner*/,
|
||||||
|
WACS_D_LLCORNER/*bottom left corner*/,
|
||||||
|
WACS_D_LRCORNER/*bottom right corner*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
wchar_t buffer[255] = {0};
|
||||||
|
WINDOW* pWindow = nullptr;
|
||||||
|
// Load ncurses and initialize stdscr.
|
||||||
|
initscr();
|
||||||
|
pWindow = stdscr;
|
||||||
|
// Enable raw mode to give us direct access to extra keys.
|
||||||
|
raw();
|
||||||
|
// Disable echoing characters as they are typed.
|
||||||
|
noecho();
|
||||||
|
// Enable keypad characters. (function keys, arrow keys, and numpad keys.)
|
||||||
|
keypad(pWindow, true);
|
||||||
|
// Remove the delay when pressing esc.
|
||||||
|
set_escdelay(0);
|
||||||
|
|
||||||
|
int key = KEY_RESIZE;
|
||||||
|
while(key != KEY_ESCAPE) {
|
||||||
|
if (key == KEY_RESIZE) {
|
||||||
|
// Clear the screen.
|
||||||
|
werase(pWindow);
|
||||||
|
// Draw a box around the window with default chars.
|
||||||
|
set_double_border(pWindow);
|
||||||
|
// Display the event
|
||||||
|
mvwaddwstr(pWindow, 2, 2, L"Resized");
|
||||||
|
// Get the window width and height.
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
getmaxyx(pWindow, height, width);
|
||||||
|
// Display the width and height.
|
||||||
|
swprintf(buffer, sizeof(buffer), L"width: %i, height: %i", width, height);
|
||||||
|
mvwaddwstr(pWindow, 1, 2, buffer);
|
||||||
|
} else {
|
||||||
|
// Display the keycode of the key that was pressed in hex and octal.
|
||||||
|
swprintf(buffer, sizeof(buffer), L"0x%04X %04o pressed", key, key);
|
||||||
|
mvwaddwstr(pWindow,2, 2, buffer);
|
||||||
|
}
|
||||||
|
wrefresh(pWindow);
|
||||||
|
key = wgetch(pWindow);
|
||||||
|
}
|
||||||
|
endwin();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user