@@ -95,7 +95,6 @@ void Application::Vits(std::string text) {
9595}
9696
9797void Application::render_code_box () {
98-
9998 ImGuiStyle &style = ImGui::GetStyle ();
10099 style.Colors [ImGuiCol_WindowBg] = ImVec4 (0 .95f , 0 .95f , 0 .95f , 1 .0f );
101100 style.Colors [ImGuiCol_TitleBg] = ImVec4 (0 .85f , 0 .85f , 0 .85f , 1 .0f );
@@ -113,19 +112,19 @@ void Application::render_code_box() {
113112 style.Colors [ImGuiCol_ScrollbarGrabHovered] = ImVec4 (0 .8f , 0 .8f , 0 .8f , 1 .0f );
114113 style.Colors [ImGuiCol_ScrollbarGrabActive] = ImVec4 (0 .9f , 0 .9f , 0 .9f , 1 .0f );
115114
116- ImGui::SetNextWindowSize (ImVec2 (400 , 300 ));
117- ImGui::Begin (" Code Box" , nullptr ,
118- ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings);
119-
115+ ImGui::Begin (" Code Box" , nullptr , ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoTitleBar);
120116 ImGui::PushStyleVar (ImGuiStyleVar_FrameRounding, 5 .0f );
121- // 显示 vector 中的值
122- for (const auto &value: codes) {
123- // 显示按钮
124- if (ImGui::Button (value.c_str (), ImVec2 (-1 , 0 ))) {
125- // 将值复制到剪贴板
126- glfwSetClipboardString (nullptr , value.c_str ());
117+
118+ static bool show_codes = false ;
119+ for (auto &it: codes) {
120+ show_codes = ImGui::CollapsingHeader (it.first .c_str ());
121+ if (show_codes) {
122+ for (const auto &code: it.second ) {
123+ if (ImGui::Button (code.c_str (), ImVec2 (-1 , 0 ))) {
124+ glfwSetClipboardString (nullptr , code.c_str ());
125+ }
126+ }
127127 }
128- ImGui::SameLine ();
129128 }
130129
131130 ImGui::PopStyleVar ();
@@ -509,8 +508,19 @@ void Application::render_input_box() {
509508 bot.content = response;
510509 add_chat_record (bot);
511510 it = submit_futures.erase (it);
512- for (auto &i: Utils::GetAllCodesFromText (response)) {
513- codes.emplace_back (i);
511+ auto tmp_code = Utils::GetAllCodesFromText (response);
512+ for (auto &i: tmp_code) {
513+ std::size_t pos = i.find (' \n ' ); // 查找第一个换行符的位置
514+ std::string codetype;
515+ if (pos != std::string::npos) { // 如果找到了换行符
516+ codetype = i.substr (0 , pos);
517+ i = i.substr (pos + 1 ); // 删除第一行
518+ }
519+ if (codes.contains (codetype)) {
520+ codes[codetype].emplace_back (i);
521+ } else {
522+ codes.insert ({codetype, {i}});
523+ }
514524 }
515525 if (vits && vitsData.enable ) {
516526 std::string VitsText = translator->translate (Utils::ExtractNormalText (response), vitsData.lanType );
0 commit comments