From d5841c264d2bdb92ced716c7ba5337fb418c94f2 Mon Sep 17 00:00:00 2001 From: Kittycannon Date: Sun, 7 Jun 2026 21:12:17 -0600 Subject: [PATCH] changes while making spider live debug --- makefile | 8 ++------ makelib.mak | 8 ++------ out.txt | 2 -- src/desktoplib/main.cpp | 5 ----- src/desktoplib/os/common.hpp | 2 ++ src/desktoplib/os/unix.cpp | 4 +++- src/desktoplib/os/windows.cpp | 8 +++++++- src/desktoplib/terminal/Terminal.cpp | 12 ++++++++---- 8 files changed, 24 insertions(+), 25 deletions(-) delete mode 100644 out.txt diff --git a/makefile b/makefile index 86e3135..bb59865 100644 --- a/makefile +++ b/makefile @@ -38,7 +38,7 @@ OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJE all: directories $(TARGET) #Remake -remake: cleaner all +remake: clean all #Make the Directories directories: @@ -49,10 +49,6 @@ directories: clean: @$(RM) -rf $(BUILDDIR) -#Full Clean, Objects and Binaries -cleaner: clean - @$(RM) -rf $(TARGETDIR) - #Pull in dependency info for *existing* .o files -include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT)) @@ -71,4 +67,4 @@ $(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT) @rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp #Non-File Targets -.PHONY: all remake clean cleaner resources \ No newline at end of file +.PHONY: all remake clean diff --git a/makelib.mak b/makelib.mak index a4d08d7..dbbe1c3 100644 --- a/makelib.mak +++ b/makelib.mak @@ -37,7 +37,7 @@ OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJE all: directories $(TARGET) #Remake -remake: cleaner all +remake: clean all #Make the Directories directories: @@ -48,10 +48,6 @@ directories: clean: @$(RM) -rf $(BUILDDIR) -#Full Clean, Objects and Binaries -cleaner: clean - @$(RM) -rf $(TARGETDIR) - #Pull in dependency info for *existing* .o files -include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT)) @@ -70,4 +66,4 @@ $(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT) @rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp #Non-File Targets -.PHONY: all remake clean cleaner \ No newline at end of file +.PHONY: all remake clean diff --git a/out.txt b/out.txt deleted file mode 100644 index dd16664..0000000 --- a/out.txt +++ /dev/null @@ -1,2 +0,0 @@ -g++ -std=c++20 -O2 -Wall -Werror -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough -Wsuggest-override -Wextra-semi -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wuseless-cast -I./src/ -c -o bin/desktoplib/terminal/Terminal.o src/desktoplib/terminal/Terminal.cpp -g++ -std=c++20 -static-libstdc++ -static-libgcc -Wl,--fatal-warnings -Wl,--warn-common -o out/out.exe bin/desktoplib/main.o bin/desktoplib/os/unix.o bin/desktoplib/os/windows.o bin/desktoplib/terminal/Terminal.o diff --git a/src/desktoplib/main.cpp b/src/desktoplib/main.cpp index 85940c3..eaf3505 100644 --- a/src/desktoplib/main.cpp +++ b/src/desktoplib/main.cpp @@ -7,12 +7,7 @@ #include #include -#include - int main() { - SetConsoleOutputCP(CP_UTF8); - SetConsoleCP(CP_UTF8); - using namespace ckitty::terminal; Terminal term; diff --git a/src/desktoplib/os/common.hpp b/src/desktoplib/os/common.hpp index 9dc21f4..9e79071 100644 --- a/src/desktoplib/os/common.hpp +++ b/src/desktoplib/os/common.hpp @@ -9,6 +9,8 @@ namespace ckitty { namespace os { + void setup(); + int getKey(bool blocking); std::optional getChar(bool blocking); diff --git a/src/desktoplib/os/unix.cpp b/src/desktoplib/os/unix.cpp index 5f2699c..011bf8f 100644 --- a/src/desktoplib/os/unix.cpp +++ b/src/desktoplib/os/unix.cpp @@ -10,6 +10,8 @@ namespace ckitty { namespace terminal { namespace os { + void setup() {} + int getKey(bool blocking) { if (!blocking) { // Set non-blocking read @@ -18,7 +20,7 @@ namespace ckitty { unsigned char ch; int n = read(STDIN_FILENO, &ch, 1); fcntl(STDIN_FILENO, F_SETFL, oldf); - return (n > 0) ? ch : -1; + return (n > 0) ? ch : key::UNKNOWN; } unsigned char buf[3]; diff --git a/src/desktoplib/os/windows.cpp b/src/desktoplib/os/windows.cpp index 75ef3bc..407b1ac 100644 --- a/src/desktoplib/os/windows.cpp +++ b/src/desktoplib/os/windows.cpp @@ -10,10 +10,16 @@ namespace ckitty { namespace terminal { namespace os { + void setup() { + SetConsoleOutputCP(CP_UTF8); + SetConsoleCP(CP_UTF8); + setRawMode(true); + } + int getKey(bool blocking) { // Handle non-blocking check for the console if (!blocking && !_kbhit()) { - return -1; + return key::UNKNOWN; } // _getch() blocks by default diff --git a/src/desktoplib/terminal/Terminal.cpp b/src/desktoplib/terminal/Terminal.cpp index 01618e9..88d9196 100644 --- a/src/desktoplib/terminal/Terminal.cpp +++ b/src/desktoplib/terminal/Terminal.cpp @@ -164,6 +164,9 @@ namespace ckitty { Terminal::Terminal() : _os(&std::cout), _is(&std::cin), _own(false) { + // setup the terminal if we don't own the + // streams, aka, the system terminal! + if(!_own) os::setup(); } Terminal::~Terminal() { @@ -176,10 +179,11 @@ namespace ckitty { // ------ // Terminal& Terminal::fill(const std::string_view color) { - // 1. Set background color - // 2. Clear screen (2J) - // 3. Move cursor to home (H) - (*_os) << color << CSI << "2J" << CSI << "H" << std::flush; + // 1. Apply color string + // 2. [3J] clears the entire terminal scrollback buffer with that active color + // 3. [2J] clears the visible screen + // 4. [H] returns cursor home + (*_os) << color << CSI << "3J" << CSI << "2J" << CSI << "H" << std::flush; return *this; }