Skip to main content

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