initial load
This commit is contained in:
8
desktoplib.code-workspace
Normal file
8
desktoplib.code-workspace
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
73
makefile
Normal file
73
makefile
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#Compiler and Linker
|
||||||
|
CC := g++
|
||||||
|
|
||||||
|
#The Target Binary Program
|
||||||
|
TARGET := out.exe
|
||||||
|
|
||||||
|
#The Directories, Source, Includes, Objects, Binary and Resources
|
||||||
|
SRCDIR := src
|
||||||
|
BUILDDIR := bin
|
||||||
|
TARGETDIR := out
|
||||||
|
SRCEXT := cpp
|
||||||
|
DEPEXT := d
|
||||||
|
OBJEXT := o
|
||||||
|
|
||||||
|
#Flags, Libraries and Includes
|
||||||
|
ROOT := ./
|
||||||
|
CFLAGS := -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
|
||||||
|
LFLAGS := -std=c++20 -static-libstdc++ -static-libgcc \
|
||||||
|
-Wl,--fatal-warnings -Wl,--warn-common
|
||||||
|
LIB :=
|
||||||
|
INC := -I./src/
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
#DO NOT EDIT BELOW THIS LINE
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
|
||||||
|
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
|
||||||
|
|
||||||
|
#Defauilt Make
|
||||||
|
all: directories $(TARGET)
|
||||||
|
|
||||||
|
#Remake
|
||||||
|
remake: cleaner all
|
||||||
|
|
||||||
|
#Make the Directories
|
||||||
|
directories:
|
||||||
|
@mkdir -p $(TARGETDIR)
|
||||||
|
@mkdir -p $(BUILDDIR)
|
||||||
|
|
||||||
|
#Clean only Objecst
|
||||||
|
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))
|
||||||
|
|
||||||
|
#Link
|
||||||
|
$(TARGET): $(OBJECTS)
|
||||||
|
$(CC) $(LFLAGS) -o $(TARGETDIR)/$(TARGET) $^ $(LIB)
|
||||||
|
|
||||||
|
#Compile
|
||||||
|
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
|
||||||
|
@$(CC) $(CFLAGS) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT)
|
||||||
|
@cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp
|
||||||
|
@sed -e 's|.*:|$(BUILDDIR)/$*.$(OBJEXT):|' < $(BUILDDIR)/$*.$(DEPEXT).tmp > $(BUILDDIR)/$*.$(DEPEXT)
|
||||||
|
@sed -e 's/.*://' -e 's/\\$$//' < $(BUILDDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(BUILDDIR)/$*.$(DEPEXT)
|
||||||
|
@rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp
|
||||||
|
|
||||||
|
#Non-File Targets
|
||||||
|
.PHONY: all remake clean cleaner resources
|
||||||
292
src/desktoplib/terminal/Terminal.hpp
Normal file
292
src/desktoplib/terminal/Terminal.hpp
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace ckitty {
|
||||||
|
|
||||||
|
namespace terminal {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Positions in the terminal begin at
|
||||||
|
* the origin (1,1). Usually, x are columns
|
||||||
|
* and y are rows. Also, they are expressed
|
||||||
|
* in (y, x) aka (row, column). Here, they
|
||||||
|
* are expressed in (x, y) order for
|
||||||
|
* ease with people familiar with cartesian
|
||||||
|
* coordinates.
|
||||||
|
*/
|
||||||
|
struct pos {
|
||||||
|
public:
|
||||||
|
int x, y;
|
||||||
|
pos(int x, int y);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a relative movement in the
|
||||||
|
* cursor.
|
||||||
|
*/
|
||||||
|
struct move {
|
||||||
|
public:
|
||||||
|
int x, y;
|
||||||
|
move(int x, int y);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an escape sequence which
|
||||||
|
* changes the color of the background.
|
||||||
|
*/
|
||||||
|
struct backg {
|
||||||
|
friend class Terminal;
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const backg BLACK; static const backg B_BLACK;
|
||||||
|
static const backg RED; static const backg B_RED;
|
||||||
|
static const backg GREEN; static const backg B_GREEN;
|
||||||
|
static const backg YELLOW; static const backg B_YELLOW;
|
||||||
|
static const backg BLUE; static const backg B_BLUE;
|
||||||
|
static const backg MAGENTA; static const backg B_MAGENTA;
|
||||||
|
static const backg CYAN; static const backg B_CYAN;
|
||||||
|
static const backg WHITE; static const backg B_WHITE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::string_view code;
|
||||||
|
backg(const std::string_view code);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static backg rgb(int r, int g, int b);
|
||||||
|
static backg hsl(float hue, float sat, float lum);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an escape sequence which
|
||||||
|
* changes the color of the foreground.
|
||||||
|
*/
|
||||||
|
struct color {
|
||||||
|
friend class Terminal;
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const color BLACK; static const color B_BLACK;
|
||||||
|
static const color RED; static const color B_RED;
|
||||||
|
static const color GREEN; static const color B_GREEN;
|
||||||
|
static const color YELLOW; static const color B_YELLOW;
|
||||||
|
static const color BLUE; static const color B_BLUE;
|
||||||
|
static const color MAGENTA; static const color B_MAGENTA;
|
||||||
|
static const color CYAN; static const color B_CYAN;
|
||||||
|
static const color WHITE; static const color B_WHITE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string_view code;
|
||||||
|
color(const std::string_view code);
|
||||||
|
public:
|
||||||
|
static color rgb(int r, int g, int b);
|
||||||
|
static color hsl(float hue, float sat, float lum);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an escape code which will alter
|
||||||
|
* the style of the printed text
|
||||||
|
*/
|
||||||
|
struct style {
|
||||||
|
friend class Terminal;
|
||||||
|
public:
|
||||||
|
static const style RESET;
|
||||||
|
static const style BOLD;
|
||||||
|
static const style ITALIC;
|
||||||
|
static const style FAINT;
|
||||||
|
static const style STRIKE;
|
||||||
|
private:
|
||||||
|
std::string_view code;
|
||||||
|
style(const std::string_view code);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a keyboard key input.
|
||||||
|
*/
|
||||||
|
struct key {
|
||||||
|
friend class Terminal;
|
||||||
|
public:
|
||||||
|
// Key Definitions (ASCII OK) //
|
||||||
|
static constexpr const char UP = 0x80;
|
||||||
|
static constexpr const char DOWN = 0x81;
|
||||||
|
static constexpr const char LEFT = 0x82;
|
||||||
|
static constexpr const char RIGHT = 0x83;
|
||||||
|
static constexpr const char ENTER = 0x84;
|
||||||
|
static constexpr const char ESC = 0x85;
|
||||||
|
static constexpr const char BACKSPACE = 0x86;
|
||||||
|
static constexpr const char UNKNOWN = 0xFF;
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a mouse input.
|
||||||
|
*/
|
||||||
|
struct mouse {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a terminal, which allows for displaying
|
||||||
|
* text based aplications. Actual constrains are placed by
|
||||||
|
* the trifecta of OS supported.
|
||||||
|
*/
|
||||||
|
class Terminal {
|
||||||
|
private:
|
||||||
|
std::ostream* _os;
|
||||||
|
std::istream* _is;
|
||||||
|
bool _own;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Terminal();
|
||||||
|
|
||||||
|
~Terminal();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills the screen with a specific background color.
|
||||||
|
* @param color The background color constant (e.g., Terminal::BG_BLUE)
|
||||||
|
*/
|
||||||
|
Terminal& fill(const std::string_view color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the screen
|
||||||
|
*/
|
||||||
|
Terminal& cls();
|
||||||
|
|
||||||
|
Terminal& altbuff(bool enable);
|
||||||
|
|
||||||
|
Terminal& createScrollRange(int start, int end);
|
||||||
|
|
||||||
|
Terminal& undoScrollRange();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears a specific row.
|
||||||
|
* @param row The 1-based index of the row to clear.
|
||||||
|
*/
|
||||||
|
Terminal& clearRow(int row);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears a range of rows (inclusive).
|
||||||
|
* @param start The first row.
|
||||||
|
* @param end The last row.
|
||||||
|
*/
|
||||||
|
Terminal& clearRows(int start, int end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears a specific column.
|
||||||
|
* @param col The 1-based index of the column to clear.
|
||||||
|
*/
|
||||||
|
Terminal& clearColumn(int col);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears a range of columns (inclusive).
|
||||||
|
* @param start The first column.
|
||||||
|
* @param end The last column.
|
||||||
|
*/
|
||||||
|
Terminal& clearColumns(int start, int end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows / Hides the cursor.
|
||||||
|
*/
|
||||||
|
Terminal& cursor(bool show);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flushes the output buffer
|
||||||
|
*/
|
||||||
|
Terminal& flush();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the input buffer.
|
||||||
|
* Useful for some specific input cases
|
||||||
|
*/
|
||||||
|
Terminal& sink();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Terminal& wait();
|
||||||
|
|
||||||
|
int getKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get key non blocking
|
||||||
|
*/
|
||||||
|
int getKeyNb();
|
||||||
|
|
||||||
|
std::optional<std::string> getChar();
|
||||||
|
|
||||||
|
std::optional<std::string> getCharNb();
|
||||||
|
|
||||||
|
pos getSize();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
Terminal& operator<<(const T& msg) {
|
||||||
|
(*_os) << msg;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Terminal& operator<<(const std::string_view& msg);
|
||||||
|
|
||||||
|
Terminal& operator<<(const pos c);
|
||||||
|
|
||||||
|
Terminal& operator<<(const move c);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an operation which will print up
|
||||||
|
* to a specific amount of characters.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
Terminal& subprint(int i0, int i1, const T& msg) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints a centered version of the final text,
|
||||||
|
* adding padding to center it as best as it can.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
Terminal& center(int width, const T& msg) {
|
||||||
|
// to string
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << msg;
|
||||||
|
std::string s = oss.str();
|
||||||
|
|
||||||
|
// then print
|
||||||
|
if (s.length() >= isize(width)) {
|
||||||
|
std::cout << s;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
isize total_padding = isize(width) - s.length();
|
||||||
|
isize left_padding = total_padding / 2;
|
||||||
|
std::cout << std::string(left_padding, ' ');
|
||||||
|
std::cout << s;
|
||||||
|
std::cout << std::string(total_padding - left_padding, ' ');
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Centered version of the subprint version.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
Terminal& subprint_center(int i0, int i1, const T& msg) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
Terminal& read(T& var) {
|
||||||
|
std::cin >> var;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
0
src/desktoplib/terminal/ui/Box.hpp
Normal file
0
src/desktoplib/terminal/ui/Box.hpp
Normal file
0
src/desktoplib/terminal/ui/Element.hpp
Normal file
0
src/desktoplib/terminal/ui/Element.hpp
Normal file
2
src/desktoplib/terminal/ui/InnerScroll.hpp
Normal file
2
src/desktoplib/terminal/ui/InnerScroll.hpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
|
||||||
0
src/desktoplib/terminal/ui/MenuMap.hpp
Normal file
0
src/desktoplib/terminal/ui/MenuMap.hpp
Normal file
3
src/desktoplib/terminal/ui/TitledBox.hpp
Normal file
3
src/desktoplib/terminal/ui/TitledBox.hpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user