diff --git a/Buffer.cc b/Buffer.cc index cb44e19..a2e89c7 100644 --- a/Buffer.cc +++ b/Buffer.cc @@ -66,11 +66,14 @@ Buffer::Buffer(std::filesystem::path fPath) this->name = fPath.filename().string(); this->cursor = Cursor(); this->file = OptFile(fPath.string()); - if (this->Exists()) { - /// \todo Should I signal an error here, or is it - /// okay for this to be a best-effort thing? - this->status = this->Refresh(); - } + // N.B. I am leaving this in to show that I thought about it, but + // it's the wrong choice. A Frame should call Refresh on a buffer + // when it's ready to load it. + // if (this->Exists()) { + // /// \todo Should I signal an error here, or is it + // /// okay for this to be a best-effort thing? + // this->status = this->Refresh(); + // } } diff --git a/CMakeLists.txt b/CMakeLists.txt index beffa40..9618a57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,12 +59,14 @@ set(HEADER_FILES Buffer.h File.h Cursor.h + Frame.h ) set(SOURCE_FILES Defs.cc Buffer.cc File.cc Cursor.cc + Frame.cc ) add_executable(ke main.cc ${SOURCE_FILES} ${HEADER_FILES}) diff --git a/Frame.cc b/Frame.cc new file mode 100644 index 0000000..0adb7f4 --- /dev/null +++ b/Frame.cc @@ -0,0 +1,64 @@ +// +// Created by kyle on 10/14/23. +// + +#include "Frame.h" + + +void +Frame::Add() +{ + auto buffer = new Buffer; + + this->bmap[buffer->Name()] = buffer; + + if (this->bmap.size() == 1) { + this->activeBuffer = buffer->Name(); + } +} + + +void +Frame::Add(std::string name) +{ + auto buffer = new Buffer(name); + + // TODO: find the small buffer name that doesn't conflict with + // any other buffers. Idea: deconflict private method? + + this->bmap[buffer->Name()] = buffer; + + if (this->bmap.size() == 1) { + this->activeBuffer = buffer->Name(); + } +} + + +void +Frame::Add(std::filesystem::path path) +{ + auto buffer = new Buffer(path); + + // TODO: find the small buffer name that doesn't conflict with + // any other buffers. Idea: deconflict private method? + + this->bmap[buffer->Name()] = buffer; + + if (this->bmap.size() == 1) { + this->activeBuffer = buffer->Name(); + } +} + + +Buffer::FileStatus +Frame::Refresh() +{ + return this->bmap[this->activeBuffer]->Refresh(); +} + + +Buffer::FileStatus +Frame::Flush() +{ + return this->bmap[this->activeBuffer]->Flush(); +} diff --git a/Frame.h b/Frame.h new file mode 100644 index 0000000..727097d --- /dev/null +++ b/Frame.h @@ -0,0 +1,37 @@ +// +// Created by kyle on 10/14/23. +// + +#ifndef KGE_FRAME_H +#define KGE_FRAME_H + + +#include +#include +#include +#include + +#include "Buffer.h" + + +class Frame { +public: + Frame(); + + void Add(); + void Add(std::string name); + void Add(std::filesystem::path path); + + /// Refresh will attempt to load the active buffer. + Buffer::FileStatus Refresh(); + + /// Flush will attempt to write the active buffer. + bool Flush(); + +private: + std::map bmap; + std::string activeBuffer; +}; + + +#endif //KGE_FRAME_H diff --git a/ext/imgui/backends/vulkan/generate_spv.sh b/ext/imgui/backends/vulkan/generate_spv.sh old mode 100755 new mode 100644 diff --git a/fonts/gen_font_includes.py b/fonts/gen_font_includes.py old mode 100755 new mode 100644 diff --git a/scripts/install-cmake-debian.sh b/scripts/install-cmake-debian.sh old mode 100644 new mode 100755 index 6d64b17..55ddac1 --- a/scripts/install-cmake-debian.sh +++ b/scripts/install-cmake-debian.sh @@ -6,36 +6,36 @@ set -eu source /etc/lsb-release preinstall () { - echo "[+] preparing to install" - sudo apt-get update - sudo apt-get install ca-certificates gpg wget + echo "[+] preparing to install" + sudo apt-get update + sudo apt-get install ca-certificates gpg wget } do_install () { -if [ ! -f /etc/apt/sources.list.d/kitware.list ] -then - echo "[+] fetching initial keyring" - wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null + if [ ! -f /etc/apt/sources.list.d/kitware.list ] + then + echo "[+] fetching initial keyring" + wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null - echo "[+] adding repo to sources.list.d" - echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${DISTRIB_RELEASE} main" | \ - sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null - sudo apt-get update + echo "[+] adding repo to sources.list.d" + echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${DISTRIB_RELEASE} main" | \ + sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null + sudo apt-get update - echo "[+] installing kitware keyring" - if [ -f "/usr/share/keyrings/kitware-archive-keyring.gpg" ] - then - sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg - fi - sudo apt-get install kitware-archive-keyring -fi + echo "[+] installing kitware keyring" + if [ -f "/usr/share/keyrings/kitware-archive-keyring.gpg" ] + then + sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg + fi + sudo apt-get install kitware-archive-keyring + fi -if [ "${USE_CMAKE_RC}" = "YES" ] -then - echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${DISTRIB_RELEASE}-rc main' | \ - sudo tee -a /etc/apt/sources.list.d/kitware.list >/dev/null - sudo apt-get update -fi + if [ "${USE_CMAKE_RC}" = "YES" ] + then + echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${DISTRIB_RELEASE}-rc main' | \ + sudo tee -a /etc/apt/sources.list.d/kitware.list >/dev/null + sudo apt-get update + fi } -sudo apt-get install cmake cmake-curses-gui cmake-extras +do_install diff --git a/scripts/install-depdendencies.sh b/scripts/install-depdendencies.sh old mode 100644 new mode 100755 index c0c7578..d42aa4e --- a/scripts/install-depdendencies.sh +++ b/scripts/install-depdendencies.sh @@ -1,4 +1,101 @@ #!/usr/bin/env bash +##################################################################### +# This script attempts to install the appopriate build dependencies # +# for the host system. # +# # +# For platforms marked as unverified, it means that I was able to # +# start a Docker container for that platform and could look up the # +# right package names. I haven't actually tried building on these # +# platforms. # +# # +# This is primarily developed on the latest Ubuntu LTS release and # +# MacOS; other platforms are best-effort. # +##################################################################### + set -eu +install_debianesque () { + echo "[+] distribution is ${DISTRIB_ID}, choosing Debianesque install." + + echo "[+] installing tools" + sudo apt-get install git cmake clang scdoc + + echo "[+] installing libraries and development headers" + sudo apt-get install libsdl2-dev libfreetype-dev +} + +install_redhat () { + echo "[+] distribution is ${DISTRIB_ID}, choosing Redhat install." + echo "[!] WARNING: installation for Redhat systems is unverified." + + echo "[+] installing tools" + sudo dnf install git cmake clang scdoc + + echo "[+] installing libraries and development headers" + sudo dnf install SDL2-devel freetype-devel +} + +install_alpine () { + echo "[+] distribution is ${DISTRIB_ID}, choosing Alpine install." + echo "[!] WARNING: installation for Alpine systems is unverified." + + echo "[+] installing tools" + sudo dnf install git cmake clang scdoc + + echo "[+] installing libraries and development headers" + sudo dnf install sdl2-dev freetype-dev +} + +install_macos () { + # TODO: consider supporting macports? + echo "[+] host system is MacOS" + + echo "[+] installing tools" + brew install git cmake scdoc + + echo "[+] installing libraries and development headers" + # TODO: look up proper package names in homebrew +} + + +install_linux () { + echo "[+] host system is Linux" + [[ -f "/etc/lsb-release" ]] && source /etc/lsb-release + if [ -z "${DISTRIB_ID}" ] + then + if [ -d /etc/apt ] + then + DISTRIB_ID="apt-based" + elif [ -f /etc/alpine-release ] + DISTRIB_ID=Alpine + elif [ -d /etc/dnf -o /etc/yum.repos.d ] + # I don't use Fedora, this is based on a cursory + # glance at the filesystem on a Docker image. + DISTRIB_ID="Fedora" + fi + fi + + case ${DISTRIB_ID} in + Ubuntu) install_debianesque ;; + Debian) install_debianesque ;; + apt-based) install_debianesque ;; + Fedora) install_redhat ;; + Alpine) install_alpine ;; + + *) + echo "[!] distribution ${DISTRIB_ID} isn't supported in this script." > /dev/null + ;; + esac +} + + +case "$(uname -s)" in + Linux) install_linux ;; + Darwin) install_macos ;; + *) + echo "[!] platform $(uname -s) isn't supported in this script." > /dev/null + ;; +esac + +