Adds ncursesw support.
This commit is contained in:
21
.vscode/c_cpp_properties.json
vendored
Normal file
21
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -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
|
||||||
|
}
|
||||||
25
Makefile
25
Makefile
@@ -14,14 +14,16 @@ else
|
|||||||
ASAN_FLAGS=
|
ASAN_FLAGS=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
INCLUDE_DIRS = sbf-cpp
|
BREW86_PREFIX := $(shell arch -x86_64 /usr/local/homebrew/bin/brew --prefix)
|
||||||
INCLUDES = $(patsubst %, -I%, $(INCLUDE_DIRS))
|
BREW_PREFIX := $(shell brew --prefix)
|
||||||
LIBRARY_DIRS =
|
INCLUDE_DIRS = sbf-cpp $(BREW_PREFIX)/opt/ncurses/include
|
||||||
LIBRARIES = $(patsubst %, -L%, $(LIBRARY_DIRS)) -lncurses
|
INCLUDES := $(patsubst %, -I%, $(INCLUDE_DIRS))
|
||||||
|
LIBRARY_DIRS = $(BUILD_DIR)/lib
|
||||||
|
LIBRARIES := $(patsubst %, -L%, $(LIBRARY_DIRS)) -lncurses
|
||||||
FRAMEWORK_NAMES =
|
FRAMEWORK_NAMES =
|
||||||
FRAMEWORKS = $(patsubst %, -framework %, $(FRAMEWORK_NAMES))
|
FRAMEWORKS := $(patsubst %, -framework %, $(FRAMEWORK_NAMES))
|
||||||
ARCHS = -arch arm64 -arch x86_64
|
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)
|
LDFLAGS := $(LIBRARIES) $(FRAMEWORKS) $(ARCHS) $(DBG_OPT_FLAGS) $(ASAN_FLAGS)
|
||||||
CC = clang++
|
CC = clang++
|
||||||
LD = clang++
|
LD = clang++
|
||||||
@@ -33,6 +35,7 @@ BUNDLEIDENTIFIER = com.majinnaibu.test.$(APPNAME)
|
|||||||
BUNDLESIGNATURE = SBF_
|
BUNDLESIGNATURE = SBF_
|
||||||
RESOURCES_DIR = Resources
|
RESOURCES_DIR = Resources
|
||||||
APP_OBJECTS = main.o
|
APP_OBJECTS = main.o
|
||||||
|
FAT_LIBS = ncurses
|
||||||
|
|
||||||
MANDATORY_TARGETS = Makefile
|
MANDATORY_TARGETS = Makefile
|
||||||
|
|
||||||
@@ -44,12 +47,16 @@ clean:
|
|||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
mkdir -p $(BUILD_DIR)
|
mkdir -p $(BUILD_DIR)
|
||||||
mkdir -p $(BUILD_DIR)/Contents
|
mkdir -p $(BUILD_DIR)/Contents
|
||||||
|
mkdir -p $(BUILD_DIR)/lib
|
||||||
mkdir -p $(BUNDLEFOLDER)/Contents/MacOS
|
mkdir -p $(BUNDLEFOLDER)/Contents/MacOS
|
||||||
mkdir -p $(BUNDLEFOLDER)/Contents/Resources
|
mkdir -p $(BUNDLEFOLDER)/Contents/Resources
|
||||||
|
|
||||||
test: clean all
|
test: clean all
|
||||||
./$(BUILD_DIR)/$(CLIAPPNAME)
|
./$(BUILD_DIR)/$(CLIAPPNAME)
|
||||||
|
|
||||||
|
run: $(BUILD_DIR)/$(CLIAPPNAME)
|
||||||
|
$(BUILD_DIR)/$(CLIAPPNAME)
|
||||||
|
|
||||||
# Main app
|
# Main app
|
||||||
app: $(BUILD_DIR)/$(CLIAPPNAME) $(SRC_DIR)/Info.plist $(RESOURCES_DIR)/en-US.lproj/InfoPlist.strings $(MANDATORY_TARGETS)
|
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
|
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 $(BUILD_DIR)/$(CLIAPPNAME) $(BUNDLEFOLDER)/Contents/MacOS/$(APPNAME)
|
||||||
cp -r $(RESOURCES_DIR)/* $(BUNDLEFOLDER)/Contents/Resources/
|
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))
|
$(LD) $(LDFLAGS) -o $@ $(patsubst %, $(BUILD_DIR)/%, $(APP_OBJECTS))
|
||||||
|
|
||||||
$(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 $@ $<
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>Metal Test</string>
|
<string>Storyteller's Best Friend</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
@@ -26,7 +26,5 @@
|
|||||||
<string></string>
|
<string></string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string></string>
|
<string></string>
|
||||||
<key>MetalCaptureEnabled</key>
|
|
||||||
<false/>
|
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -1,18 +1,79 @@
|
|||||||
#include <ncurses.h>
|
#define _XOPEN_SOURCE_EXTENDED
|
||||||
|
#include <ncursesw/curses.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define KEY_ESCAPE 0033
|
||||||
|
|
||||||
using namespace std;
|
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[]) {
|
int main(int argc, char* argv[]) {
|
||||||
// cout << "Hello, World!" << endl;
|
setlocale(LC_ALL, "");
|
||||||
|
wchar_t buffer[255] = {0};
|
||||||
|
|
||||||
|
// Load ncurses and initialize stdscr
|
||||||
initscr();
|
initscr();
|
||||||
|
// Enable raw mode to give us direct access to extra keys.
|
||||||
raw();
|
raw();
|
||||||
|
// Disable echoing characters as they are typed.
|
||||||
noecho();
|
noecho();
|
||||||
|
// Enable keypad characters (function keys, arrow keys, and numpad keys.)
|
||||||
keypad(stdscr, true);
|
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();
|
refresh();
|
||||||
getch();
|
|
||||||
|
// 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();
|
endwin();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user