Skip to content

Commit 9ff201c

Browse files
Experimental syntax highlighting (#160)
1 parent fbb039f commit 9ff201c

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,15 @@ The FlightSQL config is where you can define the connection URL for the FlightSQ
269269
[flight_sql]
270270
connection_url = "http://localhost:50051"
271271
```
272+
273+
#### Editor Config
274+
275+
The editor config is where you can set your preferred editor settings.
276+
277+
Currently only syntax highlighting is supported. It is experimental because currently the regex that is used to determine keywords only works in simple cases.
278+
279+
```toml
280+
[editor]
281+
experimental_syntax_highlighting = true
282+
```
283+

src/app/handlers/flightsql.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn normal_mode_handler(app: &mut App, key: KeyEvent) {
3737
| KeyCode::Char('3')
3838
| KeyCode::Char('4')
3939
| KeyCode::Char('5')) => tab_navigation_handler(app, tab),
40-
KeyCode::Char('c') => app.state.flightsql_tab.clear_editor(),
40+
KeyCode::Char('c') => app.state.flightsql_tab.clear_editor(&app.state.config),
4141
KeyCode::Char('e') => {
4242
info!("Handling");
4343
let editor = app.state.flightsql_tab.editor();

src/app/handlers/sql.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn normal_mode_handler(app: &mut App, key: KeyEvent) {
3535
| KeyCode::Char('3')
3636
| KeyCode::Char('4')
3737
| KeyCode::Char('5')) => tab_navigation_handler(app, tab),
38-
KeyCode::Char('c') => app.state.sql_tab.clear_editor(),
38+
KeyCode::Char('c') => app.state.sql_tab.clear_editor(&app.state.config),
3939
KeyCode::Char('e') => {
4040
let editor = app.state.sql_tab.editor();
4141
let lines = editor.lines();

src/app/state/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ impl<'app> AppState<'app> {
8686
pub fn new(config: AppConfig) -> Self {
8787
let tabs = Tabs::default();
8888

89-
let sql_tab_state = SQLTabState::new();
89+
let sql_tab_state = SQLTabState::new(&config);
9090
#[cfg(feature = "flightsql")]
91-
let flightsql_tab_state = FlightSQLTabState::new();
91+
let flightsql_tab_state = FlightSQLTabState::new(&config);
9292
let logs_tab_state = LogsTabState::default();
9393
let history_tab_state = HistoryTabState::default();
9494

src/app/state/tabs/flightsql.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ratatui::widgets::TableState;
2626
use tui_textarea::TextArea;
2727

2828
use crate::app::state::tabs::sql;
29+
use crate::config::AppConfig;
2930
use crate::execution::ExecutionStats;
3031

3132
#[derive(Clone, Debug)]
@@ -111,13 +112,15 @@ pub struct FlightSQLTabState<'app> {
111112
}
112113

113114
impl<'app> FlightSQLTabState<'app> {
114-
pub fn new() -> Self {
115+
pub fn new(config: &AppConfig) -> Self {
115116
let empty_text = vec!["Enter a query here.".to_string()];
116117
// TODO: Enable vim mode from config?
117118
let mut textarea = TextArea::new(empty_text);
118119
textarea.set_style(Style::default().fg(tailwind::WHITE));
119-
textarea.set_search_pattern(sql::keyword_regex()).unwrap();
120-
textarea.set_search_style(sql::keyword_style());
120+
if config.editor.experimental_syntax_highlighting {
121+
textarea.set_search_pattern(sql::keyword_regex()).unwrap();
122+
textarea.set_search_style(sql::keyword_style());
123+
};
121124
Self {
122125
editor: textarea,
123126
editor_editable: false,
@@ -151,11 +154,13 @@ impl<'app> FlightSQLTabState<'app> {
151154
}
152155
}
153156

154-
pub fn clear_editor(&mut self) {
157+
pub fn clear_editor(&mut self, config: &AppConfig) {
155158
let mut textarea = TextArea::new(vec!["".to_string()]);
156159
textarea.set_style(Style::default().fg(tailwind::WHITE));
157-
textarea.set_search_pattern(sql::keyword_regex()).unwrap();
158-
textarea.set_search_style(sql::keyword_style());
160+
if config.editor.experimental_syntax_highlighting {
161+
textarea.set_search_pattern(sql::keyword_regex()).unwrap();
162+
textarea.set_search_style(sql::keyword_style());
163+
};
159164
self.editor = textarea;
160165
}
161166

src/app/state/tabs/sql.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ratatui::style::{Modifier, Style};
2626
use ratatui::widgets::TableState;
2727
use tui_textarea::TextArea;
2828

29+
use crate::config::AppConfig;
2930
use crate::execution::ExecutionStats;
3031

3132
#[derive(Clone, Debug)]
@@ -132,13 +133,15 @@ pub struct SQLTabState<'app> {
132133
}
133134

134135
impl<'app> SQLTabState<'app> {
135-
pub fn new() -> Self {
136+
pub fn new(config: &AppConfig) -> Self {
136137
let empty_text = vec!["Enter a query here.".to_string()];
137138
// TODO: Enable vim mode from config?
138139
let mut textarea = TextArea::new(empty_text);
139140
textarea.set_style(Style::default().fg(tailwind::WHITE));
140-
textarea.set_search_pattern(keyword_regex()).unwrap();
141-
textarea.set_search_style(keyword_style());
141+
if config.editor.experimental_syntax_highlighting {
142+
textarea.set_search_pattern(keyword_regex()).unwrap();
143+
textarea.set_search_style(keyword_style());
144+
};
142145
Self {
143146
editor: textarea,
144147
editor_editable: false,
@@ -172,11 +175,13 @@ impl<'app> SQLTabState<'app> {
172175
}
173176
}
174177

175-
pub fn clear_editor(&mut self) {
178+
pub fn clear_editor(&mut self, config: &AppConfig) {
176179
let mut textarea = TextArea::new(vec!["".to_string()]);
177180
textarea.set_style(Style::default().fg(tailwind::WHITE));
178-
textarea.set_search_pattern(keyword_regex()).unwrap();
179-
textarea.set_search_style(keyword_style());
181+
if config.editor.experimental_syntax_highlighting {
182+
textarea.set_search_pattern(keyword_regex()).unwrap();
183+
textarea.set_search_style(keyword_style());
184+
};
180185
self.editor = textarea;
181186
}
182187

src/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub struct AppConfig {
7070
#[cfg(feature = "flightsql")]
7171
#[serde(default = "default_flightsql_config")]
7272
pub flightsql: FlightSQLConfig,
73+
pub editor: EditorConfig,
7374
}
7475

7576
fn default_execution_config() -> ExecutionConfig {
@@ -197,3 +198,8 @@ impl Default for FlightSQLConfig {
197198
pub fn default_connection_url() -> String {
198199
"http://localhost:50051".to_string()
199200
}
201+
202+
#[derive(Debug, Default, Deserialize)]
203+
pub struct EditorConfig {
204+
pub experimental_syntax_highlighting: bool,
205+
}

0 commit comments

Comments
 (0)