✨ 新增: 添加自定义主题设置相关函数
parent
0a57dae39c
commit
57cac6a451
|
@ -5,7 +5,26 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <imgui.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
|
||||
struct LogColors {
|
||||
ImVec4 error_color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
|
||||
ImVec4 warn_color = ImVec4(1.0f, 1.0f, 0.4f, 1.0f);
|
||||
ImVec4 info_color = ImVec4(0.4f, 1.0f, 0.4f, 1.0f);
|
||||
ImVec4 debug_color = ImVec4(0.6f, 0.6f, 1.0f, 1.0f);
|
||||
ImVec4 trace_color = ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
|
||||
|
||||
void ResetToDefaults() {
|
||||
error_color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
|
||||
warn_color = ImVec4(1.0f, 1.0f, 0.4f, 1.0f);
|
||||
info_color = ImVec4(0.4f, 1.0f, 0.4f, 1.0f);
|
||||
debug_color = ImVec4(0.6f, 0.6f, 1.0f, 1.0f);
|
||||
trace_color = ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AppState {
|
||||
public:
|
||||
|
@ -50,8 +69,12 @@ public:
|
|||
std::vector<std::string> command_history;
|
||||
int max_command_history;
|
||||
|
||||
LogColors log_colors;
|
||||
bool use_custom_log_colors = false;
|
||||
bool use_ansi_colors = true;
|
||||
bool settings_dirty;
|
||||
|
||||
|
||||
private:
|
||||
// 环境变量序列化辅助函数
|
||||
std::string SerializeEnvironmentVariables() const;
|
||||
|
@ -60,8 +83,11 @@ private:
|
|||
// 编码序列化辅助函数
|
||||
std::string SerializeOutputEncoding() const;
|
||||
void DeserializeOutputEncoding(const std::string& serialized);
|
||||
// 日志颜色序列化辅助
|
||||
std::string SerializeLogColors() const;
|
||||
void DeserializeLogColors(const std::string &serialized);
|
||||
|
||||
// 新增:命令历史记录序列化辅助函数
|
||||
// 命令历史记录序列化辅助函数
|
||||
std::string SerializeCommandHistory() const;
|
||||
void DeserializeCommandHistory(const std::string& serialized);
|
||||
};
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "AppState.h"
|
||||
#include "TrayIcon.h"
|
||||
|
||||
|
||||
class Manager {
|
||||
public:
|
||||
// 构造函数和析构函数
|
||||
|
@ -69,10 +70,14 @@ private:
|
|||
void RenderUI(); // 渲染主UI
|
||||
void RenderMenuBar(); // 渲染菜单栏
|
||||
void RenderMainContent(); // 渲染主内容区域
|
||||
|
||||
|
||||
void RenderSettingsMenu(); // 渲染设置菜单
|
||||
void RenderStopCommandSettings(); // 渲染停止命令设置
|
||||
void RenderEnvironmentVariablesSettings(); // 渲染环境变量设置
|
||||
void RenderOutputEncodingSettings(); // 渲染输出编码设置
|
||||
void RenderColorThemeSettings();
|
||||
|
||||
void RenderControlPanel(float buttonWidth, float buttonHeight, float inputWidth); // 渲染控制面板
|
||||
void RenderCommandPanel(float buttonWidth, float inputWidth); // 渲染命令面板
|
||||
void RenderLogPanel(); // 渲染日志面板
|
||||
|
@ -99,6 +104,11 @@ private:
|
|||
void UpdateDPIScale(); // 更新DPI缩放
|
||||
void ReloadFonts() const; // 重新加载字体
|
||||
|
||||
void SaveCurrentTheme();
|
||||
void LoadSavedTheme();
|
||||
|
||||
ImVec4 GetCustomLogLevelColor(const std::string &log);
|
||||
|
||||
// 平台相关初始化方法
|
||||
#ifdef USE_WIN32_BACKEND
|
||||
bool InitializeWin32(); // 初始化Win32
|
||||
|
@ -167,4 +177,10 @@ private:
|
|||
bool show_env_settings_ = false; // 是否显示环境变量设置
|
||||
bool show_encoding_settings_ = false; // 是否显示编码设置
|
||||
bool show_command_history_ = false; // 是否显示命令历史
|
||||
|
||||
bool m_show_theme_save_success = true;
|
||||
float m_theme_save_success_timer = 3.0f;
|
||||
|
||||
float m_theme_load_success_timer = 0.0f;
|
||||
bool m_show_theme_load_success = false;
|
||||
};
|
||||
|
|
|
@ -160,6 +160,82 @@ void AppState::DeserializeOutputEncoding(const std::string& serialized) {
|
|||
}
|
||||
}
|
||||
|
||||
std::string AppState::SerializeLogColors() const {
|
||||
std::ostringstream oss;
|
||||
|
||||
// 按顺序保存每个颜色的RGBA值
|
||||
oss << log_colors.error_color.x << ","
|
||||
<< log_colors.error_color.y << ","
|
||||
<< log_colors.error_color.z << ","
|
||||
<< log_colors.error_color.w << "|";
|
||||
|
||||
oss << log_colors.warn_color.x << ","
|
||||
<< log_colors.warn_color.y << ","
|
||||
<< log_colors.warn_color.z << ","
|
||||
<< log_colors.warn_color.w << "|";
|
||||
|
||||
oss << log_colors.info_color.x << ","
|
||||
<< log_colors.info_color.y << ","
|
||||
<< log_colors.info_color.z << ","
|
||||
<< log_colors.info_color.w << "|";
|
||||
|
||||
oss << log_colors.debug_color.x << ","
|
||||
<< log_colors.debug_color.y << ","
|
||||
<< log_colors.debug_color.z << ","
|
||||
<< log_colors.debug_color.w << "|";
|
||||
|
||||
oss << log_colors.trace_color.x << ","
|
||||
<< log_colors.trace_color.y << ","
|
||||
<< log_colors.trace_color.z << ","
|
||||
<< log_colors.trace_color.w;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// 新增:反序列化日志颜色
|
||||
void AppState::DeserializeLogColors(const std::string& serialized) {
|
||||
if (serialized.empty()) {
|
||||
log_colors.ResetToDefaults();
|
||||
return;
|
||||
}
|
||||
|
||||
std::istringstream iss(serialized);
|
||||
std::string colorStr;
|
||||
int colorIndex = 0;
|
||||
|
||||
while (std::getline(iss, colorStr, '|') && colorIndex < 5) {
|
||||
std::istringstream colorIss(colorStr);
|
||||
std::string component;
|
||||
float rgba[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
int i = 0;
|
||||
|
||||
while (std::getline(colorIss, component, ',') && i < 4) {
|
||||
try {
|
||||
rgba[i++] = std::stof(component);
|
||||
} catch (const std::exception&) {
|
||||
// 如果解析失败,使用默认值
|
||||
}
|
||||
}
|
||||
|
||||
ImVec4 color(rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||
|
||||
switch (colorIndex) {
|
||||
case 0: log_colors.error_color = color; break;
|
||||
case 1: log_colors.warn_color = color; break;
|
||||
case 2: log_colors.info_color = color; break;
|
||||
case 3: log_colors.debug_color = color; break;
|
||||
case 4: log_colors.trace_color = color; break;
|
||||
}
|
||||
|
||||
colorIndex++;
|
||||
}
|
||||
|
||||
// 如果没有足够的颜色数据,重置为默认值
|
||||
if (colorIndex < 5) {
|
||||
log_colors.ResetToDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
void AppState::LoadSettings() {
|
||||
std::ifstream file("climanager_settings.ini");
|
||||
if (!file.is_open()) return;
|
||||
|
@ -234,6 +310,14 @@ void AppState::LoadSettings() {
|
|||
else if (key == "MaxCommandHistory") {
|
||||
max_command_history = std::stoi(value);
|
||||
max_command_history = std::max(5, std::min(max_command_history, 100));
|
||||
}else if (key == "UseCustomLogColors") {
|
||||
use_custom_log_colors = (value == "1");
|
||||
}
|
||||
else if (key == "UseAnsiColors") {
|
||||
use_ansi_colors = (value == "1");
|
||||
}
|
||||
else if (key == "LogColors") {
|
||||
DeserializeLogColors(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -271,6 +355,9 @@ void AppState::SaveSettings() {
|
|||
file << "CommandHistory=" << SerializeCommandHistory() << "\n";
|
||||
file << "MaxCommandHistory=" << max_command_history << "\n";
|
||||
|
||||
file << "UseCustomLogColors=" << (use_custom_log_colors ? "1" : "0") << "\n";
|
||||
file << "UseAnsiColors=" << (use_ansi_colors ? "1" : "0") << "\n";
|
||||
file << "LogColors=" << SerializeLogColors() << "\n";
|
||||
file.close();
|
||||
|
||||
settings_dirty = false;
|
||||
|
|
|
@ -113,6 +113,7 @@ bool Manager::Initialize() {
|
|||
m_app_state.ApplySettings();
|
||||
m_app_state.SaveSettings();
|
||||
|
||||
LoadSavedTheme();
|
||||
#ifdef _WIN32
|
||||
m_tray->UpdateWebUrl(StringToWide(m_app_state.web_url));
|
||||
|
||||
|
@ -302,9 +303,10 @@ void Manager::RenderMenuBar() {
|
|||
|
||||
// 添加主题菜单
|
||||
if (ImGui::BeginMenu("主题")) {
|
||||
if (ImGui::MenuItem("暗黑(Dark)")) { ImGui::StyleColorsDark(); }
|
||||
if (ImGui::MenuItem("明亮(Light)")) { ImGui::StyleColorsLight(); }
|
||||
if (ImGui::MenuItem("经典(Classic)")) { ImGui::StyleColorsClassic(); }
|
||||
// if (ImGui::MenuItem("暗黑(Dark)")) { ImGui::StyleColorsDark(); }
|
||||
// if (ImGui::MenuItem("明亮(Light)")) { ImGui::StyleColorsLight(); }
|
||||
// if (ImGui::MenuItem("经典(Classic)")) { ImGui::StyleColorsClassic(); }
|
||||
RenderColorThemeSettings();
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
|
@ -510,6 +512,45 @@ void Manager::RenderStatusMessages() {
|
|||
m_show_load_success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_show_theme_save_success) {
|
||||
ImGui::SetNextWindowPos(ImVec2(ImGui::GetMainViewport()->Size.x * 0.5f, 50), ImGuiCond_Always,
|
||||
ImVec2(0.5f, 0.0f));
|
||||
ImGui::SetNextWindowBgAlpha(0.8f);
|
||||
|
||||
if (ImGui::Begin("ThemeSaveSuccess", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar |
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::TextColored(ImVec4(0.0f, 1.0f, 0.0f, 1.0f), "主题已保存");
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
m_theme_save_success_timer -= ImGui::GetIO().DeltaTime;
|
||||
if (m_theme_save_success_timer <= 0.0f) {
|
||||
m_show_theme_save_success = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染主题加载成功提示
|
||||
if (m_show_theme_load_success) {
|
||||
ImGui::SetNextWindowPos(ImVec2(ImGui::GetMainViewport()->Size.x * 0.5f, 50), ImGuiCond_Always,
|
||||
ImVec2(0.5f, 0.0f));
|
||||
ImGui::SetNextWindowBgAlpha(0.8f);
|
||||
|
||||
if (ImGui::Begin("ThemeLoadSuccess", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar |
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::TextColored(ImVec4(0.0f, 1.0f, 0.0f, 1.0f), "主题已加载");
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
m_theme_load_success_timer -= ImGui::GetIO().DeltaTime;
|
||||
if (m_theme_load_success_timer <= 0.0f) {
|
||||
m_show_theme_load_success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::RenderMainContent() {
|
||||
|
@ -585,6 +626,7 @@ void Manager::RenderSettingsMenu() {
|
|||
RenderStopCommandSettings();
|
||||
RenderEnvironmentVariablesSettings();
|
||||
RenderOutputEncodingSettings();
|
||||
|
||||
}
|
||||
|
||||
void Manager::RenderStopCommandSettings() {
|
||||
|
@ -774,7 +816,8 @@ void Manager::RenderControlPanel(float buttonWidth, float buttonHeight, float in
|
|||
if (strlen(m_app_state.working_directory) > 0) {
|
||||
m_app_state.cli_process.SetWorkingDirectory(m_app_state.working_directory);
|
||||
} else {
|
||||
strncpy_s(m_app_state.working_directory,m_app_state.cli_process.GetWorkingDirectory().c_str(),sizeof(m_app_state.working_directory)-1);
|
||||
strncpy_s(m_app_state.working_directory, m_app_state.cli_process.GetWorkingDirectory().c_str(),
|
||||
sizeof(m_app_state.working_directory) - 1);
|
||||
}
|
||||
m_tray->UpdateStatus(m_app_state.cli_process.IsRunning() ? L"运行中" : L"已停止",
|
||||
m_app_state.cli_process.GetPid());
|
||||
|
@ -800,9 +843,9 @@ void Manager::RenderControlPanel(float buttonWidth, float buttonHeight, float in
|
|||
|
||||
// 状态显示
|
||||
ImGui::SeparatorText("运行状态");
|
||||
ImVec4 statusColor = m_app_state.cli_process.IsRunning() ?
|
||||
ImVec4(0.0f, 1.0f, 0.0f, 1.0f) :
|
||||
ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
ImVec4 statusColor = m_app_state.cli_process.IsRunning()
|
||||
? ImVec4(0.0f, 1.0f, 0.0f, 1.0f)
|
||||
: ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
ImGui::TextColored(statusColor, "状态: %s",
|
||||
m_app_state.cli_process.IsRunning() ? "运行中" : "已停止");
|
||||
}
|
||||
|
@ -875,12 +918,18 @@ void Manager::RenderLogPanel() {
|
|||
const std::string &log = logs[i];
|
||||
|
||||
if (m_app_state.enable_colored_logs) {
|
||||
if (m_app_state.use_ansi_colors) {
|
||||
// 使用ANSI颜色转义序列解析
|
||||
RenderColoredLogLine(log);
|
||||
} else {
|
||||
// 简单的日志级别颜色区分
|
||||
ImVec4 textColor = GetLogLevelColor(log);
|
||||
// 仅使用日志级别的颜色区分
|
||||
ImVec4 textColor = GetCustomLogLevelColor(log);
|
||||
ImGui::TextColored(textColor, "%s", log.c_str());
|
||||
}
|
||||
} else {
|
||||
// 不启用彩色显示,使用默认白色
|
||||
ImGui::TextUnformatted(log.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1502,3 +1551,241 @@ extern "C" {
|
|||
void* GetMacTrayIcon();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void Manager::RenderColorThemeSettings() {
|
||||
// 预设主题
|
||||
if (ImGui::MenuItem("暗黑(Dark)")) {
|
||||
ImGui::StyleColorsDark();
|
||||
}
|
||||
if (ImGui::MenuItem("明亮(Light)")) {
|
||||
ImGui::StyleColorsLight();
|
||||
}
|
||||
if (ImGui::MenuItem("经典(Classic)")) {
|
||||
ImGui::StyleColorsClassic();
|
||||
}
|
||||
ImGui::Separator();
|
||||
ImGui::Text("颜色主题设置");
|
||||
|
||||
if (ImGui::Checkbox("自定义日志颜色", &m_app_state.use_custom_log_colors)) {
|
||||
m_app_state.settings_dirty = true;
|
||||
}
|
||||
|
||||
if (m_app_state.use_custom_log_colors) {
|
||||
ImGui::Indent();
|
||||
|
||||
ImGui::Text("日志级别颜色:");
|
||||
|
||||
// 编辑错误日志颜色
|
||||
ImVec4 errorColor = ImVec4(
|
||||
m_app_state.log_colors.error_color.x,
|
||||
m_app_state.log_colors.error_color.y,
|
||||
m_app_state.log_colors.error_color.z,
|
||||
1.0f
|
||||
);
|
||||
if (ImGui::ColorEdit3("错误日志", (float *) &errorColor)) {
|
||||
m_app_state.log_colors.error_color = errorColor;
|
||||
m_app_state.settings_dirty = true;
|
||||
}
|
||||
|
||||
// 编辑警告日志颜色
|
||||
ImVec4 warnColor = ImVec4(
|
||||
m_app_state.log_colors.warn_color.x,
|
||||
m_app_state.log_colors.warn_color.y,
|
||||
m_app_state.log_colors.warn_color.z,
|
||||
1.0f
|
||||
);
|
||||
if (ImGui::ColorEdit3("警告日志", (float *) &warnColor)) {
|
||||
m_app_state.log_colors.warn_color = warnColor;
|
||||
m_app_state.settings_dirty = true;
|
||||
}
|
||||
|
||||
// 编辑信息日志颜色
|
||||
ImVec4 infoColor = ImVec4(
|
||||
m_app_state.log_colors.info_color.x,
|
||||
m_app_state.log_colors.info_color.y,
|
||||
m_app_state.log_colors.info_color.z,
|
||||
1.0f
|
||||
);
|
||||
if (ImGui::ColorEdit3("信息日志", (float *) &infoColor)) {
|
||||
m_app_state.log_colors.info_color = infoColor;
|
||||
m_app_state.settings_dirty = true;
|
||||
}
|
||||
|
||||
// 编辑调试日志颜色
|
||||
ImVec4 debugColor = ImVec4(
|
||||
m_app_state.log_colors.debug_color.x,
|
||||
m_app_state.log_colors.debug_color.y,
|
||||
m_app_state.log_colors.debug_color.z,
|
||||
1.0f
|
||||
);
|
||||
if (ImGui::ColorEdit3("调试日志", (float *) &debugColor)) {
|
||||
m_app_state.log_colors.debug_color = debugColor;
|
||||
m_app_state.settings_dirty = true;
|
||||
}
|
||||
|
||||
// 重置为默认颜色按钮
|
||||
if (ImGui::Button("重置为默认颜色")) {
|
||||
m_app_state.log_colors.ResetToDefaults();
|
||||
m_app_state.settings_dirty = true;
|
||||
}
|
||||
|
||||
ImGui::Unindent();
|
||||
}
|
||||
|
||||
// ANSI颜色设置
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::Checkbox("使用ANSI颜色转义", &m_app_state.use_ansi_colors)) {
|
||||
m_app_state.settings_dirty = true;
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("(?)");
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
|
||||
ImGui::TextUnformatted("启用后,日志中的ANSI颜色转义序列将被解析并显示为彩色文本。");
|
||||
ImGui::TextUnformatted("例如: \\033[31m红色文本\\033[0m");
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
// 颜色样式设置
|
||||
ImGui::Text("全局颜色样式:");
|
||||
|
||||
static int currentTheme = 0; // 默认暗色主题
|
||||
const char *themes[] = {"暗黑 (Dark)", "明亮 (Light)", "经典 (Classic)", "自定义 (Custom)"};
|
||||
|
||||
if (ImGui::Combo("应用主题", ¤tTheme, themes, IM_ARRAYSIZE(themes))) {
|
||||
switch (currentTheme) {
|
||||
case 0: ImGui::StyleColorsDark();
|
||||
break;
|
||||
case 1: ImGui::StyleColorsLight();
|
||||
break;
|
||||
case 2: ImGui::StyleColorsClassic();
|
||||
break;
|
||||
case 3: /* 应用自定义主题 */ break;
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义主题编辑器(仅在选择"自定义"主题时显示)
|
||||
if (currentTheme == 3) {
|
||||
if (ImGui::TreeNode("自定义主题编辑器")) {
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
|
||||
// 添加主题颜色编辑器
|
||||
for (int i = 0; i < ImGuiCol_COUNT; i++) {
|
||||
const char *name = ImGui::GetStyleColorName(i);
|
||||
ImGui::ColorEdit4(name, (float *) &style.Colors[i]);
|
||||
}
|
||||
|
||||
// 添加样式参数编辑器
|
||||
ImGui::SliderFloat("窗口圆角", &style.WindowRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("子窗口圆角", &style.ChildRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("框架圆角", &style.FrameRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("弹出窗口圆角", &style.PopupRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("滚动条圆角", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("抓取圆角", &style.GrabRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("标签圆角", &style.TabRounding, 0.0f, 12.0f, "%.0f");
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
// 保存/加载主题按钮
|
||||
if (ImGui::Button("保存当前主题")) {
|
||||
SaveCurrentTheme();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("加载保存的主题")) {
|
||||
LoadSavedTheme();
|
||||
}
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存当前主题设置
|
||||
void Manager::SaveCurrentTheme() {
|
||||
std::ofstream file("theme.ini", std::ios::binary);
|
||||
if (file.is_open()) {
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
|
||||
// 保存主题颜色
|
||||
for (int i = 0; i < ImGuiCol_COUNT; i++) {
|
||||
file.write(reinterpret_cast<const char *>(&style.Colors[i]), sizeof(ImVec4));
|
||||
}
|
||||
|
||||
// 保存样式参数
|
||||
file.write(reinterpret_cast<const char *>(&style.WindowRounding), sizeof(float));
|
||||
file.write(reinterpret_cast<const char *>(&style.ChildRounding), sizeof(float));
|
||||
file.write(reinterpret_cast<const char *>(&style.FrameRounding), sizeof(float));
|
||||
file.write(reinterpret_cast<const char *>(&style.PopupRounding), sizeof(float));
|
||||
file.write(reinterpret_cast<const char *>(&style.ScrollbarRounding), sizeof(float));
|
||||
file.write(reinterpret_cast<const char *>(&style.GrabRounding), sizeof(float));
|
||||
file.write(reinterpret_cast<const char *>(&style.TabRounding), sizeof(float));
|
||||
|
||||
file.close();
|
||||
|
||||
// 显示保存成功提示
|
||||
m_show_theme_save_success = true;
|
||||
m_theme_save_success_timer = 3.0f; // 3秒后消失
|
||||
}
|
||||
}
|
||||
|
||||
// 加载保存的主题设置
|
||||
void Manager::LoadSavedTheme() {
|
||||
std::ifstream file("theme.ini", std::ios::binary);
|
||||
if (file.is_open()) {
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
|
||||
// 加载主题颜色
|
||||
for (int i = 0; i < ImGuiCol_COUNT; i++) {
|
||||
file.read(reinterpret_cast<char *>(&style.Colors[i]), sizeof(ImVec4));
|
||||
}
|
||||
|
||||
// 加载样式参数
|
||||
file.read(reinterpret_cast<char *>(&style.WindowRounding), sizeof(float));
|
||||
file.read(reinterpret_cast<char *>(&style.ChildRounding), sizeof(float));
|
||||
file.read(reinterpret_cast<char *>(&style.FrameRounding), sizeof(float));
|
||||
file.read(reinterpret_cast<char *>(&style.PopupRounding), sizeof(float));
|
||||
file.read(reinterpret_cast<char *>(&style.ScrollbarRounding), sizeof(float));
|
||||
file.read(reinterpret_cast<char *>(&style.GrabRounding), sizeof(float));
|
||||
file.read(reinterpret_cast<char *>(&style.TabRounding), sizeof(float));
|
||||
|
||||
file.close();
|
||||
|
||||
// 显示加载成功提示
|
||||
m_show_theme_load_success = true;
|
||||
m_theme_load_success_timer = 3.0f; // 3秒后消失
|
||||
}
|
||||
}
|
||||
|
||||
ImVec4 Manager::GetCustomLogLevelColor(const std::string &log) {
|
||||
if (!m_app_state.use_custom_log_colors) {
|
||||
// 使用默认颜色
|
||||
return GetLogLevelColor(log);
|
||||
}
|
||||
|
||||
// 使用自定义颜色
|
||||
if (log.find("错误") != std::string::npos || log.find("[E]") != std::string::npos ||
|
||||
log.find("[ERROR]") != std::string::npos || log.find("error") != std::string::npos) {
|
||||
return m_app_state.log_colors.error_color;
|
||||
} else if (log.find("警告") != std::string::npos || log.find("[W]") != std::string::npos ||
|
||||
log.find("[WARN]") != std::string::npos || log.find("warning") != std::string::npos) {
|
||||
return m_app_state.log_colors.warn_color;
|
||||
} else if (log.find("信息") != std::string::npos || log.find("[I]") != std::string::npos ||
|
||||
log.find("[INFO]") != std::string::npos || log.find("info") != std::string::npos) {
|
||||
return m_app_state.log_colors.info_color;
|
||||
} else if (log.find("调试") != std::string::npos || log.find("[D]") != std::string::npos ||
|
||||
log.find("[DEBUG]") != std::string::npos || log.find("debug") != std::string::npos) {
|
||||
return m_app_state.log_colors.debug_color;
|
||||
} else if (log.find("跟踪") != std::string::npos || log.find("[T]") != std::string::npos ||
|
||||
log.find("[TRACE]") != std::string::npos || log.find("trace") != std::string::npos) {
|
||||
return m_app_state.log_colors.trace_color;
|
||||
}
|
||||
|
||||
return ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // 默认白色
|
||||
}
|
||||
|
|
|
@ -45,8 +45,7 @@ void SetAutoStart(bool enable) {
|
|||
if (enable) {
|
||||
RegSetValueEx(hKey, keyName, 0, REG_SZ,
|
||||
(BYTE *) exePath, (wcslen(exePath) + 1) * sizeof(WCHAR));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
RegDeleteValue(hKey, keyName);
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
|
@ -79,6 +78,7 @@ bool IsAutoStartEnabled() {
|
|||
return exists;
|
||||
}
|
||||
|
||||
// 日志颜色处理函数
|
||||
ImVec4 GetLogLevelColor(const std::string &log) {
|
||||
// 简单的日志级别颜色区分
|
||||
if (log.find("错误") != std::string::npos || log.find("[E]") != std::string::npos ||
|
||||
|
@ -90,11 +90,17 @@ ImVec4 GetLogLevelColor(const std::string &log) {
|
|||
} else if (log.find("信息") != std::string::npos || log.find("[I]") != std::string::npos ||
|
||||
log.find("[INFO]") != std::string::npos || log.find("info") != std::string::npos) {
|
||||
return ImVec4(0.4f, 1.0f, 0.4f, 1.0f); // 绿色
|
||||
} else if (log.find("调试") != std::string::npos || log.find("[D]") != std::string::npos ||
|
||||
log.find("[DEBUG]") != std::string::npos || log.find("debug") != std::string::npos) {
|
||||
return ImVec4(0.6f, 0.6f, 1.0f, 1.0f); // 蓝色
|
||||
} else if (log.find("跟踪") != std::string::npos || log.find("[T]") != std::string::npos ||
|
||||
log.find("[TRACE]") != std::string::npos || log.find("trace") != std::string::npos) {
|
||||
return ImVec4(0.8f, 0.8f, 0.8f, 1.0f); // 灰色
|
||||
}
|
||||
return ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // 默认白色
|
||||
}
|
||||
|
||||
|
||||
// ANSI颜色处理增强版本
|
||||
void RenderColoredLogLine(const std::string &log) {
|
||||
auto segments = ParseAnsiColorCodes(log);
|
||||
|
||||
|
@ -263,10 +269,49 @@ ParseAnsiColorCode(const std::string &code, const ImVec4 ¤tColor, bool cur
|
|||
newColor = GetAnsiColor(15, false);
|
||||
break; // 亮白色
|
||||
|
||||
// 背景色暂时忽略 (40-47, 100-107)
|
||||
// 增加对背景色的支持 (40-47, 100-107)
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
case 44:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 100:
|
||||
case 101:
|
||||
case 102:
|
||||
case 103:
|
||||
case 104:
|
||||
case 105:
|
||||
case 106:
|
||||
case 107:
|
||||
// 背景色暂时不处理,因为ImGui不容易实现背景色
|
||||
break;
|
||||
|
||||
default:
|
||||
// 处理256色和RGB色彩(38;5;n 和 38;2;r;g;b)
|
||||
// 这里可以根据需要扩展
|
||||
if (colorCode == 38 || colorCode == 48) {
|
||||
// 38=前景,48=背景
|
||||
// 检查是否是256色模式或RGB模式
|
||||
if (codes.size() > 1) {
|
||||
if (codes[1] == 5 && codes.size() > 2) {
|
||||
// 256色模式
|
||||
// 暂时不实现所有256色,仅处理基本的16色
|
||||
int colorIndex = codes[2];
|
||||
if (colorIndex >= 0 && colorIndex < 16) {
|
||||
newColor = GetAnsiColor(colorIndex, newBold);
|
||||
}
|
||||
} else if (codes[1] == 2 && codes.size() > 4) {
|
||||
// RGB模式
|
||||
// 处理RGB值
|
||||
float r = static_cast<float>(codes[2]) / 255.0f;
|
||||
float g = static_cast<float>(codes[3]) / 255.0f;
|
||||
float b = static_cast<float>(codes[4]) / 255.0f;
|
||||
newColor = ImVec4(r, g, b, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -313,3 +358,4 @@ ImVec4 GetAnsiColor(int colorIndex, bool bright) {
|
|||
|
||||
return ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // 默认白色
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue