diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..4625718
--- /dev/null
+++ b/.vscode/c_cpp_properties.json
@@ -0,0 +1,21 @@
+{
+ "configurations": [
+ {
+ "name": "Mac",
+ "includePath": [
+ "${workspaceFolder}/**",
+ "/opt/homebrew/include",
+ "/opt/homebrew/opt/ncurses/include"
+ ],
+ "defines": [],
+ "macFrameworkPath": [
+ "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
+ ],
+ "compilerPath": "/usr/bin/clang",
+ "cStandard": "c17",
+ "cppStandard": "c++17",
+ "intelliSenseMode": "macos-clang-arm64"
+ }
+ ],
+ "version": 4
+}
\ No newline at end of file
diff --git a/Makefile b/Makefile
index cf269c9..065d238 100644
--- a/Makefile
+++ b/Makefile
@@ -14,14 +14,16 @@ else
ASAN_FLAGS=
endif
-INCLUDE_DIRS = sbf-cpp
-INCLUDES = $(patsubst %, -I%, $(INCLUDE_DIRS))
-LIBRARY_DIRS =
-LIBRARIES = $(patsubst %, -L%, $(LIBRARY_DIRS)) -lncurses
+BREW86_PREFIX := $(shell arch -x86_64 /usr/local/homebrew/bin/brew --prefix)
+BREW_PREFIX := $(shell brew --prefix)
+INCLUDE_DIRS = sbf-cpp $(BREW_PREFIX)/opt/ncurses/include
+INCLUDES := $(patsubst %, -I%, $(INCLUDE_DIRS))
+LIBRARY_DIRS = $(BUILD_DIR)/lib
+LIBRARIES := $(patsubst %, -L%, $(LIBRARY_DIRS)) -lncurses
FRAMEWORK_NAMES =
-FRAMEWORKS = $(patsubst %, -framework %, $(FRAMEWORK_NAMES))
+FRAMEWORKS := $(patsubst %, -framework %, $(FRAMEWORK_NAMES))
ARCHS = -arch arm64 -arch x86_64
-CCFLAGS := -std=c++17 -Wall -fno-objc-arc $(INCLUDES) $(DBG_OPT_FLAGS) $(ASAN_FLAGS) $(ARCHS)
+CCFLAGS := -std=c++17 -Wall -fno-objc-arc -finput-charset=UTF-8 $(INCLUDES) $(DBG_OPT_FLAGS) $(ASAN_FLAGS) $(ARCHS)
LDFLAGS := $(LIBRARIES) $(FRAMEWORKS) $(ARCHS) $(DBG_OPT_FLAGS) $(ASAN_FLAGS)
CC = clang++
LD = clang++
@@ -33,6 +35,7 @@ BUNDLEIDENTIFIER = com.majinnaibu.test.$(APPNAME)
BUNDLESIGNATURE = SBF_
RESOURCES_DIR = Resources
APP_OBJECTS = main.o
+FAT_LIBS = ncurses
MANDATORY_TARGETS = Makefile
@@ -44,12 +47,16 @@ clean:
rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
mkdir -p $(BUILD_DIR)/Contents
+ mkdir -p $(BUILD_DIR)/lib
mkdir -p $(BUNDLEFOLDER)/Contents/MacOS
mkdir -p $(BUNDLEFOLDER)/Contents/Resources
test: clean all
./$(BUILD_DIR)/$(CLIAPPNAME)
+run: $(BUILD_DIR)/$(CLIAPPNAME)
+ $(BUILD_DIR)/$(CLIAPPNAME)
+
# Main app
app: $(BUILD_DIR)/$(CLIAPPNAME) $(SRC_DIR)/Info.plist $(RESOURCES_DIR)/en-US.lproj/InfoPlist.strings $(MANDATORY_TARGETS)
cp $(SRC_DIR)/Info.plist $(BUILD_DIR)/Contents/Info.plist
@@ -61,8 +68,12 @@ app: $(BUILD_DIR)/$(CLIAPPNAME) $(SRC_DIR)/Info.plist $(RESOURCES_DIR)/en-US.lpr
cp $(BUILD_DIR)/$(CLIAPPNAME) $(BUNDLEFOLDER)/Contents/MacOS/$(APPNAME)
cp -r $(RESOURCES_DIR)/* $(BUNDLEFOLDER)/Contents/Resources/
-$(BUILD_DIR)/$(CLIAPPNAME): $(patsubst %, $(BUILD_DIR)/%, $(APP_OBJECTS)) $(MANDATORY_TARGETS)
+$(BUILD_DIR)/$(CLIAPPNAME): $(patsubst %, $(BUILD_DIR)/%, $(APP_OBJECTS)) $(patsubst %, $(BUILD_DIR)/lib/lib%.a, $(FAT_LIBS)) $(MANDATORY_TARGETS)
$(LD) $(LDFLAGS) -o $@ $(patsubst %, $(BUILD_DIR)/%, $(APP_OBJECTS))
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/*.h $(MANDATORY_TARGETS)
$(CC) $(CCFLAGS) -c -o $@ $<
+
+# We make our own fat libs cause homebrew sucks
+$(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
diff --git a/sbf-cpp/Info.plist b/sbf-cpp/Info.plist
index b8889c9..7afc3ca 100644
--- a/sbf-cpp/Info.plist
+++ b/sbf-cpp/Info.plist
@@ -7,7 +7,7 @@
CFBundleInfoDictionaryVersion
6.0
CFBundleDisplayName
- Metal Test
+ Storyteller's Best Friend
CFBundlePackageType
APPL
CFBundleVersion
@@ -26,7 +26,5 @@
CFBundleSignature
- MetalCaptureEnabled
-
diff --git a/sbf-cpp/main.cpp b/sbf-cpp/main.cpp
index c3bd813..1469af2 100644
--- a/sbf-cpp/main.cpp
+++ b/sbf-cpp/main.cpp
@@ -1,19 +1,80 @@
-#include
+#define _XOPEN_SOURCE_EXTENDED
+#include
#include
+#include
+#include
+
+#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 main(int argc, char* argv[]) {
- // cout << "Hello, World!" << endl;
+ setlocale(LC_ALL, "");
+ 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);
- printw("Hello, World!");
+ // 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();
- getch();
- endwin();
+ // Draw a box around the window with default chars
+ wborder_set(stdscr,
+ 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 width;
+ int height;
+ getmaxyx(stdscr, height, width);
+ swprintf(buffer, sizeof(buffer), L"width: %i, height: %i", width, height);
+ mvaddwstr(1, 2, buffer);
+ //mvaddwstr(5,5, L"x\u2562╢x");
+ //mvadd_wch(3,2, WACS_D_PLUS);
+ refresh();
+
+ // wrefresh(pWindow);
+ set_escdelay(0);
+ bool done = false;
+ while(!done) {
+ int key = getch();
+ swprintf(buffer, sizeof(buffer), L"0x%04o pressed", key);
+ mvaddwstr(2, 2, buffer);
+ if (key == KEY_ESCAPE) {
+ done = true;
+ }
+ }
+ endwin();
+
return 0;
}