Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support Perspective "blanking" #224

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 46 additions & 19 deletions src/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ struct ModuleView {

/// If set, avoid low-constrast colors
high_contrast: bool,

/// if set, values are blanked in cells relating to inactive
/// perspectives.
blank_perspectives: bool,
}
impl ModuleView {
fn from_cs(cs: &ConstraintSet, name: &str, high_contrast: bool) -> ModuleView {
fn from_cs(
cs: &ConstraintSet,
name: &str,
high_contrast: bool,
blank_perspectives: bool,
) -> ModuleView {
let mut max_size = 0;
let columns: Vec<(ColumnRef, Handle)> = cs
.columns
Expand All @@ -72,6 +81,7 @@ impl ModuleView {

last_scan: String::new(),
high_contrast,
blank_perspectives,
}
}

Expand Down Expand Up @@ -178,8 +188,7 @@ impl ModuleView {
.get(column_ref, i, false)
.map(|x| {
let base = cs.columns.column(column_ref).unwrap().base;
let x_str = x.pretty_with_base(base);
maxes[k + 1] = maxes[k + 1].max(x_str.len());
let mut x_str = x.pretty_with_base(base);
// map color to the 231-17 range of readable color
// https://i.stack.imgur.com/KTSQa.png
let hash =
Expand Down Expand Up @@ -211,21 +220,25 @@ impl ModuleView {
} else {
false
};

// Blank out the column if its not in
// an active perspective.
if dim && self.blank_perspectives {
x_str = String::new();
}
// Update column widths
maxes[k + 1] = maxes[k + 1].max(x_str.len());
// render the cell
Cell::from(x_str)
.fg(if dim {
dimmed_value
if dim {
Cell::from(x_str).fg(dimmed_value).bg(Color::Reset)
} else {
let bg_col = if bg_color > 0 {
Color::Indexed(bg_color.wrapping_add(16) % 251)
} else {
corrected_fg_color
})
.bg({
if bg_color > 0 && !dim {
Color::Indexed(bg_color.wrapping_add(16) % 251)
} else {
Color::Reset
}
})
Color::Reset
};
//
Cell::from(x_str).fg(corrected_fg_color).bg(bg_col)
}
})
.unwrap_or(Cell::from("."))
})),
Expand Down Expand Up @@ -257,14 +270,18 @@ struct Inspector<'a> {
message: Span<'a>,
}
impl<'a> Inspector<'a> {
fn from_cs(cs: &'a ConstraintSet, high_contrast: bool) -> Result<Self> {
fn from_cs(
cs: &'a ConstraintSet,
high_contrast: bool,
blank_perspectives: bool,
) -> Result<Self> {
let r = Inspector {
cs,
modules: cs
.columns
.modules()
.iter()
.map(|n| ModuleView::from_cs(cs, n, high_contrast))
.map(|n| ModuleView::from_cs(cs, n, high_contrast, blank_perspectives))
.sorted_by(|m1, m2| m1.name.cmp(&m2.name))
.collect(),
current_module: 0,
Expand Down Expand Up @@ -347,6 +364,9 @@ impl<'a> Inspector<'a> {
// "[p]".yellow().bold(),
// "lookup".into(),
// " :: ".into(),
"[p]".yellow().bold(),
"erspectives".into(),
" :: ".into(),
"[q]".red().bold(),
"uit".into(),
];
Expand Down Expand Up @@ -477,6 +497,11 @@ impl<'a> Inspector<'a> {
let _ = terminal.clear();
}
KeyCode::Char('F') => self.current_module_mut().clear_filter(),
KeyCode::Char('p') => {
let flag = self.current_module().blank_perspectives;
self.current_module_mut().blank_perspectives = !flag;
let _ = terminal.clear();
}
KeyCode::BackTab => {
self.prev();
}
Expand Down Expand Up @@ -530,10 +555,12 @@ impl<'a> Inspector<'a> {
pub(crate) struct InspectorSettings {
pub open_module: Option<String>,
pub high_contrast: bool,
pub blank_perspectives: bool,
}

pub(crate) fn inspect(cs: &ConstraintSet, settings: InspectorSettings) -> Result<()> {
let mut inspector = Inspector::from_cs(cs, settings.high_contrast)?;
let mut inspector =
Inspector::from_cs(cs, settings.high_contrast, settings.blank_perspectives)?;
if let Some(module) = settings.open_module.as_ref() {
inspector.open_module(module);
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ fn main() -> Result<()> {
InspectorSettings {
open_module,
high_contrast,
blank_perspectives: true,
},
)
.with_context(|| format!("while checking {}", tracefile.bright_white().bold()))?;
Expand Down
Loading