git: 4c4329a8a3cb - main - sysutils/rw-tui: New port: Read & Write Everything (only memory for now on FreeBSD)

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Wed, 12 Jun 2024 09:15:22 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=4c4329a8a3cbae54ceb2d16c6ce90e60eb02d456

commit 4c4329a8a3cbae54ceb2d16c6ce90e60eb02d456
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2024-06-12 09:14:44 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2024-06-12 09:15:20 +0000

    sysutils/rw-tui: New port: Read & Write Everything (only memory for now on FreeBSD)
---
 sysutils/Makefile                            |  1 +
 sysutils/rw-tui/Makefile                     | 26 ++++++++++
 sysutils/rw-tui/distinfo                     |  3 ++
 sysutils/rw-tui/files/patch-CMakeLists.txt   | 16 +++++++
 sysutils/rw-tui/files/patch-src_dataview.cpp | 21 ++++++++
 sysutils/rw-tui/files/patch-src_main.cpp     | 72 ++++++++++++++++++++++++++++
 sysutils/rw-tui/pkg-descr                    |  1 +
 7 files changed, 140 insertions(+)

diff --git a/sysutils/Makefile b/sysutils/Makefile
index 5d5dc42e3c8f..25665d4d2792 100644
--- a/sysutils/Makefile
+++ b/sysutils/Makefile
@@ -1324,6 +1324,7 @@
     SUBDIR += rust-coreutils
     SUBDIR += rust-findutils
     SUBDIR += rw
+    SUBDIR += rw-tui
     SUBDIR += s-tui
     SUBDIR += s6
     SUBDIR += s6-rc
