Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d1a45581bf | |||
| 81a5c25071 | |||
| 5667a6d7bd | |||
| 99c4bb2066 | |||
| 953fee97d7 | |||
| d7e35727f1 |
@@ -4,7 +4,7 @@ project(kte)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(KTE_VERSION "1.10.0")
|
||||
set(KTE_VERSION "1.11.1")
|
||||
|
||||
# Default to terminal-only build to avoid SDL/OpenGL dependency by default.
|
||||
# Enable with -DBUILD_GUI=ON when SDL2/OpenGL/Freetype are available.
|
||||
@@ -14,7 +14,7 @@ set(BUILD_TESTS ON CACHE BOOL "Enable building test programs.")
|
||||
set(KTE_FONT_SIZE "18.0" CACHE STRING "Default font size for GUI")
|
||||
option(KTE_UNDO_DEBUG "Enable undo instrumentation logs" OFF)
|
||||
option(KTE_ENABLE_TREESITTER "Enable optional Tree-sitter highlighter adapter" OFF)
|
||||
option(KTE_STATIC_LINK "Enable static linking on Linux" ON)
|
||||
option(KTE_STATIC_LINK "Enable static linking on Linux" OFF)
|
||||
|
||||
# Optionally enable AddressSanitizer (ASan)
|
||||
option(ENABLE_ASAN "Enable AddressSanitizer for builds" OFF)
|
||||
@@ -51,6 +51,7 @@ else ()
|
||||
)
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
add_compile_options("-stdlib=libc++")
|
||||
add_link_options("-stdlib=libc++")
|
||||
else ()
|
||||
# nothing special for gcc at the moment
|
||||
endif ()
|
||||
|
||||
29
GUIConfig.cc
29
GUIConfig.cc
@@ -99,16 +99,22 @@ GUIConfig::LoadFromTOML(const std::string &path)
|
||||
}
|
||||
|
||||
// [font]
|
||||
bool explicit_code_font = false;
|
||||
bool explicit_writing_font = false;
|
||||
if (auto sec = tbl["font"].as_table()) {
|
||||
if (auto v = (*sec)["name"].value<std::string>())
|
||||
font = *v;
|
||||
if (auto v = (*sec)["size"].value<double>()) {
|
||||
if (*v > 0.0) font_size = static_cast<float>(*v);
|
||||
}
|
||||
if (auto v = (*sec)["code"].value<std::string>())
|
||||
if (auto v = (*sec)["code"].value<std::string>()) {
|
||||
code_font = *v;
|
||||
if (auto v = (*sec)["writing"].value<std::string>())
|
||||
explicit_code_font = true;
|
||||
}
|
||||
if (auto v = (*sec)["writing"].value<std::string>()) {
|
||||
writing_font = *v;
|
||||
explicit_writing_font = true;
|
||||
}
|
||||
}
|
||||
|
||||
// [appearance]
|
||||
@@ -131,6 +137,12 @@ GUIConfig::LoadFromTOML(const std::string &path)
|
||||
syntax = *v;
|
||||
}
|
||||
|
||||
// Default code_font to the main font if not explicitly set
|
||||
if (!explicit_code_font)
|
||||
code_font = font;
|
||||
if (!explicit_writing_font && writing_font == "crimsonpro" && font != "default")
|
||||
writing_font = font;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -142,6 +154,9 @@ GUIConfig::LoadFromINI(const std::string &path)
|
||||
if (!in.good())
|
||||
return false;
|
||||
|
||||
bool explicit_code_font = false;
|
||||
bool explicit_writing_font = false;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(in, line)) {
|
||||
// Remove comments starting with '#' or ';'
|
||||
@@ -198,8 +213,10 @@ GUIConfig::LoadFromINI(const std::string &path)
|
||||
font = val;
|
||||
} else if (key == "code_font") {
|
||||
code_font = val;
|
||||
explicit_code_font = true;
|
||||
} else if (key == "writing_font") {
|
||||
writing_font = val;
|
||||
explicit_writing_font = true;
|
||||
} else if (key == "theme") {
|
||||
theme = val;
|
||||
} else if (key == "background" || key == "bg") {
|
||||
@@ -222,5 +239,13 @@ GUIConfig::LoadFromINI(const std::string &path)
|
||||
}
|
||||
}
|
||||
|
||||
// If code_font was not explicitly set, default it to the main font
|
||||
// so that the edit-mode font switcher doesn't immediately switch away
|
||||
// from the font loaded during Init.
|
||||
if (!explicit_code_font)
|
||||
code_font = font;
|
||||
if (!explicit_writing_font && writing_font == "crimsonpro" && font != "default")
|
||||
writing_font = font;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,9 @@ static void
|
||||
update_editor_dimensions(Editor &ed, float disp_w, float disp_h)
|
||||
{
|
||||
float row_h = ImGui::GetTextLineHeightWithSpacing();
|
||||
float ch_w = ImGui::CalcTextSize("M").x;
|
||||
// Use average character width rather than "M" (the widest character)
|
||||
// so that column count is reasonable for proportional fonts too.
|
||||
float ch_w = ImGui::CalcTextSize("abcdefghijklmnopqrstuvwxyz").x / 26.0f;
|
||||
if (row_h <= 0.0f)
|
||||
row_h = 16.0f;
|
||||
if (ch_w <= 0.0f)
|
||||
@@ -565,7 +567,7 @@ GUIFrontend::Step(Editor &ed, bool &running)
|
||||
running = false;
|
||||
}
|
||||
|
||||
// Switch font based on current buffer's edit mode
|
||||
// Switch font based on current buffer's edit mode (deferred to next frame)
|
||||
{
|
||||
Buffer *cur = wed.CurrentBuffer();
|
||||
if (cur) {
|
||||
@@ -577,9 +579,7 @@ GUIFrontend::Step(Editor &ed, bool &running)
|
||||
if (fr.CurrentFontName() != expected && fr.HasFont(expected)) {
|
||||
float sz = fr.CurrentFontSize();
|
||||
if (sz <= 0.0f) sz = config_.font_size;
|
||||
fr.LoadFont(expected, sz);
|
||||
ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
fr.RequestLoadFont(expected, sz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
100
ImGuiRenderer.cc
100
ImGuiRenderer.cc
@@ -85,11 +85,9 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
float target_y = static_cast<float>(buf_rowoffs) * row_h;
|
||||
ImGui::SetNextWindowScroll(ImVec2(-1.0f, target_y));
|
||||
}
|
||||
if (prev_buf_coloffs_ >= 0 && buf_coloffs != prev_buf_coloffs_) {
|
||||
float target_x = static_cast<float>(buf_coloffs) * space_w;
|
||||
float target_y = static_cast<float>(buf_rowoffs) * row_h;
|
||||
ImGui::SetNextWindowScroll(ImVec2(target_x, target_y));
|
||||
}
|
||||
// Horizontal scroll is handled purely in pixel space (see
|
||||
// cursor-visibility block after the line loop) so we don't
|
||||
// convert the character-based coloffs to an ImGui scroll here.
|
||||
|
||||
// Reserve space for status bar at bottom.
|
||||
// We calculate a height that is an exact multiple of the line height
|
||||
@@ -114,26 +112,21 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
bool forced_scroll = false;
|
||||
{
|
||||
const long scroll_top = static_cast<long>(scroll_y / row_h);
|
||||
const long scroll_left = static_cast<long>(scroll_x / space_w);
|
||||
|
||||
// Check if rowoffs was programmatically changed this frame
|
||||
if (prev_buf_rowoffs_ >= 0 && buf_rowoffs != prev_buf_rowoffs_) {
|
||||
forced_scroll = true;
|
||||
}
|
||||
|
||||
// If user scrolled (not programmatic), update buffer offsets accordingly
|
||||
// If user scrolled vertically (not programmatic), update buffer row offset
|
||||
if (prev_scroll_y_ >= 0.0f && scroll_y != prev_scroll_y_ && !forced_scroll) {
|
||||
if (Buffer *mbuf = const_cast<Buffer *>(buf)) {
|
||||
mbuf->SetOffsets(static_cast<std::size_t>(std::max(0L, scroll_top)),
|
||||
mbuf->Coloffs());
|
||||
}
|
||||
}
|
||||
if (prev_scroll_x_ >= 0.0f && scroll_x != prev_scroll_x_ && !forced_scroll) {
|
||||
if (Buffer *mbuf = const_cast<Buffer *>(buf)) {
|
||||
mbuf->SetOffsets(mbuf->Rowoffs(),
|
||||
static_cast<std::size_t>(std::max(0L, scroll_left)));
|
||||
}
|
||||
}
|
||||
// Horizontal scroll is pixel-based and managed by the cursor
|
||||
// visibility block below; we don't sync it back to coloffs.
|
||||
|
||||
// Update trackers for next frame
|
||||
prev_scroll_y_ = scroll_y;
|
||||
@@ -141,8 +134,8 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
}
|
||||
prev_buf_rowoffs_ = buf_rowoffs;
|
||||
prev_buf_coloffs_ = buf_coloffs;
|
||||
// Cache current horizontal offset in rendered columns for click handling
|
||||
const std::size_t coloffs_now = buf->Coloffs();
|
||||
// Track the widest line in pixels for ImGui content width
|
||||
float max_line_width_px = 0.0f;
|
||||
|
||||
// Mark selection state (mark -> cursor), in source coordinates
|
||||
bool sel_active = false;
|
||||
@@ -286,17 +279,14 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: convert a rendered column position to pixel x offset
|
||||
// relative to the visible line start, using actual text measurement
|
||||
// so proportional fonts render correctly.
|
||||
// Helper: convert a rendered column position to an absolute
|
||||
// pixel x offset from the start of the line. ImGui's scroll
|
||||
// handles viewport clipping so we measure from column 0.
|
||||
auto rx_to_px = [&](std::size_t rx_col) -> float {
|
||||
if (rx_col <= coloffs_now)
|
||||
std::size_t end = std::min(expanded.size(), rx_col);
|
||||
if (end == 0)
|
||||
return 0.0f;
|
||||
std::size_t start = coloffs_now;
|
||||
std::size_t end = std::min(expanded.size(), rx_col);
|
||||
if (start >= expanded.size() || end <= start)
|
||||
return 0.0f;
|
||||
return ImGui::CalcTextSize(expanded.c_str() + start,
|
||||
return ImGui::CalcTextSize(expanded.c_str(),
|
||||
expanded.c_str() + end).x;
|
||||
};
|
||||
|
||||
@@ -351,9 +341,6 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
std::size_t sx = rg.first, ex = rg.second;
|
||||
std::size_t rx_start = src_to_rx(sx);
|
||||
std::size_t rx_end = src_to_rx(ex);
|
||||
// Apply horizontal scroll offset
|
||||
if (rx_end <= coloffs_now)
|
||||
continue; // fully left of view
|
||||
ImVec2 p0 = ImVec2(line_pos.x + rx_to_px(rx_start), line_pos.y);
|
||||
ImVec2 p1 = ImVec2(line_pos.x + rx_to_px(rx_end),
|
||||
line_pos.y + line_h);
|
||||
@@ -392,14 +379,12 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
if (line_has) {
|
||||
std::size_t rx_start = src_to_rx(sx);
|
||||
std::size_t rx_end = src_to_rx(ex);
|
||||
if (rx_end > coloffs_now) {
|
||||
ImVec2 p0 = ImVec2(line_pos.x + rx_to_px(rx_start),
|
||||
line_pos.y);
|
||||
ImVec2 p1 = ImVec2(line_pos.x + rx_to_px(rx_end),
|
||||
line_pos.y + line_h);
|
||||
ImU32 col = ImGui::GetColorU32(ImGuiCol_TextSelectedBg);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(p0, p1, col);
|
||||
}
|
||||
ImVec2 p0 = ImVec2(line_pos.x + rx_to_px(rx_start),
|
||||
line_pos.y);
|
||||
ImVec2 p1 = ImVec2(line_pos.x + rx_to_px(rx_end),
|
||||
line_pos.y + line_h);
|
||||
ImU32 col = ImGui::GetColorU32(ImGuiCol_TextSelectedBg);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(p0, p1, col);
|
||||
}
|
||||
}
|
||||
if (vsel_active && i >= vsel_sy && i <= vsel_ey) {
|
||||
@@ -413,14 +398,12 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
// EOL spot: draw a 1-cell highlight just past the last character.
|
||||
rx_end = rx_start + 1;
|
||||
}
|
||||
if (rx_end > coloffs_now) {
|
||||
ImVec2 p0 = ImVec2(line_pos.x + rx_to_px(rx_start),
|
||||
line_pos.y);
|
||||
ImVec2 p1 = ImVec2(line_pos.x + rx_to_px(rx_end),
|
||||
line_pos.y + line_h);
|
||||
ImU32 col = ImGui::GetColorU32(ImGuiCol_TextSelectedBg);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(p0, p1, col);
|
||||
}
|
||||
ImVec2 p0 = ImVec2(line_pos.x + rx_to_px(rx_start),
|
||||
line_pos.y);
|
||||
ImVec2 p1 = ImVec2(line_pos.x + rx_to_px(rx_end),
|
||||
line_pos.y + line_h);
|
||||
ImU32 col = ImGui::GetColorU32(ImGuiCol_TextSelectedBg);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(p0, p1, col);
|
||||
}
|
||||
// Draw syntax-colored runs (text above background highlights)
|
||||
if (buf->SyntaxEnabled() && buf->Highlighter() && buf->Highlighter()->HasHighlighter()) {
|
||||
@@ -464,16 +447,12 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
for (const auto &sp: spans) {
|
||||
std::size_t rx_s = src_to_rx_full(sp.s);
|
||||
std::size_t rx_e = src_to_rx_full(sp.e);
|
||||
if (rx_e <= coloffs_now)
|
||||
continue; // fully left of viewport
|
||||
// Clamp to visible portion and expanded length
|
||||
std::size_t draw_start = (rx_s > coloffs_now) ? rx_s : coloffs_now;
|
||||
std::size_t draw_start = rx_s;
|
||||
if (draw_start >= expanded.size())
|
||||
continue; // fully right of expanded text
|
||||
continue;
|
||||
std::size_t draw_end = std::min<std::size_t>(rx_e, expanded.size());
|
||||
if (draw_end <= draw_start)
|
||||
continue;
|
||||
// Screen position via actual text measurement
|
||||
ImU32 col = ImGui::GetColorU32(kte::SyntaxInk(sp.k));
|
||||
ImVec2 p = ImVec2(line_pos.x + rx_to_px(draw_start),
|
||||
line_pos.y);
|
||||
@@ -484,17 +463,14 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
// Use row_h (with spacing) to match click calculation and ensure consistent line positions.
|
||||
ImGui::SetCursorScreenPos(ImVec2(line_pos.x, line_pos.y + row_h));
|
||||
} else {
|
||||
// No syntax: draw as one run, accounting for horizontal scroll offset
|
||||
if (coloffs_now < expanded.size()) {
|
||||
// No syntax: draw the full line; ImGui scroll handles clipping.
|
||||
if (!expanded.empty()) {
|
||||
ImVec2 p = ImVec2(line_pos.x, line_pos.y);
|
||||
ImGui::GetWindowDrawList()->AddText(
|
||||
p, ImGui::GetColorU32(ImGuiCol_Text),
|
||||
expanded.c_str() + coloffs_now);
|
||||
ImGui::SetCursorScreenPos(ImVec2(line_pos.x, line_pos.y + row_h));
|
||||
} else {
|
||||
// Line is fully scrolled out of view horizontally
|
||||
ImGui::SetCursorScreenPos(ImVec2(line_pos.x, line_pos.y + row_h));
|
||||
expanded.c_str());
|
||||
}
|
||||
ImGui::SetCursorScreenPos(ImVec2(line_pos.x, line_pos.y + row_h));
|
||||
}
|
||||
|
||||
// Draw a visible cursor indicator on the current line
|
||||
@@ -506,6 +482,18 @@ ImGuiRenderer::Draw(Editor &ed)
|
||||
ImU32 col = IM_COL32(200, 200, 255, 128); // soft highlight
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(p0, p1, col);
|
||||
}
|
||||
|
||||
// Track widest line for content width reporting
|
||||
if (!expanded.empty()) {
|
||||
float line_w = ImGui::CalcTextSize(expanded.c_str()).x;
|
||||
if (line_w > max_line_width_px)
|
||||
max_line_width_px = line_w;
|
||||
}
|
||||
}
|
||||
// Report content width to ImGui so horizontal scrollbar works correctly.
|
||||
if (max_line_width_px > 0.0f) {
|
||||
ImGui::SetCursorPosX(max_line_width_px);
|
||||
ImGui::Dummy(ImVec2(0, 0));
|
||||
}
|
||||
// Synchronize cursor and scrolling after rendering all lines so content size is known.
|
||||
{
|
||||
|
||||
59
default.nix
59
default.nix
@@ -1,6 +1,5 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
lib ? pkgs.lib,
|
||||
lib,
|
||||
stdenv,
|
||||
cmake,
|
||||
ncurses,
|
||||
@@ -10,9 +9,10 @@
|
||||
kdePackages,
|
||||
qt6Packages ? kdePackages.qt6Packages,
|
||||
installShellFiles,
|
||||
copyDesktopItems,
|
||||
makeDesktopItem,
|
||||
graphical ? false,
|
||||
graphical-qt ? false,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cmakeContent = builtins.readFile ./CMakeLists.txt;
|
||||
@@ -23,25 +23,29 @@ let
|
||||
version = builtins.head (builtins.match ".*set\\(KTE_VERSION \"(.+)\"\\).*" versionLine);
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "kte";
|
||||
pname = if graphical then (if graphical-qt then "kge-qt" else "kge") else "kte";
|
||||
inherit version;
|
||||
|
||||
src = lib.cleanSource ./.;
|
||||
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
ncurses
|
||||
installShellFiles
|
||||
]
|
||||
++ lib.optionals graphical [
|
||||
] ++ lib.optionals graphical [
|
||||
copyDesktopItems
|
||||
] ++ lib.optionals graphical-qt [
|
||||
qt6Packages.wrapQtAppsHook
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
ncurses
|
||||
] ++ lib.optionals graphical [
|
||||
SDL2
|
||||
libGL
|
||||
xorg.libX11
|
||||
]
|
||||
++ lib.optionals graphical-qt [
|
||||
] ++ lib.optionals graphical-qt [
|
||||
kdePackages.qt6ct
|
||||
qt6Packages.qtbase
|
||||
qt6Packages.wrapQtAppsHook
|
||||
];
|
||||
|
||||
cmakeFlags = [
|
||||
@@ -51,6 +55,30 @@ stdenv.mkDerivation {
|
||||
"-DKTE_STATIC_LINK=OFF"
|
||||
];
|
||||
|
||||
desktopItems = lib.optionals graphical [
|
||||
(makeDesktopItem {
|
||||
name = "kge";
|
||||
desktopName = "kge";
|
||||
genericName = "Text Editor";
|
||||
comment = "kyle's graphical text editor";
|
||||
exec = if graphical-qt then "kge-qt %F" else "kge %F";
|
||||
icon = "kge";
|
||||
terminal = false;
|
||||
categories = [ "Utility" "TextEditor" "Development" ];
|
||||
mimeTypes = [
|
||||
"text/plain"
|
||||
"text/x-c"
|
||||
"text/x-c++"
|
||||
"text/x-python"
|
||||
"text/x-go"
|
||||
"text/x-rust"
|
||||
"application/json"
|
||||
"text/markdown"
|
||||
"text/x-shellscript"
|
||||
];
|
||||
})
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
@@ -59,14 +87,11 @@ stdenv.mkDerivation {
|
||||
installManPage ../docs/kte.1
|
||||
|
||||
${lib.optionalString graphical ''
|
||||
mkdir -p $out/bin
|
||||
|
||||
${if graphical-qt then ''
|
||||
${if graphical-qt then ''
|
||||
cp kge $out/bin/kge-qt
|
||||
'' else ''
|
||||
cp kge $out/bin/kge
|
||||
''}
|
||||
|
||||
installManPage ../docs/kge.1
|
||||
|
||||
mkdir -p $out/share/icons/hicolor/256x256/apps
|
||||
@@ -75,4 +100,10 @@ stdenv.mkDerivation {
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "kyle's text editor" + lib.optionalString graphical " (graphical)";
|
||||
platforms = lib.platforms.unix;
|
||||
mainProgram = if graphical then (if graphical-qt then "kge-qt" else "kge") else "kte";
|
||||
};
|
||||
}
|
||||
|
||||
25
flake.nix
25
flake.nix
@@ -3,8 +3,7 @@
|
||||
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
|
||||
outputs =
|
||||
inputs@{ self, nixpkgs, ... }:
|
||||
outputs = { self, nixpkgs, ... }:
|
||||
let
|
||||
eachSystem = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
|
||||
pkgsFor = system: import nixpkgs { inherit system; };
|
||||
@@ -17,5 +16,27 @@
|
||||
kge = (pkgsFor system).callPackage ./default.nix { graphical = true; graphical-qt = false; };
|
||||
qt = (pkgsFor system).callPackage ./default.nix { graphical = true; graphical-qt = true; };
|
||||
});
|
||||
|
||||
devShells = eachSystem (system:
|
||||
let pkgs = pkgsFor system;
|
||||
in {
|
||||
default = pkgs.mkShell {
|
||||
inputsFrom = [ self.packages.${system}.kge ];
|
||||
packages = with pkgs; [ gdb valgrind ];
|
||||
};
|
||||
terminal = pkgs.mkShell {
|
||||
inputsFrom = [ self.packages.${system}.kte ];
|
||||
};
|
||||
qt = pkgs.mkShell {
|
||||
inputsFrom = [ self.packages.${system}.qt ];
|
||||
packages = with pkgs; [ gdb valgrind ];
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
overlays.default = final: prev: {
|
||||
kte = self.packages.${final.system}.kte;
|
||||
kge = self.packages.${final.system}.kge;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user