bestool_psql/
config.rs

1use std::{collections::HashSet, sync::Arc};
2
3use crate::{column_extractor::ColumnRef, theme::Theme};
4
5pub trait SnippetLookupProvider: Send + Sync {
6	fn lookup(&self, name: &str) -> Option<String>;
7	fn list_names(&self) -> Vec<String> {
8		Vec::new()
9	}
10	fn get_description(&self, name: &str) -> Option<String> {
11		let _ = name;
12		None
13	}
14}
15
16pub type SnippetLookup = Arc<dyn SnippetLookupProvider>;
17
18#[derive(Clone)]
19pub struct Config {
20	/// Syntax highlighting theme
21	pub theme: Theme,
22
23	/// Path to audit database directory
24	pub audit_path: Option<std::path::PathBuf>,
25
26	/// Whether write mode is enabled upon entering the REPL
27	pub write: bool,
28
29	/// Whether to use colours in output
30	pub use_colours: bool,
31
32	/// Whether redaction mode is enabled
33	pub redact_mode: bool,
34
35	/// Set of columns to redact
36	pub redactions: HashSet<ColumnRef>,
37
38	/// Optional provider for custom snippet lookup
39	pub snippet_lookup: Option<SnippetLookup>,
40}
41
42impl std::fmt::Debug for Config {
43	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44		f.debug_struct("Config")
45			.field("theme", &self.theme)
46			.field("audit_path", &self.audit_path)
47			.field("write", &self.write)
48			.field("use_colours", &self.use_colours)
49			.field("redact_mode", &self.redact_mode)
50			.field("redactions", &self.redactions)
51			.field(
52				"snippet_lookup",
53				&self.snippet_lookup.as_ref().map(|_| "<closure>"),
54			)
55			.finish()
56	}
57}
58
59impl Default for Config {
60	fn default() -> Self {
61		Self {
62			theme: Theme::Dark,
63			audit_path: None,
64			write: false,
65			use_colours: true,
66			redact_mode: false,
67			redactions: HashSet::new(),
68			snippet_lookup: None,
69		}
70	}
71}