diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d74344c..ca8e2c9 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -32,29 +32,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
@@ -142,7 +123,7 @@
1764457173148
-
+
diff --git a/Buffer.cpp b/Buffer.cpp
index 493ecca..f353e09 100644
--- a/Buffer.cpp
+++ b/Buffer.cpp
@@ -2,6 +2,7 @@
#include
#include
+#include
Buffer::Buffer() = default;
@@ -17,11 +18,29 @@ Buffer::Buffer(const std::string &path)
bool
Buffer::OpenFromFile(const std::string &path, std::string &err)
{
- std::ifstream in(path, std::ios::in | std::ios::binary);
- if (!in) {
- err = "Failed to open file: " + path;
- return false;
- }
+ // If the file doesn't exist, initialize an empty, non-file-backed buffer
+ // with the provided filename. Do not touch the filesystem until Save/SaveAs.
+ if (!std::filesystem::exists(path)) {
+ rows_.clear();
+ nrows_ = 0;
+ filename_ = path;
+ is_file_backed_ = false;
+ dirty_ = false;
+
+ // Reset cursor/viewport state
+ curx_ = cury_ = rx_ = 0;
+ rowoffs_ = coloffs_ = 0;
+ mark_set_ = false;
+ mark_curx_ = mark_cury_ = 0;
+
+ return true;
+ }
+
+ std::ifstream in(path, std::ios::in | std::ios::binary);
+ if (!in) {
+ err = "Failed to open file: " + path;
+ return false;
+ }
rows_.clear();
std::string line;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e9a7d4d..0edb1ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,7 +44,7 @@ endif ()
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
-set(SOURCES
+set(COMMON_SOURCES
GapBuffer.cpp
PieceTable.cpp
Buffer.cpp
@@ -55,7 +55,7 @@ set(SOURCES
TerminalFrontend.cpp
)
-set(HEADERS
+set(COMMON_HEADERS
GapBuffer.h
PieceTable.h
Buffer.h
@@ -70,10 +70,11 @@ set(HEADERS
TerminalFrontend.h
)
+# kte (terminal-first) executable
add_executable(kte
main.cpp
- ${SOURCES}
- ${HEADERS}
+ ${COMMON_SOURCES}
+ ${COMMON_HEADERS}
)
if (KTE_USE_PIECE_TABLE)
@@ -83,6 +84,7 @@ endif ()
target_link_libraries(kte ${CURSES_LIBRARIES})
if (${BUILD_GUI})
+ # Add GUI support to kte so it can be started with -g
target_sources(kte PRIVATE
GUIRenderer.cpp
GUIRenderer.h
@@ -92,4 +94,18 @@ if (${BUILD_GUI})
GUIFrontend.h)
target_compile_definitions(kte PRIVATE KTE_BUILD_GUI=1)
target_link_libraries(kte imgui)
+
+ # kge (GUI-first) executable
+ add_executable(kge
+ main.cpp
+ ${COMMON_SOURCES}
+ ${COMMON_HEADERS}
+ GUIRenderer.cpp
+ GUIRenderer.h
+ GUIInputHandler.cpp
+ GUIInputHandler.h
+ GUIFrontend.cpp
+ GUIFrontend.h)
+ target_compile_definitions(kge PRIVATE KTE_BUILD_GUI=1 KTE_DEFAULT_GUI=1)
+ target_link_libraries(kge ${CURSES_LIBRARIES} imgui)
endif ()
diff --git a/GUIRenderer.cpp b/GUIRenderer.cpp
index ab56a09..faae808 100644
--- a/GUIRenderer.cpp
+++ b/GUIRenderer.cpp
@@ -7,7 +7,25 @@
void GUIRenderer::Draw(const Editor &ed)
{
- ImGui::Begin("kte");
+ // Make the editor window occupy the entire GUI container/viewport
+ ImGuiViewport* vp = ImGui::GetMainViewport();
+ ImGui::SetNextWindowPos(vp->Pos);
+ ImGui::SetNextWindowSize(vp->Size);
+
+ ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar
+ | ImGuiWindowFlags_NoResize
+ | ImGuiWindowFlags_NoMove
+ | ImGuiWindowFlags_NoCollapse
+ | ImGuiWindowFlags_NoSavedSettings
+ | ImGuiWindowFlags_NoBringToFrontOnFocus
+ | ImGuiWindowFlags_NoNavFocus;
+
+ // Reduce padding so the buffer content uses the whole area
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(6.f, 6.f));
+
+ ImGui::Begin("kte", nullptr, flags);
const Buffer *buf = ed.CurrentBuffer();
if (!buf) {
@@ -34,4 +52,5 @@ void GUIRenderer::Draw(const Editor &ed)
}
ImGui::End();
+ ImGui::PopStyleVar(3);
}
diff --git a/README.md b/README.md
index 0e564fa..ea464a4 100644
--- a/README.md
+++ b/README.md
@@ -180,32 +180,6 @@ Run:
./cmake-build-debug/kte [files]
```
-CLI usage
----------
-
-```
-kte [OPTIONS] [files]
-
-Options:
- -g, --gui Use GUI frontend (if built)
- -t, --term Use terminal (ncurses) frontend [default]
- -h, --help Show help and exit
- -V, --version Show version and exit
-```
-
-Examples:
-
-```
-# Terminal (default)
-kte foo.txt bar.txt
-
-# Explicit terminal
-kte -t foo.txt
-
-# GUI (requires building with -DBUILD_GUI=ON and GUI deps installed)
-kte --gui foo.txt
-```
-
GUI build example
-----------------
diff --git a/main.cpp b/main.cpp
index 4789b5d..a64c2a8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -90,8 +90,12 @@ main(int argc, const char *argv[])
} else if (req_term) {
use_gui = false;
} else {
- // Default to terminal
- use_gui = false;
+ // Default depends on build target: kge defaults to GUI, kte to terminal
+ #if defined(KTE_DEFAULT_GUI)
+ use_gui = true;
+ #else
+ use_gui = false;
+ #endif
}
#endif