update nix build
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled
This commit is contained in:
55
.idea/workspace.xml
generated
55
.idea/workspace.xml
generated
@@ -11,9 +11,9 @@
|
|||||||
<option name="/Default/Housekeeping/RefactoringsMru/RenameRefactoring/DoSearchForTextInStrings/@EntryValue" value="true" type="bool" />
|
<option name="/Default/Housekeeping/RefactoringsMru/RenameRefactoring/DoSearchForTextInStrings/@EntryValue" value="true" type="bool" />
|
||||||
<option name="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue" value="false" type="bool" />
|
<option name="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue" value="false" type="bool" />
|
||||||
</component>
|
</component>
|
||||||
<component name="CMakePresetLoader"><![CDATA[{
|
<component name="CMakePresetLoader">{
|
||||||
"useNewFormat": true
|
"useNewFormat": true
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="CMakeProjectFlavorService">
|
<component name="CMakeProjectFlavorService">
|
||||||
<option name="flavorId" value="CMakePlainProjectFlavor" />
|
<option name="flavorId" value="CMakePlainProjectFlavor" />
|
||||||
</component>
|
</component>
|
||||||
@@ -21,11 +21,7 @@
|
|||||||
<option name="reloaded" value="true" />
|
<option name="reloaded" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="CMakeRunConfigurationManager">
|
<component name="CMakeRunConfigurationManager">
|
||||||
<generated>
|
<generated />
|
||||||
<config projectName="kte" targetName="kte" />
|
|
||||||
<config projectName="kte" targetName="imgui" />
|
|
||||||
<config projectName="kte" targetName="kge" />
|
|
||||||
</generated>
|
|
||||||
</component>
|
</component>
|
||||||
<component name="CMakeSettings" AUTO_RELOAD="true">
|
<component name="CMakeSettings" AUTO_RELOAD="true">
|
||||||
<configurations>
|
<configurations>
|
||||||
@@ -34,8 +30,13 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e1fe3ab0-3650-4fca-8664-a247d5dfa457" name="Changes" comment="Add GUI initialization updates and improve navigation commands. - Implement terminal detachment for GUI mode to enable terminal closure post-launch. - Add `+N` support for opening files at specific line numbers and refine cursor positioning. - Introduce `JumpToLine` command for direct navigation by line number. - Enhance mouse wheel handling for line-wise scrolling.">
|
<list default="true" id="e1fe3ab0-3650-4fca-8664-a247d5dfa457" name="Changes" comment="Add GUI initialization updates and improve navigation commands. - Implement terminal detachment for GUI mode to enable terminal closure post-launch. - Add `+N` support for opening files at specific line numbers and refine cursor positioning. - Introduce `JumpToLine` command for direct navigation by line number. - Enhance mouse wheel handling for line-wise scrolling.">
|
||||||
|
<change afterPath="$PROJECT_DIR$/default-nogui.nix" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/default-gui.nix" beforeDir="false" afterPath="$PROJECT_DIR$/default-gui.nix" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/default.nix" beforeDir="false" afterPath="$PROJECT_DIR$/default.nix" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/flake.nix" beforeDir="false" afterPath="$PROJECT_DIR$/flake.nix" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/main.cc" beforeDir="false" afterPath="$PROJECT_DIR$/main.cc" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -75,9 +76,9 @@
|
|||||||
<option name="minorVersion" value="2.5" />
|
<option name="minorVersion" value="2.5" />
|
||||||
<option name="productBranch" value="Classic" />
|
<option name="productBranch" value="Classic" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectColorInfo"><![CDATA[{
|
<component name="ProjectColorInfo">{
|
||||||
"associatedIndex": 3
|
"associatedIndex": 3
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="ProjectId" id="36AlI8oyQOzOwSuZg6WxXf5LbHb" />
|
<component name="ProjectId" id="36AlI8oyQOzOwSuZg6WxXf5LbHb" />
|
||||||
<component name="ProjectLevelVcsManager">
|
<component name="ProjectLevelVcsManager">
|
||||||
<OptionsSetting value="false" id="Update" />
|
<OptionsSetting value="false" id="Update" />
|
||||||
@@ -104,6 +105,7 @@
|
|||||||
"RunOnceActivity.RadMigrateCodeStyle": "true",
|
"RunOnceActivity.RadMigrateCodeStyle": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.cidr.known.project.marker": "true",
|
"RunOnceActivity.cidr.known.project.marker": "true",
|
||||||
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"RunOnceActivity.readMode.enableVisualFormatting": "true",
|
"RunOnceActivity.readMode.enableVisualFormatting": "true",
|
||||||
"RunOnceActivity.west.config.association.type.startup.service": "true",
|
"RunOnceActivity.west.config.association.type.startup.service": "true",
|
||||||
"cf.first.check.clang-format": "false",
|
"cf.first.check.clang-format": "false",
|
||||||
@@ -119,7 +121,7 @@
|
|||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"onboarding.tips.debug.path": "/Users/kyle/src/kte/main.cpp",
|
"onboarding.tips.debug.path": "/Users/kyle/src/kte/main.cpp",
|
||||||
"rearrange.code.on.save": "true",
|
"rearrange.code.on.save": "true",
|
||||||
"settings.editor.selected.configurable": "junie.application.models",
|
"settings.editor.selected.configurable": "editor.preferences.fonts.default",
|
||||||
"to.speed.mode.migration.done": "true",
|
"to.speed.mode.migration.done": "true",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
@@ -129,32 +131,12 @@
|
|||||||
<recent name="$PROJECT_DIR$/docs" />
|
<recent name="$PROJECT_DIR$/docs" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="CMake Application.kge">
|
<component name="RunManager">
|
||||||
<configuration default="true" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true">
|
<configuration default="true" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true">
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="imgui" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="kte" TARGET_NAME="imgui" CONFIG_NAME="Debug">
|
|
||||||
<method v="2">
|
|
||||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<configuration name="kge" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="kte" TARGET_NAME="kge" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="kte" RUN_TARGET_NAME="kge">
|
|
||||||
<method v="2">
|
|
||||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<configuration name="kte" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="kte" TARGET_NAME="kte" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="kte" RUN_TARGET_NAME="kte">
|
|
||||||
<method v="2">
|
|
||||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<list>
|
|
||||||
<item itemvalue="CMake Application.imgui" />
|
|
||||||
<item itemvalue="CMake Application.kge" />
|
|
||||||
<item itemvalue="CMake Application.kte" />
|
|
||||||
</list>
|
|
||||||
</component>
|
</component>
|
||||||
<component name="TaskManager">
|
<component name="TaskManager">
|
||||||
<task active="true" id="Default" summary="Default task">
|
<task active="true" id="Default" summary="Default task">
|
||||||
@@ -164,6 +146,13 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1764457173148</updated>
|
<updated>1764457173148</updated>
|
||||||
<workItem from="1764457174208" duration="46950000" />
|
<workItem from="1764457174208" duration="46950000" />
|
||||||
|
<workItem from="1764538560497" duration="215000" />
|
||||||
|
<workItem from="1764539255906" duration="196000" />
|
||||||
|
<workItem from="1764539459951" duration="64000" />
|
||||||
|
<workItem from="1764539535105" duration="10000" />
|
||||||
|
<workItem from="1764539556448" duration="156000" />
|
||||||
|
<workItem from="1764539725338" duration="1075000" />
|
||||||
|
<workItem from="1764542392763" duration="3512000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Add undo/redo infrastructure and buffer management additions.">
|
<task id="LOCAL-00001" summary="Add undo/redo infrastructure and buffer management additions.">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ project(kte)
|
|||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(KTE_VERSION "0.9.0")
|
set(KTE_VERSION "0.9.1")
|
||||||
|
|
||||||
# Default to terminal-only build to avoid SDL/OpenGL dependency by default.
|
# Default to terminal-only build to avoid SDL/OpenGL dependency by default.
|
||||||
# Enable with -DBUILD_GUI=ON when SDL2/OpenGL/Freetype are available.
|
# Enable with -DBUILD_GUI=ON when SDL2/OpenGL/Freetype are available.
|
||||||
@@ -44,6 +44,8 @@ if (${BUILD_GUI})
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# NCurses for terminal mode
|
# NCurses for terminal mode
|
||||||
|
set(CURSES_NEED_NCURSES)
|
||||||
|
set(CURSES_NEED_WIDE)
|
||||||
find_package(Curses REQUIRED)
|
find_package(Curses REQUIRED)
|
||||||
include_directories(${CURSES_INCLUDE_DIR})
|
include_directories(${CURSES_INCLUDE_DIR})
|
||||||
|
|
||||||
|
|||||||
@@ -137,9 +137,6 @@ KLookupCtrlCommand(const int ascii_key, CommandId &out) -> bool
|
|||||||
case 'g':
|
case 'g':
|
||||||
out = CommandId::Refresh;
|
out = CommandId::Refresh;
|
||||||
return true;
|
return true;
|
||||||
case 'x':
|
|
||||||
out = CommandId::SaveAndQuit; // direct C-x mapping (GUI had this)
|
|
||||||
return true;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,36 +2,37 @@
|
|||||||
lib,
|
lib,
|
||||||
stdenv,
|
stdenv,
|
||||||
cmake,
|
cmake,
|
||||||
libGL,
|
ncurses,
|
||||||
SDL2,
|
SDL2,
|
||||||
xorg.libX11
|
libGL,
|
||||||
|
xorg,
|
||||||
installShellFiles,
|
installShellFiles,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cmakeContent = builtins.readFile ./CMakeLists.txt;
|
cmakeContent = builtins.readFile ./CMakeLists.txt;
|
||||||
cmakeLines = lib.splitString "\n" cmakeContent;
|
cmakeLines = lib.splitString "\n" cmakeContent;
|
||||||
versionLine = lib.findFirst (l: builtins.match ".*set\\(KE_VERSION \".+\"\\).*" l
|
versionLine = lib.findFirst (l: builtins.match ".*set\\(KTE_VERSION \".+\"\\).*" l != null) (throw "KTE_VERSION not found in CMakeLists.txt") cmakeLines;
|
||||||
version = builtins.head (builtins.match ".*set\\(KE_VERSION \"(.+)\"\\).*" versio
|
version = builtins.head (builtins.match ".*set\\(KTE_VERSION \"(.+)\"\\).*" versionLine);
|
||||||
in
|
in
|
||||||
pkgs.stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
pname = "kte";
|
pname = "kte";
|
||||||
inherit version;
|
inherit version;
|
||||||
|
|
||||||
src = ./.;
|
src = lib.cleanSource ./.;
|
||||||
|
|
||||||
nativeBuildInputs = [ pkgs.cmake pkgs.pkg-config ];
|
nativeBuildInputs = [
|
||||||
buildInputs = with pkgs; [
|
cmake
|
||||||
ncurses
|
ncurses
|
||||||
SDL2
|
SDL2
|
||||||
libGL
|
libGL
|
||||||
xorg.libX11
|
xorg.libX11
|
||||||
|
installShellFiles
|
||||||
];
|
];
|
||||||
|
|
||||||
cmakeFlags = [
|
cmakeFlags = [
|
||||||
"-DBUILD_GUI=ON"
|
"-DBUILD_GUI=ON"
|
||||||
"-DCURSES_NEED_NCURSES=TRUE"
|
"-DCMAKE_BUILD_TYPE=Debug"
|
||||||
"-DCURSES_NEED_WIDE=TRUE"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
@@ -42,7 +43,8 @@ pkgs.stdenv.mkDerivation {
|
|||||||
cp kge $out/bin/
|
cp kge $out/bin/
|
||||||
|
|
||||||
installManPage ../docs/kte.1
|
installManPage ../docs/kte.1
|
||||||
installManPage ../docs/kte.1
|
installManPage ../docs/kge.1
|
||||||
|
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|||||||
42
default-nogui.nix
Normal file
42
default-nogui.nix
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
stdenv,
|
||||||
|
cmake,
|
||||||
|
ncurses,
|
||||||
|
installShellFiles,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cmakeContent = builtins.readFile ./CMakeLists.txt;
|
||||||
|
cmakeLines = lib.splitString "\n" cmakeContent;
|
||||||
|
versionLine = lib.findFirst (l: builtins.match ".*set\\(KTE_VERSION \".+\"\\).*" l != null) (throw "KTE_VERSION not found in CMakeLists.txt") cmakeLines;
|
||||||
|
version = builtins.head (builtins.match ".*set\\(KTE_VERSION \"(.+)\"\\).*" versionLine);
|
||||||
|
in
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
pname = "kte";
|
||||||
|
inherit version;
|
||||||
|
|
||||||
|
src = lib.cleanSource ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
cmake
|
||||||
|
ncurses
|
||||||
|
installShellFiles
|
||||||
|
];
|
||||||
|
|
||||||
|
cmakeFlags = [
|
||||||
|
"-DBUILD_GUI=OFF"
|
||||||
|
"-DCMAKE_BUILD_TYPE=Debug"
|
||||||
|
];
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
|
mkdir -p $out/bin
|
||||||
|
cp kte $out/bin/
|
||||||
|
|
||||||
|
installManPage ../docs/kte.1
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
}
|
||||||
12
default.nix
12
default.nix
@@ -3,6 +3,9 @@
|
|||||||
stdenv,
|
stdenv,
|
||||||
cmake,
|
cmake,
|
||||||
ncurses,
|
ncurses,
|
||||||
|
SDL2,
|
||||||
|
libGL,
|
||||||
|
xorg,
|
||||||
installShellFiles,
|
installShellFiles,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
@@ -13,7 +16,7 @@ let
|
|||||||
version = builtins.head (builtins.match ".*set\\(KTE_VERSION \"(.+)\"\\).*" versionLine);
|
version = builtins.head (builtins.match ".*set\\(KTE_VERSION \"(.+)\"\\).*" versionLine);
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
pname = "ke";
|
pname = "kte";
|
||||||
inherit version;
|
inherit version;
|
||||||
|
|
||||||
src = lib.cleanSource ./.;
|
src = lib.cleanSource ./.;
|
||||||
@@ -21,11 +24,14 @@ stdenv.mkDerivation {
|
|||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
cmake
|
cmake
|
||||||
ncurses
|
ncurses
|
||||||
|
SDL2
|
||||||
|
libGL
|
||||||
|
xorg.libX11
|
||||||
installShellFiles
|
installShellFiles
|
||||||
];
|
];
|
||||||
|
|
||||||
cmakeFlags = [
|
cmakeFlags = [
|
||||||
"-DKTE_USE_PIECE_TABLE=ON"
|
"-DBUILD_GUI=ON"
|
||||||
"-DCMAKE_BUILD_TYPE=Debug"
|
"-DCMAKE_BUILD_TYPE=Debug"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -34,8 +40,10 @@ stdenv.mkDerivation {
|
|||||||
|
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
cp kte $out/bin/
|
cp kte $out/bin/
|
||||||
|
cp kge $out/bin/
|
||||||
|
|
||||||
installManPage ../docs/kte.1
|
installManPage ../docs/kte.1
|
||||||
|
installManPage ../docs/kge.1
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -12,7 +12,10 @@
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages.x86_64-linux = {
|
packages.x86_64-linux = {
|
||||||
default = pkgs.callPackage ./default.nix { };
|
default = pkgs.callPackage ./default-nogui.nix { };
|
||||||
|
kge = pkgs.callPackage ./default-gui.nix { };
|
||||||
|
kte = pkgs.callPackage ./default-nogui.nix { };
|
||||||
|
full = pkgs.callPackage ./default.nix { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
175
main.cc
175
main.cc
@@ -12,6 +12,7 @@
|
|||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "Frontend.h"
|
#include "Frontend.h"
|
||||||
#include "TerminalFrontend.h"
|
#include "TerminalFrontend.h"
|
||||||
|
|
||||||
#if defined(KTE_BUILD_GUI)
|
#if defined(KTE_BUILD_GUI)
|
||||||
#include "GUIFrontend.h"
|
#include "GUIFrontend.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -25,156 +26,52 @@ static void
|
|||||||
PrintUsage(const char *prog)
|
PrintUsage(const char *prog)
|
||||||
{
|
{
|
||||||
std::cerr << "Usage: " << prog << " [OPTIONS] [files]\n"
|
std::cerr << "Usage: " << prog << " [OPTIONS] [files]\n"
|
||||||
<< "Options:\n"
|
<< "Options:\n"
|
||||||
<< " -g, --gui Use GUI frontend (if built)\n"
|
<< " -g, --gui Use GUI frontend (if built)\n"
|
||||||
<< " -t, --term Use terminal (ncurses) frontend [default]\n"
|
<< " -t, --term Use terminal (ncurses) frontend [default]\n"
|
||||||
<< " -h, --help Show this help and exit\n"
|
<< " -h, --help Show this help and exit\n"
|
||||||
<< " -V, --version Show version and exit\n";
|
<< " -V, --version Show version and exit\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(KTE_BUILD_GUI)
|
|
||||||
// Detach the process from the controlling terminal when running the GUI so the
|
|
||||||
// launching terminal can be closed. This mirrors typical GUI app behavior on
|
|
||||||
// POSIX systems.
|
|
||||||
static void
|
|
||||||
DetachFromTerminalIfGUI(bool use_gui)
|
|
||||||
{
|
|
||||||
#if defined(__APPLE__) || defined(__linux__) || defined(__unix__)
|
|
||||||
if (!use_gui)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Ignore SIGHUP so closing the terminal won't terminate us.
|
|
||||||
signal(SIGHUP, SIG_IGN);
|
|
||||||
|
|
||||||
// Helper: redirect stdio to /dev/null and optionally close extra FDs.
|
|
||||||
auto redirect_stdio_and_close = []() {
|
|
||||||
// Reset file mode creation mask and working directory to a safe default
|
|
||||||
umask(0);
|
|
||||||
chdir("/");
|
|
||||||
|
|
||||||
FILE *fnull_r = fopen("/dev/null", "r");
|
|
||||||
if (fnull_r) {
|
|
||||||
dup2(fileno(fnull_r), STDIN_FILENO);
|
|
||||||
}
|
|
||||||
FILE *fnull_w = fopen("/dev/null", "w");
|
|
||||||
if (fnull_w) {
|
|
||||||
dup2(fileno(fnull_w), STDOUT_FILENO);
|
|
||||||
dup2(fileno(fnull_w), STDERR_FILENO);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close any other inherited FDs to avoid keeping terminal/pty or pipes open
|
|
||||||
long max_fd = sysconf(_SC_OPEN_MAX);
|
|
||||||
if (max_fd < 0)
|
|
||||||
max_fd = 256; // conservative fallback
|
|
||||||
for (long fd = 3; fd < max_fd; ++fd) {
|
|
||||||
close(static_cast<int>(fd));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
// macOS: daemon(3) is deprecated and treated as an error with -Werror.
|
|
||||||
// Use double-fork + setsid and redirect stdio to /dev/null.
|
|
||||||
pid_t pid = fork();
|
|
||||||
if (pid < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid > 0) {
|
|
||||||
_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setsid() < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_t pid2 = fork();
|
|
||||||
if (pid2 < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid2 > 0) {
|
|
||||||
_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect_stdio_and_close();
|
|
||||||
#else
|
|
||||||
// Prefer daemon(3) on non-Apple POSIX; fall back to manual detach if it fails.
|
|
||||||
if (daemon(0, 0) == 0) {
|
|
||||||
redirect_stdio_and_close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_t pid = fork();
|
|
||||||
if (pid < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid > 0) {
|
|
||||||
_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setsid() < 0) {
|
|
||||||
// bogus check
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_t pid2 = fork();
|
|
||||||
if (pid2 < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid2 > 0) {
|
|
||||||
_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect_stdio_and_close();
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
(void) use_gui;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
Editor editor;
|
Editor editor;
|
||||||
|
|
||||||
// CLI parsing using getopt_long
|
// CLI parsing using getopt_long
|
||||||
bool req_gui = false;
|
bool req_gui = false;
|
||||||
bool req_term = false;
|
bool req_term = false;
|
||||||
bool show_help = false;
|
bool show_help = false;
|
||||||
bool show_version = false;
|
bool show_version = false;
|
||||||
|
|
||||||
static struct option long_opts[] = {
|
static struct option long_opts[] = {
|
||||||
{"gui", no_argument, nullptr, 'g'},
|
{"gui", no_argument, nullptr, 'g'},
|
||||||
{"term", no_argument, nullptr, 't'},
|
{"term", no_argument, nullptr, 't'},
|
||||||
{"help", no_argument, nullptr, 'h'},
|
{"help", no_argument, nullptr, 'h'},
|
||||||
{"version", no_argument, nullptr, 'V'},
|
{"version", no_argument, nullptr, 'V'},
|
||||||
{nullptr, 0, nullptr, 0}
|
{nullptr, 0, nullptr, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
int long_index = 0;
|
int long_index = 0;
|
||||||
while ((opt = getopt_long(argc, const_cast<char * const*>(argv), "gthV", long_opts, &long_index)) != -1) {
|
while ((opt = getopt_long(argc, const_cast<char *const *>(argv), "gthV", long_opts, &long_index)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'g':
|
case 'g':
|
||||||
req_gui = true;
|
req_gui = true;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
req_term = true;
|
req_term = true;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
show_help = true;
|
show_help = true;
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
show_version = true;
|
show_version = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
PrintUsage(argv[0]);
|
PrintUsage(argv[0]);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +92,7 @@ main(int argc, const char *argv[])
|
|||||||
#if !defined(KTE_BUILD_GUI)
|
#if !defined(KTE_BUILD_GUI)
|
||||||
if (req_gui) {
|
if (req_gui) {
|
||||||
std::cerr << "kte: GUI not built. Reconfigure with -DBUILD_GUI=ON and required deps installed." <<
|
std::cerr << "kte: GUI not built. Reconfigure with -DBUILD_GUI=ON and required deps installed." <<
|
||||||
std::endl;
|
std::endl;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -212,8 +109,6 @@ main(int argc, const char *argv[])
|
|||||||
use_gui = false;
|
use_gui = false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// If using GUI, detach from the controlling terminal so the terminal can be closed.
|
|
||||||
DetachFromTerminalIfGUI(use_gui);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Open files passed on the CLI; support +N to jump to line N in the next file.
|
// Open files passed on the CLI; support +N to jump to line N in the next file.
|
||||||
@@ -237,7 +132,7 @@ main(int argc, const char *argv[])
|
|||||||
// Clamp to >=1 later; 0 disables.
|
// Clamp to >=1 later; 0 disables.
|
||||||
try {
|
try {
|
||||||
unsigned long v = std::stoul(p);
|
unsigned long v = std::stoul(p);
|
||||||
pending_line = static_cast<std::size_t>(v);
|
pending_line = static_cast<std::size_t>(v);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// Ignore malformed huge numbers
|
// Ignore malformed huge numbers
|
||||||
pending_line = 0;
|
pending_line = 0;
|
||||||
@@ -257,7 +152,7 @@ main(int argc, const char *argv[])
|
|||||||
// Apply pending +N to the just-opened (current) buffer
|
// Apply pending +N to the just-opened (current) buffer
|
||||||
if (Buffer *b = editor.CurrentBuffer()) {
|
if (Buffer *b = editor.CurrentBuffer()) {
|
||||||
std::size_t nrows = b->Nrows();
|
std::size_t nrows = b->Nrows();
|
||||||
std::size_t line = pending_line > 0 ? pending_line - 1 : 0;
|
std::size_t line = pending_line > 0 ? pending_line - 1 : 0;
|
||||||
// 1-based to 0-based
|
// 1-based to 0-based
|
||||||
if (nrows > 0) {
|
if (nrows > 0) {
|
||||||
if (line >= nrows)
|
if (line >= nrows)
|
||||||
@@ -283,7 +178,7 @@ main(int argc, const char *argv[])
|
|||||||
InstallDefaultCommands();
|
InstallDefaultCommands();
|
||||||
|
|
||||||
// Select frontend
|
// Select frontend
|
||||||
std::unique_ptr<Frontend> fe;
|
std::unique_ptr <Frontend> fe;
|
||||||
#if defined(KTE_BUILD_GUI)
|
#if defined(KTE_BUILD_GUI)
|
||||||
if (use_gui) {
|
if (use_gui) {
|
||||||
fe = std::make_unique<GUIFrontend>();
|
fe = std::make_unique<GUIFrontend>();
|
||||||
|
|||||||
Reference in New Issue
Block a user