diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6138a00..d75e85a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,6 +34,8 @@ message(STATUS "[GCTL] Use the GMT library: " ${GCTL_GMT})
message(STATUS "[GCTL] Check Bounder: " ${GCTL_CHECK_BOUNDER})
message(STATUS "[GCTL] Check Size: " ${GCTL_CHECK_SIZE})
+find_library(NCURSES_LIB ncurses REQUIRED)
+
if(GCTL_FFTW3)
if(NOT FFTW3_FOUND)
find_package(FFTW3 REQUIRED)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index e26edde..27a7353 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -42,6 +42,9 @@ set_target_properties(gctl_static PROPERTIES INSTALL_RPATH /usr/local/lib)
set_target_properties(gctl PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
set_target_properties(gctl_static PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
+target_link_libraries(gctl PUBLIC ${NCURSES_LIB})
+target_link_libraries(gctl_static ${NCURSES_LIB})
+
if(GCTL_NETCDF)
target_link_libraries(gctl PUBLIC ${netCDF_CXX_LEGACY_LIB})
target_link_libraries(gctl_static ${netCDF_CXX_LEGACY_LIB})
diff --git a/lib/io.h b/lib/io.h
index cc994aa..2777008 100644
--- a/lib/io.h
+++ b/lib/io.h
@@ -40,5 +40,6 @@
#include "io/off_io.h"
#include "io/stl_io.h"
#include "io/ply_io.h"
+#include "io/cli_viewer.h"
#endif // _GCTL_IO_H
\ No newline at end of file
diff --git a/lib/io/cli_viewer.cpp b/lib/io/cli_viewer.cpp
new file mode 100644
index 0000000..337c04f
--- /dev/null
+++ b/lib/io/cli_viewer.cpp
@@ -0,0 +1,93 @@
+/********************************************************
+ * ██████╗ ██████╗████████╗██╗
+ * ██╔════╝ ██╔════╝╚══██╔══╝██║
+ * ██║ ███╗██║ ██║ ██║
+ * ██║ ██║██║ ██║ ██║
+ * ╚██████╔╝╚██████╗ ██║ ███████╗
+ * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
+ * Geophysical Computational Tools & Library (GCTL)
+ *
+ * Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
+ *
+ * GCTL is distributed under a dual licensing scheme. You can redistribute
+ * it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either version 2
+ * of the License, or (at your option) any later version. You should have
+ * received a copy of the GNU Lesser General Public License along with this
+ * program. If not, see .
+ *
+ * If the terms and conditions of the LGPL v.2. would prevent you from using
+ * the GCTL, please consider the option to obtain a commercial license for a
+ * fee. These licenses are offered by the GCTL's original author. As a rule,
+ * licenses are provided "as-is", unlimited in time for a one time fee. Please
+ * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
+ * to include some description of your company and the realm of its activities.
+ * Also add information on how to contact you by electronic and paper mail.
+ ******************************************************/
+
+#include "cli_viewer.h"
+
+gctl::cli_viewer::cli_viewer()
+{
+ // 初始化ncurses
+ initscr();
+ cbreak(); // 禁用行缓冲
+ noecho(); // 不显示输入字符
+ keypad(stdscr, TRUE); // 启用键盘扩展键
+ timeout(0); // 设置非阻塞输入
+ curs_set(0); // 隐藏光标
+}
+
+// 析构函数
+gctl::cli_viewer::~cli_viewer()
+{
+ // 清理ncurses
+ endwin();
+}
+
+// 设置显示内容
+void gctl::cli_viewer::setData(const std::vector& data)
+{
+ lines = data;
+ return;
+}
+
+void gctl::cli_viewer::addData(const std::string& l)
+{
+ lines.push_back(l);
+ return;
+}
+
+// 显示文件内容并进入查看循环
+void gctl::cli_viewer::display()
+{
+ int maxLines = LINES - 1; // 终端的行数(减去提示行)
+ int startLine = 0; // 当前显示的起始行
+ // 主循环
+ while (true)
+ {
+ // 清屏并显示文件内容
+ werase(stdscr); // 清屏但不闪烁
+ for (int i = startLine; i < startLine + maxLines && i < lines.size(); ++i)
+ {
+ mvprintw(i - startLine, 0, "%s", lines[i].c_str());
+ }
+ // 在最后一行显示提示信息
+ mvprintw(LINES - 1, 0, "Use arrow keys or mouse wheel to scroll. Press Q or ESC to exit.");
+ int ch = getch(); // 获取按键
+ if (ch == KEY_UP)
+ {
+ startLine = std::max(0, startLine - 1); // 向上滚动
+ }
+ else if (ch == KEY_DOWN)
+ {
+ startLine = std::min(startLine + 1, static_cast(lines.size()) - maxLines); // 向下滚动
+ }
+ else if (ch == 'q' || ch == 'Q' || ch == 27)
+ { // 按Q或ESC退出
+ break;
+ }
+ wrefresh(stdscr); // 刷新屏幕
+ }
+ return;
+}
\ No newline at end of file
diff --git a/lib/io/cli_viewer.h b/lib/io/cli_viewer.h
new file mode 100644
index 0000000..ff230b9
--- /dev/null
+++ b/lib/io/cli_viewer.h
@@ -0,0 +1,57 @@
+/********************************************************
+ * ██████╗ ██████╗████████╗██╗
+ * ██╔════╝ ██╔════╝╚══██╔══╝██║
+ * ██║ ███╗██║ ██║ ██║
+ * ██║ ██║██║ ██║ ██║
+ * ╚██████╔╝╚██████╗ ██║ ███████╗
+ * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
+ * Geophysical Computational Tools & Library (GCTL)
+ *
+ * Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
+ *
+ * GCTL is distributed under a dual licensing scheme. You can redistribute
+ * it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either version 2
+ * of the License, or (at your option) any later version. You should have
+ * received a copy of the GNU Lesser General Public License along with this
+ * program. If not, see .
+ *
+ * If the terms and conditions of the LGPL v.2. would prevent you from using
+ * the GCTL, please consider the option to obtain a commercial license for a
+ * fee. These licenses are offered by the GCTL's original author. As a rule,
+ * licenses are provided "as-is", unlimited in time for a one time fee. Please
+ * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
+ * to include some description of your company and the realm of its activities.
+ * Also add information on how to contact you by electronic and paper mail.
+ ******************************************************/
+
+#ifndef _GCTL_CLI_VIEWER_H
+#define _GCTL_CLI_VIEWER_H
+
+#include
+#include
+#include
+#include
+
+namespace gctl
+{
+ class cli_viewer
+ {
+ public:
+ // 构造函数
+ cli_viewer();
+ // 析构函数
+ ~cli_viewer();
+ // 设置显示内容
+ void setData(const std::vector& data);
+ // 添加显示内容
+ void addData(const std::string& l);
+ // 显示文件内容并进入查看循环
+ void display();
+
+ private:
+ std::vector lines; // 存储文件内容
+ };
+};
+
+#endif // _GCTL_CLI_VIEWER_H
\ No newline at end of file
diff --git a/lib/io/dsv_io.cpp b/lib/io/dsv_io.cpp
index b79c1dd..eaf97f0 100644
--- a/lib/io/dsv_io.cpp
+++ b/lib/io/dsv_io.cpp
@@ -26,6 +26,7 @@
******************************************************/
#include "dsv_io.h"
+#include "cli_viewer.h"
gctl::dsv_io::dsv_io()
{
@@ -521,24 +522,29 @@ void gctl::dsv_io::info(int t, std::ostream &os)
return;
}
-void gctl::dsv_io::display(std::ostream &os)
+void gctl::dsv_io::display()
{
+ std::string line;
+ cli_viewer viewer;
for (int i = 0; i <= row_num_; i++)
{
for (size_t j = 0; j <= col_num_; j++)
{
if (table_[i][j].out_ok_ && table_[i][j].str_!= "")
{
- os << table_[i][j].str_;
+ line = table_[i][j].str_;
for (size_t k = j + 1; k <= col_num_; k++)
{
- if (table_[i][k].out_ok_) os << deli_sym_ << table_[i][k].str_;
+ if (table_[i][k].out_ok_) line += deli_sym_ + table_[i][k].str_;
}
- os << std::endl;
+
+ viewer.addData(line);
break;
}
}
}
+
+ viewer.display();
return;
}
diff --git a/lib/io/dsv_io.h b/lib/io/dsv_io.h
index f60db1a..9f09b77 100644
--- a/lib/io/dsv_io.h
+++ b/lib/io/dsv_io.h
@@ -440,9 +440,8 @@ namespace gctl
/**
* @brief 显示表格(不会显示失效的行和列)
*
- * @param os 输出流
*/
- void display(std::ostream &os = std::cout);
+ void display();
/**
* @brief 返回名称为name和R和C的行或列的索引