diff --git a/sysutils/rw-tui/Makefile b/sysutils/rw-tui/Makefile
new file mode 100644
index 000000000000..eb60676d76db
--- /dev/null
+++ b/sysutils/rw-tui/Makefile
@@ -0,0 +1,26 @@
+PORTNAME=	rw-tui
+DISTVERSIONPREFIX=	v
+DISTVERSION=	1.0.0-1
+DISTVERSIONSUFFIX=	-gfd62cef
+CATEGORIES=	sysutils
+
+MAINTAINER=	yuri@FreeBSD.org
+COMMENT=	Read & Write Everything (only memory for now on FreeBSD)
+WWW=		https://github.com/LeeKyuHyuk/rw-tui
+
+LICENSE=	MIT
+LICENSE_FILE=	${WRKSRC}/LICENSE
+
+LIB_DEPENDS=	libftxui-screen.so:devel/ftxui
+
+USES=		cmake #localbase:ldflags
+
+USE_GITHUB=	yes
+GH_ACCOUNT=	LeeKyuHyuk
+
+PLIST_FILES=	bin/${PORTNAME}
+
+do-install:
+	${INSTALL_PROGRAM} ${BUILD_WRKSRC}/${PORTNAME} ${STAGEDIR}${PREFIX}/bin
+
+.include <bsd.port.mk>
diff --git a/sysutils/rw-tui/distinfo b/sysutils/rw-tui/distinfo
new file mode 100644
index 000000000000..509023c1485b
--- /dev/null
+++ b/sysutils/rw-tui/distinfo
@@ -0,0 +1,3 @@
+TIMESTAMP = 1718043067
+SHA256 (LeeKyuHyuk-rw-tui-v1.0.0-1-gfd62cef_GH0.tar.gz) = 920ce14c2d4932277fac1a97906cdd731953a7eaeb30f99a6d0c4254cbedfbd1
+SIZE (LeeKyuHyuk-rw-tui-v1.0.0-1-gfd62cef_GH0.tar.gz) = 2005010
diff --git a/sysutils/rw-tui/files/patch-CMakeLists.txt b/sysutils/rw-tui/files/patch-CMakeLists.txt
new file mode 100644
index 000000000000..3bceb9a1b4a7
--- /dev/null
+++ b/sysutils/rw-tui/files/patch-CMakeLists.txt
@@ -0,0 +1,16 @@
+--- CMakeLists.txt.orig	2023-07-30 15:32:56 UTC
++++ CMakeLists.txt
+@@ -14,11 +14,10 @@ set_property(TARGET rw-tui PROPERTY CXX_STANDARD 17)
+ 
+ set_property(TARGET rw-tui PROPERTY CXX_STANDARD 17)
+ 
+-add_subdirectory(${CMAKE_SOURCE_DIR}/lib/ftxui ${CMAKE_BINARY_DIR}/ftxui EXCLUDE_FROM_ALL)
++find_package(ftxui REQUIRED)
+  
+ target_link_libraries(rw-tui
+   PRIVATE ftxui::screen
+   PRIVATE ftxui::dom
+   PRIVATE ftxui::component
+-  -static
+ )
+\ No newline at end of file
diff --git a/sysutils/rw-tui/files/patch-src_dataview.cpp b/sysutils/rw-tui/files/patch-src_dataview.cpp
new file mode 100644
index 000000000000..802791eb1b14
--- /dev/null
+++ b/sysutils/rw-tui/files/patch-src_dataview.cpp
@@ -0,0 +1,21 @@
+--- src/dataview.cpp.orig	2023-07-30 15:32:56 UTC
++++ src/dataview.cpp
+@@ -5,6 +5,9 @@
+ #include "global.hpp"
+ #include "utils/hex_string.hpp"
+ 
++#include <unistd.h>
++
++
+ DataView::DataView(uint64_t address) {
+   mContainer = Container::Vertical({});
+   mAddress = address;
+@@ -25,7 +28,7 @@ void DataView::refresh() {
+ void DataView::refresh() {
+   void *mapBase, *virtAddress;
+   mContainer->DetachAllChildren();
+-  mapBase = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
++  mapBase = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED,
+                  *gFileDescriptor, mAddress & ~MAP_MASK);
+   if (mapBase == (void *)-1)
+     FATAL;
diff --git a/sysutils/rw-tui/files/patch-src_main.cpp b/sysutils/rw-tui/files/patch-src_main.cpp
new file mode 100644
index 000000000000..f303ecfd92f3
--- /dev/null
+++ b/sysutils/rw-tui/files/patch-src_main.cpp
@@ -0,0 +1,72 @@
+--- src/main.cpp.orig	2023-07-30 15:32:56 UTC
++++ src/main.cpp
+@@ -25,7 +25,13 @@
+ #include "utils/is_file_exist.hpp"
+ 
+ #define DEV_MEM "/dev/mem"
+-#define DEV_FMEM "/dev/fmem"
++#if defined(__linux__)
++#  define DEV_FMEM "/dev/fmem"
++#elif defined(__FreeBSD__)
++#  define DEV_KMEM "/dev/kmem"
++#else
++#  error "Unsupported OS"
++#endif
+ 
+ using namespace std;
+ using namespace ftxui;
+@@ -71,6 +77,7 @@ int main(int argc, char *argv[]) {
+   gShowMessageModal = &showMessageModal;
+   gMessageStr = &messageStr;
+ 
++#if defined(__linux__)
+   if (isFileExist(DEV_FMEM) == false) {
+     if (isFileExist(DEV_MEM) == false) {
+       cerr << "[ERROR] Neither /dev/mem nor /dev/fmem exist.\nGet the source "
+@@ -90,9 +97,21 @@ int main(int argc, char *argv[]) {
+       return EXIT_FAILURE;
+     }
+   }
++#elif defined(__FreeBSD__)
++  if (isFileExist(DEV_MEM) == false /*|| isFileExist(DEV_KMEM) == false*/) {
++      cerr << "[ERROR] Either /dev/mem or /dev/kmem doesn't exist.\n"
++              "Please check if the kernel was configured with 'device mem'."
++           << endl;
++      return EXIT_FAILURE;
++  }
++#endif
+ 
+   int fileDescriptor;
++#if defined(__linux__)
+   if ((fileDescriptor = open(DEV_FMEM, O_RDWR | O_SYNC)) == -1)
++#elif defined(__FreeBSD__)
++  if ((fileDescriptor = open(DEV_MEM, O_RDWR | O_SYNC)) == -1)
++#endif
+     FATAL;
+   gFileDescriptor = &fileDescriptor;
+ 
+@@ -102,7 +121,7 @@ int main(int argc, char *argv[]) {
+   int tabSelected = 0;
+   vector<string> tabValues{
+       " Memory ",
+-      " PCI ",
++      //" PCI ",
+   };
+   auto tabToggle =
+       Menu(&tabValues, &tabSelected, MenuOption::Horizontal()) | border;
+@@ -110,7 +129,7 @@ int main(int argc, char *argv[]) {
+   Component tabContainer = Container::Tab(
+       {
+           (new Memory(0x00000000))->getComponent(),
+-          (new PCI(*gBaseAddress))->getComponent(),
++          //(new PCI(*gBaseAddress))->getComponent(),
+       },
+       &tabSelected);
+ 
+@@ -140,4 +159,4 @@ int main(int argc, char *argv[]) {
+               center);
+   close(fileDescriptor);
+   return EXIT_SUCCESS;
+-}
+\ No newline at end of file
++}
diff --git a/sysutils/rw-tui/pkg-descr b/sysutils/rw-tui/pkg-descr
new file mode 100644
index 000000000000..1bf5a47a90d4
--- /dev/null
+++ b/sysutils/rw-tui/pkg-descr
@@ -0,0 +1 @@
+rgb-tui is a color picker with a terminal UI.