diff --git a/README.md b/README.md index 93aec45..6e290ca 100644 --- a/README.md +++ b/README.md @@ -269,3 +269,15 @@ The FlightSQL config is where you can define the connection URL for the FlightSQ [flight_sql] connection_url = "http://localhost:50051" ``` + +#### Editor Config + +The editor config is where you can set your preferred editor settings. + +Currently only syntax highlighting is supported. It is experimental because currently the regex that is used to determine keywords only works in simple cases. + +```toml +[editor] +experimental_syntax_highlighting = true +``` + diff --git a/src/app/handlers/flightsql.rs b/src/app/handlers/flightsql.rs index a759e5d..c849e12 100644 --- a/src/app/handlers/flightsql.rs +++ b/src/app/handlers/flightsql.rs @@ -37,7 +37,7 @@ pub fn normal_mode_handler(app: &mut App, key: KeyEvent) { | KeyCode::Char('3') | KeyCode::Char('4') | KeyCode::Char('5')) => tab_navigation_handler(app, tab), - KeyCode::Char('c') => app.state.flightsql_tab.clear_editor(), + KeyCode::Char('c') => app.state.flightsql_tab.clear_editor(&app.state.config), KeyCode::Char('e') => { info!("Handling"); let editor = app.state.flightsql_tab.editor(); diff --git a/src/app/handlers/sql.rs b/src/app/handlers/sql.rs index 7481a05..4e6fa5f 100644 --- a/src/app/handlers/sql.rs +++ b/src/app/handlers/sql.rs @@ -35,7 +35,7 @@ pub fn normal_mode_handler(app: &mut App, key: KeyEvent) { | KeyCode::Char('3') | KeyCode::Char('4') | KeyCode::Char('5')) => tab_navigation_handler(app, tab), - KeyCode::Char('c') => app.state.sql_tab.clear_editor(), + KeyCode::Char('c') => app.state.sql_tab.clear_editor(&app.state.config), KeyCode::Char('e') => { let editor = app.state.sql_tab.editor(); let lines = editor.lines(); diff --git a/src/app/state/mod.rs b/src/app/state/mod.rs index 92ad00b..1f3723d 100644 --- a/src/app/state/mod.rs +++ b/src/app/state/mod.rs @@ -86,9 +86,9 @@ impl<'app> AppState<'app> { pub fn new(config: AppConfig) -> Self { let tabs = Tabs::default(); - let sql_tab_state = SQLTabState::new(); + let sql_tab_state = SQLTabState::new(&config); #[cfg(feature = "flightsql")] - let flightsql_tab_state = FlightSQLTabState::new(); + let flightsql_tab_state = FlightSQLTabState::new(&config); let logs_tab_state = LogsTabState::default(); let history_tab_state = HistoryTabState::default(); diff --git a/src/app/state/tabs/flightsql.rs b/src/app/state/tabs/flightsql.rs index 74aee20..8ae520f 100644 --- a/src/app/state/tabs/flightsql.rs +++ b/src/app/state/tabs/flightsql.rs @@ -26,6 +26,7 @@ use ratatui::widgets::TableState; use tui_textarea::TextArea; use crate::app::state::tabs::sql; +use crate::config::AppConfig; use crate::execution::ExecutionStats; #[derive(Clone, Debug)] @@ -111,13 +112,15 @@ pub struct FlightSQLTabState<'app> { } impl<'app> FlightSQLTabState<'app> { - pub fn new() -> Self { + pub fn new(config: &AppConfig) -> Self { let empty_text = vec!["Enter a query here.".to_string()]; // TODO: Enable vim mode from config? let mut textarea = TextArea::new(empty_text); textarea.set_style(Style::default().fg(tailwind::WHITE)); - textarea.set_search_pattern(sql::keyword_regex()).unwrap(); - textarea.set_search_style(sql::keyword_style()); + if config.editor.experimental_syntax_highlighting { + textarea.set_search_pattern(sql::keyword_regex()).unwrap(); + textarea.set_search_style(sql::keyword_style()); + }; Self { editor: textarea, editor_editable: false, @@ -151,11 +154,13 @@ impl<'app> FlightSQLTabState<'app> { } } - pub fn clear_editor(&mut self) { + pub fn clear_editor(&mut self, config: &AppConfig) { let mut textarea = TextArea::new(vec!["".to_string()]); textarea.set_style(Style::default().fg(tailwind::WHITE)); - textarea.set_search_pattern(sql::keyword_regex()).unwrap(); - textarea.set_search_style(sql::keyword_style()); + if config.editor.experimental_syntax_highlighting { + textarea.set_search_pattern(sql::keyword_regex()).unwrap(); + textarea.set_search_style(sql::keyword_style()); + }; self.editor = textarea; } diff --git a/src/app/state/tabs/sql.rs b/src/app/state/tabs/sql.rs index d4cafc1..8b4c35c 100644 --- a/src/app/state/tabs/sql.rs +++ b/src/app/state/tabs/sql.rs @@ -26,6 +26,7 @@ use ratatui::style::{Modifier, Style}; use ratatui::widgets::TableState; use tui_textarea::TextArea; +use crate::config::AppConfig; use crate::execution::ExecutionStats; #[derive(Clone, Debug)] @@ -132,13 +133,15 @@ pub struct SQLTabState<'app> { } impl<'app> SQLTabState<'app> { - pub fn new() -> Self { + pub fn new(config: &AppConfig) -> Self { let empty_text = vec!["Enter a query here.".to_string()]; // TODO: Enable vim mode from config? let mut textarea = TextArea::new(empty_text); textarea.set_style(Style::default().fg(tailwind::WHITE)); - textarea.set_search_pattern(keyword_regex()).unwrap(); - textarea.set_search_style(keyword_style()); + if config.editor.experimental_syntax_highlighting { + textarea.set_search_pattern(keyword_regex()).unwrap(); + textarea.set_search_style(keyword_style()); + }; Self { editor: textarea, editor_editable: false, @@ -172,11 +175,13 @@ impl<'app> SQLTabState<'app> { } } - pub fn clear_editor(&mut self) { + pub fn clear_editor(&mut self, config: &AppConfig) { let mut textarea = TextArea::new(vec!["".to_string()]); textarea.set_style(Style::default().fg(tailwind::WHITE)); - textarea.set_search_pattern(keyword_regex()).unwrap(); - textarea.set_search_style(keyword_style()); + if config.editor.experimental_syntax_highlighting { + textarea.set_search_pattern(keyword_regex()).unwrap(); + textarea.set_search_style(keyword_style()); + }; self.editor = textarea; } diff --git a/src/config.rs b/src/config.rs index 8f1e3ac..cf2850d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -70,6 +70,7 @@ pub struct AppConfig { #[cfg(feature = "flightsql")] #[serde(default = "default_flightsql_config")] pub flightsql: FlightSQLConfig, + pub editor: EditorConfig, } fn default_execution_config() -> ExecutionConfig { @@ -197,3 +198,8 @@ impl Default for FlightSQLConfig { pub fn default_connection_url() -> String { "http://localhost:50051".to_string() } + +#[derive(Debug, Default, Deserialize)] +pub struct EditorConfig { + pub experimental_syntax_highlighting: bool, +}