add:1.添加重启动也能恢复最近的输入记录。2.Get和Cancel可以简化输入g或者c。
This commit is contained in:
parent
b41a54ca89
commit
4c4eaf8734
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"files.autoSave": "onFocusChange",
|
"files.autoSave": "onFocusChange",
|
||||||
"editor.fontSize": 14,
|
"editor.fontSize": 14,
|
||||||
"editor.fontFamily": "'Monaspace Krypton Light', 'Monaspace Krypton Light', 'Monaspace Krypton Light'",
|
"editor.fontFamily": "'Source Code Pro', 'Source Code Pro', 'Source Code Pro'",
|
||||||
"terminal.integrated.fontFamily": "Monaspace Krypton Light",
|
"terminal.integrated.fontFamily": "Source Code Pro",
|
||||||
"editor.fontLigatures": true,
|
"editor.fontLigatures": true,
|
||||||
//"C_Cpp.default.configurationProvider": "tboox.xmake-vscode",
|
//"C_Cpp.default.configurationProvider": "tboox.xmake-vscode",
|
||||||
"cmake.configureOnOpen": true,
|
"cmake.configureOnOpen": true,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
project(transm VERSION 1.2.8 LANGUAGES CXX)
|
project(transm VERSION 1.3.0 LANGUAGES CXX)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
@ -56,11 +56,6 @@ add_subdirectory(server)
|
|||||||
add_subdirectory(client)
|
add_subdirectory(client)
|
||||||
add_subdirectory(filecomplete)
|
add_subdirectory(filecomplete)
|
||||||
|
|
||||||
if(DEFINED TSCGUI)
|
|
||||||
message(STATUS "transm use TSCGUI defined ${TSCGUI}")
|
|
||||||
add_subdirectory(gui)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(TIMESTAMP VERSION_BUILD_DATE "%Y-%m-%d %H:%M")
|
string(TIMESTAMP VERSION_BUILD_DATE "%Y-%m-%d %H:%M")
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND git rev-parse --short HEAD
|
COMMAND git rev-parse --short HEAD
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <of_path.h>
|
#include <of_path.h>
|
||||||
@ -48,8 +49,15 @@ CClient::~CClient()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::run(const std::string& ip, const std::string& port)
|
void CClient::run(const std::string& ip, const std::string& port, const std::string& config_dir)
|
||||||
{
|
{
|
||||||
|
fs::path fp(config_dir);
|
||||||
|
config_path_ = fp.append("history.txt").string();
|
||||||
|
auto his = load_line_his();
|
||||||
|
for (const auto& cc : his) {
|
||||||
|
fc_add_his(cc.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
th_run_ = true;
|
th_run_ = true;
|
||||||
if (!client_->connect(ip, port)) {
|
if (!client_->connect(ip, port)) {
|
||||||
TLOGI("{} connect err.", __FUNCTION__);
|
TLOGI("{} connect err.", __FUNCTION__);
|
||||||
@ -88,19 +96,20 @@ void CClient::run(const std::string& ip, const std::string& port)
|
|||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
save_line_his(cmd_input);
|
||||||
if (cmd_input == "who" || cmd_input == "Who") {
|
if (cmd_input == "who" || cmd_input == "Who") {
|
||||||
TLOGD("ID => {}", own_id_);
|
TLOGD("ID => {}", own_id_);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cmd_input == "Where" || cmd_input == "where") {
|
if (cmd_input == "Where" || cmd_input == "where" || cmd_input == "wh") {
|
||||||
TLOGD("At => {}", COfPath::to_full("."));
|
TLOGD("At => {}", COfPath::to_full("."));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cmd_input == "Get" || cmd_input == "get") {
|
if (cmd_input == "Get" || cmd_input == "get" || cmd_input == "g" || cmd_input == "G") {
|
||||||
get_task_list();
|
get_task_list();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cmd_input == "Cancel" || cmd_input == "cancel") {
|
if (cmd_input == "Cancel" || cmd_input == "cancel" || cmd_input == "c" || cmd_input == "C") {
|
||||||
cancel_task();
|
cancel_task();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -541,6 +550,54 @@ bool CClient::send_frame(CFrameBuffer* buf)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CClient::save_line_his(const std::string& input)
|
||||||
|
{
|
||||||
|
if (input.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto history = load_line_his();
|
||||||
|
|
||||||
|
for (const auto& item : history) {
|
||||||
|
if (input == item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
history.push_back(input);
|
||||||
|
|
||||||
|
const size_t max_history = 30;
|
||||||
|
if (history.size() > max_history) {
|
||||||
|
history.erase(history.begin());
|
||||||
|
}
|
||||||
|
std::ofstream out_file(config_path_, std::ios::out);
|
||||||
|
if (out_file.is_open()) {
|
||||||
|
for (const auto& line : history) {
|
||||||
|
out_file << line << "\n";
|
||||||
|
}
|
||||||
|
out_file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> CClient::load_line_his()
|
||||||
|
{
|
||||||
|
std::vector<std::string> history;
|
||||||
|
if (!std::filesystem::exists(config_path_)) {
|
||||||
|
return history;
|
||||||
|
}
|
||||||
|
std::ifstream in_file(config_path_, std::ios::in);
|
||||||
|
if (in_file.is_open()) {
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(in_file, line)) {
|
||||||
|
if (!line.empty()) {
|
||||||
|
history.push_back(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
in_file.close();
|
||||||
|
}
|
||||||
|
return history;
|
||||||
|
}
|
||||||
|
|
||||||
void CClient::handle_frame(CFrameBuffer* buf)
|
void CClient::handle_frame(CFrameBuffer* buf)
|
||||||
{
|
{
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
~CClient();
|
~CClient();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void run(const std::string& ip, const std::string& port);
|
void run(const std::string& ip, const std::string& port, const std::string& config_dir);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool get_task_list();
|
bool get_task_list();
|
||||||
@ -59,6 +59,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool send_frame(CFrameBuffer* buf);
|
bool send_frame(CFrameBuffer* buf);
|
||||||
|
void save_line_his(const std::string& input);
|
||||||
|
std::vector<std::string> load_line_his();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handle_frame(CFrameBuffer* buf);
|
void handle_frame(CFrameBuffer* buf);
|
||||||
@ -92,6 +94,7 @@ private:
|
|||||||
std::string list_serve_id_;
|
std::string list_serve_id_;
|
||||||
std::thread update_list_th_;
|
std::thread update_list_th_;
|
||||||
std::string own_id_{};
|
std::string own_id_{};
|
||||||
|
std::string config_path_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class CFileOpr
|
class CFileOpr
|
||||||
|
@ -19,6 +19,7 @@ CServerConfig::~CServerConfig() = default;
|
|||||||
bool CServerConfig::baseInit()
|
bool CServerConfig::baseInit()
|
||||||
{
|
{
|
||||||
fs::path tpath(COfPath::get_config_dir("transm", true));
|
fs::path tpath(COfPath::get_config_dir("transm", true));
|
||||||
|
config_dir_ = tpath.string();
|
||||||
config_path_ = tpath.append("transm.ini").string();
|
config_path_ = tpath.append("transm.ini").string();
|
||||||
if (!fs::exists(config_path_)) {
|
if (!fs::exists(config_path_)) {
|
||||||
gen_default_ini(config_path_);
|
gen_default_ini(config_path_);
|
||||||
@ -136,6 +137,11 @@ bool CServerConfig::get_ini(const std::vector<TransmSet>& set, long num, TransmS
|
|||||||
return find;
|
return find;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CServerConfig::get_config_dir() const
|
||||||
|
{
|
||||||
|
return config_dir_;
|
||||||
|
}
|
||||||
|
|
||||||
bool CServerConfig::save_last_use(const std::string& ip, long port)
|
bool CServerConfig::save_last_use(const std::string& ip, long port)
|
||||||
{
|
{
|
||||||
assert(init_ == true);
|
assert(init_ == true);
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
long append_ini(const std::string& ip, long port, const std::string& comment);
|
long append_ini(const std::string& ip, long port, const std::string& comment);
|
||||||
bool remove_ini(long num);
|
bool remove_ini(long num);
|
||||||
static bool get_ini(const std::vector<TransmSet>& set, long num, TransmSet& use);
|
static bool get_ini(const std::vector<TransmSet>& set, long num, TransmSet& use);
|
||||||
|
std::string get_config_dir() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool save_last_use(const std::string& ip, long port);
|
bool save_last_use(const std::string& ip, long port);
|
||||||
@ -50,4 +51,5 @@ private:
|
|||||||
bool init_{false};
|
bool init_{false};
|
||||||
CSimpleIniA ini_handle_{};
|
CSimpleIniA ini_handle_{};
|
||||||
std::string config_path_{};
|
std::string config_path_{};
|
||||||
|
std::string config_dir_{};
|
||||||
};
|
};
|
@ -218,7 +218,7 @@ int main(int argc, char* argv[])
|
|||||||
TLOGI("Build At {} {} under {} on {}", __DATE__, __TIME__, VERSION_GIT_COMMIT, VERSION_GIT_BRANCH);
|
TLOGI("Build At {} {} under {} on {}", __DATE__, __TIME__, VERSION_GIT_COMMIT, VERSION_GIT_BRANCH);
|
||||||
TLOGI("use ip => [{}], port => [{}]", ip, port);
|
TLOGI("use ip => [{}], port => [{}]", ip, port);
|
||||||
CClient client;
|
CClient client;
|
||||||
client.run(ip, std::to_string(port));
|
client.run(ip, std::to_string(port), g_Config->get_config_dir());
|
||||||
TLOGI("exit ==========");
|
TLOGI("exit ==========");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit 389837feb3c1147a39729907ce361dad54c5a437
|
Subproject commit c477dad67e171aecf9fb5b8ce361119bf459ff8f
|
Loading…
x
Reference in New Issue
Block a user