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