Mercurial > dnft
changeset 0:4171b2d4684b default tip
initial commit
| author | Yasuri <linuxoverwindows@charliesmp.net> |
|---|---|
| date | Sat, 05 Sep 2026 15:35:48 -0500 |
| parents | |
| children | |
| files | .hgignore LICENSE README pipes.cpp spawn.cpp |
| diffstat | 5 files changed, 105 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Sep 05 15:35:48 2026 -0500 @@ -0,0 +1,2 @@ +main +dnft
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE Sat Sep 05 15:35:48 2026 -0500 @@ -0,0 +1,7 @@ +ISC License + +Copyright 2026 Yasuri <linuxoverwindows@charliesmp.net> + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Sat Sep 05 15:35:48 2026 -0500 @@ -0,0 +1,21 @@ +dnft +---- +dnft is a fzf-based TUI for Fedora's DNF. + +dependencies +------------ +C++ compiler +DNF +fzf +sudo + +how to build +------------ +run: g++ main.cpp -o dnft + +what it does +------------ +lists all packages, pipes into fzf, and installs the selection. +state of dnft +------------- +this is a early ALPHA version, i just finished it. please email any bugs to linuxoverwindows [at] charliesmp.net.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pipes.cpp Sat Sep 05 15:35:48 2026 -0500 @@ -0,0 +1,52 @@ +#include <iostream> +#include <unistd.h> +#include <spawn.h> +#include <cstring> +#include <string> +#include <sys/wait.h> +extern char** environ; +std::string run_piped(const char* path, char* const argv[], const std::string& input) +{ + int status; + pid_t pid; + int pipeA[2]; + int pipeB[2]; + pipe(pipeA); + pipe(pipeB); + posix_spawn_file_actions_t actions; + posix_spawn_file_actions_init(&actions); // initialize actions + posix_spawn_file_actions_adddup2(&actions, pipeA[0], STDIN_FILENO); + posix_spawn_file_actions_adddup2(&actions, pipeB[1], STDOUT_FILENO); + posix_spawn_file_actions_addclose(&actions, pipeA[1]); // closes write end in child + posix_spawn_file_actions_addclose(&actions, pipeB[0]); // makes sure child doesn't read its own output pipe + posix_spawn_file_actions_addclose(&actions, pipeA[0]); // close read fd in child + posix_spawn_file_actions_addclose(&actions, pipeB[1]); // close read fd in child, part 2 + std::cout << "Running posix_spawn()..." << std::endl; + status = posix_spawn(&pid, path, &actions, NULL, const_cast<char* const*>(argv), environ); + close(pipeA[0]); + close(pipeB[1]); + if (status != 0) { + posix_spawn_file_actions_destroy(&actions); + close(pipeA[1]); + close(pipeB[0]); + std::cerr << "posix_spawn failed: " << strerror(status) << std::endl; + return "error"; + } + write(pipeA[1],input.c_str(), input.size()); + close(pipeA[1]); + char buf[256]; +std::string result; +ssize_t n; +while ((n = read(pipeB[0], buf, sizeof(buf))) > 0) { + result.append(buf, n); +} + close(pipeB[0]); + if (waitpid(pid, &status, 0) == -1) { + posix_spawn_file_actions_destroy(&actions); + close(pipeA[1]); + close(pipeB[0]); + perror("waitpid"); + return "error"; + } + return result; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spawn.cpp Sat Sep 05 15:35:48 2026 -0500 @@ -0,0 +1,23 @@ +#include <iostream> +#include <unistd.h> +#include <sys/wait.h> +#include <spawn.h> +extern char** environ; // idk what this does +int spawn(char* const argv[], const char* path) +{ + pid_t pid; + int status; + status = posix_spawn(&pid, path, NULL, NULL, const_cast<char* const*>(argv), environ); + if (status != 0) { + std::cerr << "posix_spawn failed:" << strerror(status) << std::endl; + return 1; + } + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid"); + return 1; + } + if (WIFEXITED(status)) { + return WEXITSTATUS(status); + } + return 1; +}
