Document configuration file & more cleanup

This commit is contained in:
2023-08-12 14:18:09 -04:00
parent eaf0fabc2d
commit 3970bc8acf
16 changed files with 389 additions and 232 deletions

View File

@@ -7,7 +7,6 @@ pub struct Appearance {
pub ui_font: FontId,
pub code_font: FontId,
pub diff_colors: Vec<Color32>,
pub reverse_fn_order: bool,
pub theme: eframe::Theme,
// Applied by theme
@@ -37,7 +36,6 @@ impl Default for Appearance {
ui_font: FontId { size: 12.0, family: FontFamily::Proportional },
code_font: FontId { size: 14.0, family: FontFamily::Monospace },
diff_colors: DEFAULT_COLOR_ROTATION.to_vec(),
reverse_fn_order: false,
theme: eframe::Theme::Dark,
text_color: Color32::GRAY,
emphasized_text_color: Color32::LIGHT_GRAY,

View File

@@ -2,8 +2,8 @@
use std::string::FromUtf16Error;
use std::{
borrow::Cow,
mem::take,
path::{PathBuf, MAIN_SEPARATOR},
sync::{Arc, RwLock},
};
#[cfg(windows)]
@@ -17,9 +17,13 @@ use globset::Glob;
use self_update::cargo_crate_version;
use crate::{
app::AppConfig,
config::{ProjectUnit, ProjectUnitNode},
jobs::{check_update::CheckUpdateResult, objdiff::start_build, update::start_update, JobQueue},
app::{AppConfig, AppConfigRef},
config::{ProjectObject, ProjectObjectNode},
jobs::{
check_update::{start_check_update, CheckUpdateResult},
update::start_update,
Job, JobQueue, JobResult,
},
update::RELEASE_URL,
views::appearance::Appearance,
};
@@ -27,14 +31,54 @@ use crate::{
#[derive(Default)]
pub struct ConfigViewState {
pub check_update: Option<Box<CheckUpdateResult>>,
pub check_update_running: bool,
pub queue_check_update: bool,
pub update_running: bool,
pub queue_update: bool,
pub build_running: bool,
pub queue_build: bool,
pub watch_pattern_text: String,
pub queue_update_check: bool,
pub load_error: Option<String>,
pub unit_search: String,
pub object_search: String,
#[cfg(windows)]
pub available_wsl_distros: Option<Vec<String>>,
}
impl ConfigViewState {
pub fn pre_update(&mut self, jobs: &mut JobQueue) {
jobs.results.retain_mut(|result| {
if let JobResult::CheckUpdate(result) = result {
self.check_update = take(result);
false
} else {
true
}
});
self.build_running = jobs.is_running(Job::ObjDiff);
self.check_update_running = jobs.is_running(Job::CheckUpdate);
self.update_running = jobs.is_running(Job::Update);
}
pub fn post_update(&mut self, jobs: &mut JobQueue, config: &AppConfigRef) {
if self.queue_build {
self.queue_build = false;
if let Ok(mut config) = config.write() {
config.queue_build = true;
}
}
if self.queue_check_update {
self.queue_check_update = false;
jobs.push_once(Job::CheckUpdate, start_check_update);
}
if self.queue_update {
self.queue_update = false;
jobs.push_once(Job::Update, start_update);
}
}
}
const DEFAULT_WATCH_PATTERNS: &[&str] = &[
"*.c", "*.cp", "*.cpp", "*.cxx", "*.h", "*.hp", "*.hpp", "*.hxx", "*.s", "*.S", "*.asm",
"*.inc", "*.py", "*.yml", "*.txt", "*.json",
@@ -75,8 +119,7 @@ fn fetch_wsl2_distros() -> Vec<String> {
pub fn config_ui(
ui: &mut egui::Ui,
config: &Arc<RwLock<AppConfig>>,
jobs: &mut JobQueue,
config: &AppConfigRef,
show_config_window: &mut bool,
state: &mut ConfigViewState,
appearance: &Appearance,
@@ -88,15 +131,15 @@ pub fn config_ui(
base_obj_dir,
obj_path,
auto_update_check,
units,
unit_nodes,
objects,
object_nodes,
..
} = &mut *config_guard;
ui.heading("Updates");
ui.checkbox(auto_update_check, "Check for updates on startup");
if ui.button("Check now").clicked() {
state.queue_update_check = true;
if ui.add_enabled(!state.check_update_running, egui::Button::new("Check now")).clicked() {
state.queue_check_update = true;
}
ui.label(format!("Current version: {}", cargo_crate_version!())).on_hover_ui_at_pointer(|ui| {
ui.label(formatcp!("Git branch: {}", env!("VERGEN_GIT_BRANCH")));
@@ -104,20 +147,20 @@ pub fn config_ui(
ui.label(formatcp!("Build target: {}", env!("VERGEN_CARGO_TARGET_TRIPLE")));
ui.label(formatcp!("Debug: {}", env!("VERGEN_CARGO_DEBUG")));
});
if let Some(state) = &state.check_update {
ui.label(format!("Latest version: {}", state.latest_release.version));
if state.update_available {
if let Some(result) = &state.check_update {
ui.label(format!("Latest version: {}", result.latest_release.version));
if result.update_available {
ui.colored_label(appearance.insert_color, "Update available");
ui.horizontal(|ui| {
if state.found_binary
if result.found_binary
&& ui
.button("Automatic")
.add_enabled(!state.update_running, egui::Button::new("Automatic"))
.on_hover_text_at_pointer(
"Automatically download and replace the current build",
)
.clicked()
{
jobs.push(start_update());
state.queue_update = true;
}
if ui
.button("Manual")
@@ -164,7 +207,7 @@ pub fn config_ui(
if let (Some(base_dir), Some(target_dir)) = (base_obj_dir, target_obj_dir) {
let mut new_build_obj = obj_path.clone();
if units.is_empty() {
if objects.is_empty() {
if ui.button("Select object").clicked() {
if let Some(path) = rfd::FileDialog::new()
.set_directory(&target_dir)
@@ -186,8 +229,8 @@ pub fn config_ui(
);
}
} else {
let had_search = !state.unit_search.is_empty();
egui::TextEdit::singleline(&mut state.unit_search).hint_text("Filter").ui(ui);
let had_search = !state.object_search.is_empty();
egui::TextEdit::singleline(&mut state.object_search).hint_text("Filter").ui(ui);
let mut root_open = None;
let mut node_open = NodeOpen::Default;
@@ -209,7 +252,7 @@ pub fn config_ui(
node_open = NodeOpen::Object;
}
});
if state.unit_search.is_empty() {
if state.object_search.is_empty() {
if had_search {
root_open = Some(true);
node_open = NodeOpen::Object;
@@ -226,11 +269,11 @@ pub fn config_ui(
.open(root_open)
.default_open(true)
.show(ui, |ui| {
let mut nodes = Cow::Borrowed(unit_nodes);
if !state.unit_search.is_empty() {
let search = state.unit_search.to_ascii_lowercase();
let mut nodes = Cow::Borrowed(object_nodes);
if !state.object_search.is_empty() {
let search = state.object_search.to_ascii_lowercase();
nodes = Cow::Owned(
unit_nodes.iter().filter_map(|node| filter_node(node, &search)).collect(),
object_nodes.iter().filter_map(|node| filter_node(node, &search)).collect(),
);
}
@@ -245,30 +288,30 @@ pub fn config_ui(
if let Some(obj) = new_build_obj {
// Will set obj_changed, which will trigger a rebuild
config_guard.set_obj_path(obj);
// TODO apply reverse_fn_order
}
}
if config_guard.obj_path.is_some() && ui.button("Build").clicked() {
// Rebuild immediately
jobs.push(start_build(config.clone()));
if config_guard.obj_path.is_some()
&& ui.add_enabled(!state.build_running, egui::Button::new("Build")).clicked()
{
state.queue_build = true;
}
} else {
ui.colored_label(appearance.delete_color, "Missing project settings");
}
// ui.checkbox(&mut view_config.reverse_fn_order, "Reverse function order (deferred)");
ui.separator();
}
fn display_unit(
fn display_object(
ui: &mut egui::Ui,
obj_path: &mut Option<String>,
name: &str,
unit: &ProjectUnit,
object: &ProjectObject,
appearance: &Appearance,
) {
let path_string = unit.path.to_string_lossy().to_string();
let path_string = object.path.to_string_lossy().to_string();
let selected = matches!(obj_path, Some(path) if path == &path_string);
let color = if selected { appearance.emphasized_text_color } else { appearance.text_color };
if SelectableLabel::new(
selected,
RichText::new(name)
@@ -276,7 +319,7 @@ fn display_unit(
size: appearance.ui_font.size,
family: appearance.code_font.family.clone(),
})
.color(appearance.text_color),
.color(color),
)
.ui(ui)
.clicked()
@@ -297,15 +340,15 @@ enum NodeOpen {
fn display_node(
ui: &mut egui::Ui,
obj_path: &mut Option<String>,
node: &ProjectUnitNode,
node: &ProjectObjectNode,
appearance: &Appearance,
node_open: NodeOpen,
) {
match node {
ProjectUnitNode::File(name, unit) => {
display_unit(ui, obj_path, name, unit, appearance);
ProjectObjectNode::File(name, object) => {
display_object(ui, obj_path, name, object, appearance);
}
ProjectUnitNode::Dir(name, children) => {
ProjectObjectNode::Dir(name, children) => {
let contains_obj = obj_path.as_ref().map(|path| contains_node(node, path));
let open = match node_open {
NodeOpen::Default => None,
@@ -336,33 +379,35 @@ fn display_node(
}
}
fn contains_node(node: &ProjectUnitNode, path: &str) -> bool {
fn contains_node(node: &ProjectObjectNode, path: &str) -> bool {
match node {
ProjectUnitNode::File(_, unit) => {
let path_string = unit.path.to_string_lossy().to_string();
ProjectObjectNode::File(_, object) => {
let path_string = object.path.to_string_lossy().to_string();
path == path_string
}
ProjectUnitNode::Dir(_, children) => children.iter().any(|node| contains_node(node, path)),
ProjectObjectNode::Dir(_, children) => {
children.iter().any(|node| contains_node(node, path))
}
}
}
fn filter_node(node: &ProjectUnitNode, search: &str) -> Option<ProjectUnitNode> {
fn filter_node(node: &ProjectObjectNode, search: &str) -> Option<ProjectObjectNode> {
match node {
ProjectUnitNode::File(name, _) => {
ProjectObjectNode::File(name, _) => {
if name.to_ascii_lowercase().contains(search) {
Some(node.clone())
} else {
None
}
}
ProjectUnitNode::Dir(name, children) => {
ProjectObjectNode::Dir(name, children) => {
if name.to_ascii_lowercase().contains(search) {
return Some(node.clone());
}
let new_children =
children.iter().filter_map(|child| filter_node(child, search)).collect::<Vec<_>>();
if !new_children.is_empty() {
Some(ProjectUnitNode::Dir(name.clone(), new_children))
Some(ProjectObjectNode::Dir(name.clone(), new_children))
} else {
None
}
@@ -411,7 +456,7 @@ fn pick_folder_ui(
pub fn project_window(
ctx: &egui::Context,
config: &Arc<RwLock<AppConfig>>,
config: &AppConfigRef,
show: &mut bool,
state: &mut ConfigViewState,
appearance: &Appearance,

View File

@@ -5,7 +5,6 @@ use egui_extras::{Column, TableBuilder};
use time::format_description;
use crate::{
jobs::{Job, JobQueue},
obj::{ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjSection},
views::{
appearance::Appearance,
@@ -164,15 +163,10 @@ fn data_table_ui(
Some(())
}
pub fn data_diff_ui(
ui: &mut egui::Ui,
jobs: &JobQueue,
state: &mut DiffViewState,
appearance: &Appearance,
) -> bool {
let mut rebuild = false;
let (Some(result), Some(selected_symbol)) = (&state.build, &state.selected_symbol) else {
return rebuild;
pub fn data_diff_ui(ui: &mut egui::Ui, state: &mut DiffViewState, appearance: &Appearance) {
let (Some(result), Some(selected_symbol)) = (&state.build, &state.symbol_state.selected_symbol)
else {
return;
};
// Header
@@ -210,13 +204,16 @@ pub fn data_diff_ui(
ui.set_width(column_width);
ui.horizontal(|ui| {
if ui.button("Build").clicked() {
rebuild = true;
if ui
.add_enabled(!state.build_running, egui::Button::new("Build"))
.clicked()
{
state.queue_build = true;
}
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
if jobs.is_running(Job::ObjDiff) {
if state.build_running {
ui.colored_label(appearance.replace_color, "Building…");
} else {
ui.label("Last built:");
@@ -257,6 +254,4 @@ pub fn data_diff_ui(
.min_scrolled_height(available_height);
data_table_ui(table, left_obj, right_obj, selected_symbol, appearance);
}
rebuild
}

View File

@@ -8,7 +8,6 @@ use ppc750cl::Argument;
use time::format_description;
use crate::{
jobs::{Job, JobQueue},
obj::{
ObjInfo, ObjIns, ObjInsArg, ObjInsArgDiff, ObjInsDiff, ObjInsDiffKind, ObjReloc,
ObjRelocKind, ObjSymbol,
@@ -403,15 +402,10 @@ fn asm_table_ui(
Some(())
}
pub fn function_diff_ui(
ui: &mut egui::Ui,
jobs: &JobQueue,
state: &mut DiffViewState,
appearance: &Appearance,
) -> bool {
let mut rebuild = false;
let (Some(result), Some(selected_symbol)) = (&state.build, &state.selected_symbol) else {
return rebuild;
pub fn function_diff_ui(ui: &mut egui::Ui, state: &mut DiffViewState, appearance: &Appearance) {
let (Some(result), Some(selected_symbol)) = (&state.build, &state.symbol_state.selected_symbol)
else {
return;
};
// Header
@@ -459,13 +453,16 @@ pub fn function_diff_ui(
ui.set_width(column_width);
ui.horizontal(|ui| {
if ui.button("Build").clicked() {
rebuild = true;
if ui
.add_enabled(!state.build_running, egui::Button::new("Build"))
.clicked()
{
state.queue_build = true;
}
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
if jobs.is_running(Job::ObjDiff) {
if state.build_running {
ui.colored_label(appearance.replace_color, "Building…");
} else {
ui.label("Last built:");
@@ -517,5 +514,4 @@ pub fn function_diff_ui(
.min_scrolled_height(available_height);
asm_table_ui(table, left_obj, right_obj, selected_symbol, appearance);
}
rebuild
}

View File

@@ -1,3 +1,5 @@
use std::mem::take;
use egui::{
text::LayoutJob, Align, CollapsingHeader, Color32, Layout, Rgba, ScrollArea, SelectableLabel,
TextEdit, Ui, Vec2, Widget,
@@ -5,7 +7,11 @@ use egui::{
use egui_extras::{Size, StripBuilder};
use crate::{
jobs::objdiff::{BuildStatus, ObjDiffResult},
app::AppConfigRef,
jobs::{
objdiff::{BuildStatus, ObjDiffResult},
Job, JobQueue, JobResult,
},
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
views::{appearance::Appearance, write_text},
};
@@ -16,7 +22,7 @@ pub struct SymbolReference {
}
#[allow(clippy::enum_variant_names)]
#[derive(Default, Eq, PartialEq)]
#[derive(Default, Eq, PartialEq, Copy, Clone)]
pub enum View {
#[default]
SymbolDiff,
@@ -28,9 +34,56 @@ pub enum View {
pub struct DiffViewState {
pub build: Option<Box<ObjDiffResult>>,
pub current_view: View,
pub symbol_state: SymbolViewState,
pub search: String,
pub queue_build: bool,
pub build_running: bool,
}
#[derive(Default)]
pub struct SymbolViewState {
pub highlighted_symbol: Option<String>,
pub selected_symbol: Option<SymbolReference>,
pub search: String,
pub reverse_fn_order: bool,
pub disable_reverse_fn_order: bool,
}
impl DiffViewState {
pub fn pre_update(&mut self, jobs: &mut JobQueue, config: &AppConfigRef) {
jobs.results.retain_mut(|result| {
if let JobResult::ObjDiff(result) = result {
self.build = take(result);
false
} else {
true
}
});
self.build_running = jobs.is_running(Job::ObjDiff);
self.symbol_state.disable_reverse_fn_order = false;
if let Ok(config) = config.read() {
if let Some(obj_path) = &config.obj_path {
if let Some(object) = config.objects.iter().find(|object| {
let path_string = object.path.to_string_lossy().to_string();
&path_string == obj_path
}) {
if let Some(value) = object.reverse_fn_order {
self.symbol_state.reverse_fn_order = value;
self.symbol_state.disable_reverse_fn_order = true;
}
}
}
}
}
pub fn post_update(&mut self, _jobs: &mut JobQueue, config: &AppConfigRef) {
if self.queue_build {
self.queue_build = false;
if let Ok(mut config) = config.write() {
config.queue_build = true;
}
}
}
}
pub fn match_color_for_symbol(match_percent: f32, appearance: &Appearance) -> Color32 {
@@ -79,30 +132,25 @@ fn symbol_hover_ui(ui: &mut Ui, symbol: &ObjSymbol, appearance: &Appearance) {
});
}
#[must_use]
fn symbol_ui(
ui: &mut Ui,
symbol: &ObjSymbol,
section: Option<&ObjSection>,
highlighted_symbol: &mut Option<String>,
selected_symbol: &mut Option<SymbolReference>,
current_view: &mut View,
state: &mut SymbolViewState,
appearance: &Appearance,
) {
) -> Option<View> {
let mut ret = None;
let mut job = LayoutJob::default();
let name: &str =
if let Some(demangled) = &symbol.demangled_name { demangled } else { &symbol.name };
let mut selected = false;
if let Some(sym) = highlighted_symbol {
if let Some(sym) = &state.highlighted_symbol {
selected = sym == &symbol.name;
}
write_text("[", appearance.text_color, &mut job, appearance.code_font.clone());
if symbol.flags.0.contains(ObjSymbolFlags::Common) {
write_text(
"c",
appearance.replace_color, /* Color32::from_rgb(0, 255, 255) */
&mut job,
appearance.code_font.clone(),
);
write_text("c", appearance.replace_color, &mut job, appearance.code_font.clone());
} else if symbol.flags.0.contains(ObjSymbolFlags::Global) {
write_text("g", appearance.insert_color, &mut job, appearance.code_font.clone());
} else if symbol.flags.0.contains(ObjSymbolFlags::Local) {
@@ -130,22 +178,23 @@ fn symbol_ui(
if response.clicked() {
if let Some(section) = section {
if section.kind == ObjSectionKind::Code {
*selected_symbol = Some(SymbolReference {
state.selected_symbol = Some(SymbolReference {
symbol_name: symbol.name.clone(),
section_name: section.name.clone(),
});
*current_view = View::FunctionDiff;
ret = Some(View::FunctionDiff);
} else if section.kind == ObjSectionKind::Data {
*selected_symbol = Some(SymbolReference {
state.selected_symbol = Some(SymbolReference {
symbol_name: section.name.clone(),
section_name: section.name.clone(),
});
*current_view = View::DataDiff;
ret = Some(View::DataDiff);
}
}
} else if response.hovered() {
*highlighted_symbol = Some(symbol.name.clone());
state.highlighted_symbol = Some(symbol.name.clone());
}
ret
}
fn symbol_matches_search(symbol: &ObjSymbol, search_str: &str) -> bool {
@@ -158,16 +207,15 @@ fn symbol_matches_search(symbol: &ObjSymbol, search_str: &str) -> bool {
.unwrap_or(false)
}
#[allow(clippy::too_many_arguments)]
#[must_use]
fn symbol_list_ui(
ui: &mut Ui,
obj: &ObjInfo,
highlighted_symbol: &mut Option<String>,
selected_symbol: &mut Option<SymbolReference>,
current_view: &mut View,
state: &mut SymbolViewState,
lower_search: &str,
appearance: &Appearance,
) {
) -> Option<View> {
let mut ret = None;
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
@@ -176,15 +224,7 @@ fn symbol_list_ui(
if !obj.common.is_empty() {
CollapsingHeader::new(".comm").default_open(true).show(ui, |ui| {
for symbol in &obj.common {
symbol_ui(
ui,
symbol,
None,
highlighted_symbol,
selected_symbol,
current_view,
appearance,
);
ret = ret.or(symbol_ui(ui, symbol, None, state, appearance));
}
});
}
@@ -193,41 +233,28 @@ fn symbol_list_ui(
CollapsingHeader::new(format!("{} ({:x})", section.name, section.size))
.default_open(true)
.show(ui, |ui| {
if section.kind == ObjSectionKind::Code && appearance.reverse_fn_order {
if section.kind == ObjSectionKind::Code && state.reverse_fn_order {
for symbol in section.symbols.iter().rev() {
if !symbol_matches_search(symbol, lower_search) {
continue;
}
symbol_ui(
ui,
symbol,
Some(section),
highlighted_symbol,
selected_symbol,
current_view,
appearance,
);
ret =
ret.or(symbol_ui(ui, symbol, Some(section), state, appearance));
}
} else {
for symbol in &section.symbols {
if !symbol_matches_search(symbol, lower_search) {
continue;
}
symbol_ui(
ui,
symbol,
Some(section),
highlighted_symbol,
selected_symbol,
current_view,
appearance,
);
ret =
ret.or(symbol_ui(ui, symbol, Some(section), state, appearance));
}
}
});
}
});
});
ret
}
fn build_log_ui(ui: &mut Ui, status: &BuildStatus, appearance: &Appearance) {
@@ -242,7 +269,7 @@ fn build_log_ui(ui: &mut Ui, status: &BuildStatus, appearance: &Appearance) {
}
pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appearance) {
let DiffViewState { build, current_view, highlighted_symbol, selected_symbol, search } = state;
let DiffViewState { build, current_view, symbol_state, search, .. } = state;
let Some(result) = build else {
return;
};
@@ -295,6 +322,14 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
}
});
ui.add_enabled(
!symbol_state.disable_reverse_fn_order,
egui::Checkbox::new(
&mut symbol_state.reverse_fn_order,
"Reverse function order (-inline deferred)",
),
);
},
);
},
@@ -302,6 +337,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
ui.separator();
// Table
let mut ret = None;
let lower_search = search.to_ascii_lowercase();
StripBuilder::new(ui).size(Size::remainder()).vertical(|mut strip| {
strip.strip(|builder| {
@@ -310,15 +346,13 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
ui.push_id("left", |ui| {
if result.first_status.success {
if let Some(obj) = &result.first_obj {
symbol_list_ui(
ret = ret.or(symbol_list_ui(
ui,
obj,
highlighted_symbol,
selected_symbol,
current_view,
symbol_state,
&lower_search,
appearance,
);
));
}
} else {
build_log_ui(ui, &result.first_status, appearance);
@@ -329,15 +363,13 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
ui.push_id("right", |ui| {
if result.second_status.success {
if let Some(obj) = &result.second_obj {
symbol_list_ui(
ret = ret.or(symbol_list_ui(
ui,
obj,
highlighted_symbol,
selected_symbol,
current_view,
symbol_state,
&lower_search,
appearance,
);
));
}
} else {
build_log_ui(ui, &result.second_status, appearance);
@@ -347,4 +379,8 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
});
});
});
if let Some(view) = ret {
*current_view = view;
}
}