tmp
This commit is contained in:
parent
a43fd84986
commit
dfce004048
@ -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 Bounder: " ${GCTL_CHECK_BOUNDER})
|
||||||
message(STATUS "[GCTL] Check Size: " ${GCTL_CHECK_SIZE})
|
message(STATUS "[GCTL] Check Size: " ${GCTL_CHECK_SIZE})
|
||||||
|
|
||||||
|
find_library(NCURSES_LIB ncurses REQUIRED)
|
||||||
|
|
||||||
if(GCTL_FFTW3)
|
if(GCTL_FFTW3)
|
||||||
if(NOT FFTW3_FOUND)
|
if(NOT FFTW3_FOUND)
|
||||||
find_package(FFTW3 REQUIRED)
|
find_package(FFTW3 REQUIRED)
|
||||||
|
@ -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 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||||
set_target_properties(gctl_static 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)
|
if(GCTL_NETCDF)
|
||||||
target_link_libraries(gctl PUBLIC ${netCDF_CXX_LEGACY_LIB})
|
target_link_libraries(gctl PUBLIC ${netCDF_CXX_LEGACY_LIB})
|
||||||
target_link_libraries(gctl_static ${netCDF_CXX_LEGACY_LIB})
|
target_link_libraries(gctl_static ${netCDF_CXX_LEGACY_LIB})
|
||||||
|
1
lib/io.h
1
lib/io.h
@ -40,5 +40,6 @@
|
|||||||
#include "io/off_io.h"
|
#include "io/off_io.h"
|
||||||
#include "io/stl_io.h"
|
#include "io/stl_io.h"
|
||||||
#include "io/ply_io.h"
|
#include "io/ply_io.h"
|
||||||
|
#include "io/cli_viewer.h"
|
||||||
|
|
||||||
#endif // _GCTL_IO_H
|
#endif // _GCTL_IO_H
|
93
lib/io/cli_viewer.cpp
Normal file
93
lib/io/cli_viewer.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* 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<std::string>& 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<int>(lines.size()) - maxLines); // 向下滚动
|
||||||
|
}
|
||||||
|
else if (ch == 'q' || ch == 'Q' || ch == 27)
|
||||||
|
{ // 按Q或ESC退出
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wrefresh(stdscr); // 刷新屏幕
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
57
lib/io/cli_viewer.h
Normal file
57
lib/io/cli_viewer.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* 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 <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
class cli_viewer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// 构造函数
|
||||||
|
cli_viewer();
|
||||||
|
// 析构函数
|
||||||
|
~cli_viewer();
|
||||||
|
// 设置显示内容
|
||||||
|
void setData(const std::vector<std::string>& data);
|
||||||
|
// 添加显示内容
|
||||||
|
void addData(const std::string& l);
|
||||||
|
// 显示文件内容并进入查看循环
|
||||||
|
void display();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::string> lines; // 存储文件内容
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _GCTL_CLI_VIEWER_H
|
@ -26,6 +26,7 @@
|
|||||||
******************************************************/
|
******************************************************/
|
||||||
|
|
||||||
#include "dsv_io.h"
|
#include "dsv_io.h"
|
||||||
|
#include "cli_viewer.h"
|
||||||
|
|
||||||
gctl::dsv_io::dsv_io()
|
gctl::dsv_io::dsv_io()
|
||||||
{
|
{
|
||||||
@ -521,24 +522,29 @@ void gctl::dsv_io::info(int t, std::ostream &os)
|
|||||||
return;
|
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 (int i = 0; i <= row_num_; i++)
|
||||||
{
|
{
|
||||||
for (size_t j = 0; j <= col_num_; j++)
|
for (size_t j = 0; j <= col_num_; j++)
|
||||||
{
|
{
|
||||||
if (table_[i][j].out_ok_ && table_[i][j].str_!= "")
|
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++)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewer.display();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,9 +440,8 @@ namespace gctl
|
|||||||
/**
|
/**
|
||||||
* @brief 显示表格(不会显示失效的行和列)
|
* @brief 显示表格(不会显示失效的行和列)
|
||||||
*
|
*
|
||||||
* @param os 输出流
|
|
||||||
*/
|
*/
|
||||||
void display(std::ostream &os = std::cout);
|
void display();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 返回名称为name和R<id>和C<id>的行或列的索引
|
* @brief 返回名称为name和R<id>和C<id>的行或列的索引
|
||||||
|
Loading…
Reference in New Issue
Block a user