add:尝试添加选择task内容功能(未完成)。
This commit is contained in:
parent
78036328a5
commit
3b82087eee
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -21,7 +21,7 @@
|
||||
],
|
||||
"visualizerFile": "${workspaceRoot}/.vscode/qt5.natvis",
|
||||
"args": [
|
||||
"-n", "0"
|
||||
"-n", "1"
|
||||
]
|
||||
},
|
||||
"cmake.environment": {
|
||||
|
@ -383,13 +383,14 @@ bool CClient::request_update_list(const std::string& param)
|
||||
// 校验格式是否正确
|
||||
auto vec = COfStr::split(content, "\n");
|
||||
bool valid = true;
|
||||
int line = 1;
|
||||
std::unordered_map<int, std::string> mre{};
|
||||
std::string handled_content;
|
||||
for (const auto& item : vec) {
|
||||
std::string hitem = COfStr::trim(item);
|
||||
if (hitem.empty()) {
|
||||
continue;
|
||||
}
|
||||
mpinfo("---> check {}", hitem);
|
||||
auto v = COfStr::split(hitem, "|");
|
||||
if (v.size() >= 2) {
|
||||
auto pr = variable_handle(list_file_full, v[0], true);
|
||||
@ -398,8 +399,8 @@ bool CClient::request_update_list(const std::string& param)
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
mpinfo("---> check pass {}", pr);
|
||||
handled_content.append(pr + "|" + v[1] + "\n");
|
||||
mpinfo("--->check pass {}:{}", line, pr);
|
||||
mre[line++] = pr + "|" + v[1];
|
||||
continue;
|
||||
}
|
||||
valid = false;
|
||||
@ -411,15 +412,21 @@ bool CClient::request_update_list(const std::string& param)
|
||||
return false;
|
||||
}
|
||||
|
||||
auto handel_ret = handle_user_select(mre);
|
||||
if (handel_ret.empty()) {
|
||||
mperror("handle_user_select not pass, abort action!");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
handled_content = CCodec::ansi_to_u8(handled_content);
|
||||
handel_ret = CCodec::ansi_to_u8(handel_ret);
|
||||
#endif
|
||||
|
||||
list_file_ = list_file_full;
|
||||
std::shared_ptr<CFrameBuffer> buf = std::make_shared<CFrameBuffer>();
|
||||
buf->type_ = TYPE_REQUEST_UPDATE_LIST;
|
||||
buf->data_ = new char[handled_content.size() + 1]();
|
||||
buf->len_ = std::snprintf(buf->data_, handled_content.size() + 1, "%s", handled_content.c_str());
|
||||
buf->data_ = new char[handel_ret.size() + 1]();
|
||||
buf->len_ = std::snprintf(buf->data_, handel_ret.size() + 1, "%s", handel_ret.c_str());
|
||||
buf->tid_ = task_list_[index]->id;
|
||||
|
||||
if (!send_frame(buf.get())) {
|
||||
@ -824,6 +831,54 @@ std::string CClient::variable_handle(const std::string& task_list_path, const st
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string CClient::handle_user_select(const std::unordered_map<int, std::string>& source)
|
||||
{
|
||||
std::string handled_content{};
|
||||
std::string input{};
|
||||
|
||||
while (true) {
|
||||
mpinfo("numbers by space, or '0' use all, 'end' to quit: ");
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "end") {
|
||||
handled_content.clear();
|
||||
break;
|
||||
}
|
||||
if (input == "0") {
|
||||
handled_content.clear(); // 清空之前的内容
|
||||
for (const auto& pair : source) {
|
||||
handled_content.append(pair.second + "\n");
|
||||
}
|
||||
} else {
|
||||
// 处理多个值的输入
|
||||
std::stringstream ss(input);
|
||||
std::string num_str;
|
||||
|
||||
while (ss >> num_str) {
|
||||
// 判断输入的每个值是否为有效的数字
|
||||
try {
|
||||
int key = std::stoi(num_str);
|
||||
|
||||
if (source.find(key) != source.end()) {
|
||||
handled_content.append(source.at(key) + "\n");
|
||||
} else {
|
||||
// 如果mre中没有这个key
|
||||
mperror("Invalid input, please enter valid numbers or '0' for all.");
|
||||
break;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
mperror("Invalid input, please enter valid numbers or '0' for all.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!handled_content.empty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return handled_content;
|
||||
}
|
||||
|
||||
CFileOpr::CFileOpr() = default;
|
||||
|
||||
CFileOpr::~CFileOpr() = default;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <util.h>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace ofen;
|
||||
struct DownClientInfo {
|
||||
@ -65,6 +66,7 @@ private:
|
||||
void hearts();
|
||||
void judget_down_active();
|
||||
std::string variable_handle(const std::string& task_list_path, const std::string& source, bool is_send);
|
||||
std::string handle_user_select(const std::unordered_map<int, std::string>& source);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user