From 4c4eaf873408861546490614d81c582ef888b16b Mon Sep 17 00:00:00 2001
From: taynpg <taynpg@163.com>
Date: Fri, 28 Mar 2025 12:56:06 +0800
Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A1.=E6=B7=BB=E5=8A=A0=E9=87=8D?=
 =?UTF-8?q?=E5=90=AF=E5=8A=A8=E4=B9=9F=E8=83=BD=E6=81=A2=E5=A4=8D=E6=9C=80?=
 =?UTF-8?q?=E8=BF=91=E7=9A=84=E8=BE=93=E5=85=A5=E8=AE=B0=E5=BD=95=E3=80=82?=
 =?UTF-8?q?2.Get=E5=92=8CCancel=E5=8F=AF=E4=BB=A5=E7=AE=80=E5=8C=96?=
 =?UTF-8?q?=E8=BE=93=E5=85=A5g=E6=88=96=E8=80=85c=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .vscode/settings.json |  4 +--
 CMakeLists.txt        |  7 +----
 client/client.cpp     | 65 ++++++++++++++++++++++++++++++++++++++++---
 client/client.h       |  5 +++-
 client/config.cpp     |  6 ++++
 client/config.h       |  2 ++
 client/main.cpp       |  2 +-
 filecomplete          |  2 +-
 8 files changed, 78 insertions(+), 15 deletions(-)

diff --git a/.vscode/settings.json b/.vscode/settings.json
index fafc8cb..b4589e2 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,8 +1,8 @@
 {
     "files.autoSave": "onFocusChange",
     "editor.fontSize": 14,
-    "editor.fontFamily": "'Monaspace Krypton Light', 'Monaspace Krypton Light', 'Monaspace Krypton Light'",
-    "terminal.integrated.fontFamily": "Monaspace Krypton Light",
+    "editor.fontFamily": "'Source Code Pro', 'Source Code Pro', 'Source Code Pro'",
+    "terminal.integrated.fontFamily": "Source Code Pro",
     "editor.fontLigatures": true,
     //"C_Cpp.default.configurationProvider": "tboox.xmake-vscode",
     "cmake.configureOnOpen": true,
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3240411..4186390 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
 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_REQUIRED ON)
 
@@ -56,11 +56,6 @@ add_subdirectory(server)
 add_subdirectory(client)
 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")
 execute_process(
     COMMAND git rev-parse --short HEAD
diff --git a/client/client.cpp b/client/client.cpp
index dfbfec6..b23f300 100644
--- a/client/client.cpp
+++ b/client/client.cpp
@@ -1,4 +1,5 @@
 #include "client.h"
+
 #include <fstream>
 #include <iostream>
 #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;
     if (!client_->connect(ip, port)) {
         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));
             break;
         }
+        save_line_his(cmd_input);
         if (cmd_input == "who" || cmd_input == "Who") {
             TLOGD("ID => {}", own_id_);
             continue;
         }
-        if (cmd_input == "Where" || cmd_input == "where") {
+        if (cmd_input == "Where" || cmd_input == "where" || cmd_input == "wh") {
             TLOGD("At => {}", COfPath::to_full("."));
             continue;
         }
-        if (cmd_input == "Get" || cmd_input == "get") {
+        if (cmd_input == "Get" || cmd_input == "get" || cmd_input == "g" || cmd_input == "G") {
             get_task_list();
             continue;
         }
-        if (cmd_input == "Cancel" || cmd_input == "cancel") {
+        if (cmd_input == "Cancel" || cmd_input == "cancel" || cmd_input == "c" || cmd_input == "C") {
             cancel_task();
             continue;
         }
@@ -541,6 +550,54 @@ bool CClient::send_frame(CFrameBuffer* buf)
     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)
 {
     if (buf == nullptr) {
diff --git a/client/client.h b/client/client.h
index 17f0236..d0b6ef2 100644
--- a/client/client.h
+++ b/client/client.h
@@ -44,7 +44,7 @@ public:
     ~CClient();
 
 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:
     bool get_task_list();
@@ -59,6 +59,8 @@ public:
 
 private:
     bool send_frame(CFrameBuffer* buf);
+    void save_line_his(const std::string& input);
+    std::vector<std::string> load_line_his();
 
 private:
     void handle_frame(CFrameBuffer* buf);
@@ -92,6 +94,7 @@ private:
     std::string list_serve_id_;
     std::thread update_list_th_;
     std::string own_id_{};
+    std::string config_path_{};
 };
 
 class CFileOpr
diff --git a/client/config.cpp b/client/config.cpp
index 02b8011..990a6c1 100644
--- a/client/config.cpp
+++ b/client/config.cpp
@@ -19,6 +19,7 @@ CServerConfig::~CServerConfig() = default;
 bool CServerConfig::baseInit()
 {
     fs::path tpath(COfPath::get_config_dir("transm", true));
+    config_dir_ = tpath.string();
     config_path_ = tpath.append("transm.ini").string();
     if (!fs::exists(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;
 }
 
+std::string CServerConfig::get_config_dir() const
+{
+    return config_dir_;
+}
+
 bool CServerConfig::save_last_use(const std::string& ip, long port)
 {
     assert(init_ == true);
diff --git a/client/config.h b/client/config.h
index 1020adb..36a486c 100644
--- a/client/config.h
+++ b/client/config.h
@@ -38,6 +38,7 @@ public:
     long append_ini(const std::string& ip, long port, const std::string& comment);
     bool remove_ini(long num);
     static bool get_ini(const std::vector<TransmSet>& set, long num, TransmSet& use);
+    std::string get_config_dir() const;
 
 public:
     bool save_last_use(const std::string& ip, long port);
@@ -50,4 +51,5 @@ private:
     bool init_{false};
     CSimpleIniA ini_handle_{};
     std::string config_path_{};
+    std::string config_dir_{};
 };
\ No newline at end of file
diff --git a/client/main.cpp b/client/main.cpp
index 7a52e71..90fb73e 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -218,7 +218,7 @@ int main(int argc, char* argv[])
     TLOGI("Build At {} {} under {} on {}", __DATE__, __TIME__, VERSION_GIT_COMMIT, VERSION_GIT_BRANCH);
     TLOGI("use ip => [{}], port => [{}]", ip, port);
     CClient client;
-    client.run(ip, std::to_string(port));
+    client.run(ip, std::to_string(port), g_Config->get_config_dir());
     TLOGI("exit ==========");
     return 0;
 }
\ No newline at end of file
diff --git a/filecomplete b/filecomplete
index 389837f..c477dad 160000
--- a/filecomplete
+++ b/filecomplete
@@ -1 +1 @@
-Subproject commit 389837feb3c1147a39729907ce361dad54c5a437
+Subproject commit c477dad67e171aecf9fb5b8ce361119bf459ff8f