feat: add SQL syntax highlighting in query editor

This commit is contained in:
Valdemar Lorenzen
2026-10-19 14:16:04 +02:00
parent 49a3dbddcf
commit dbd4c05cf4
7 changed files with 285 additions and 11 deletions
+15 -10
View File
@@ -1,7 +1,4 @@
use std::{
borrow::Cow,
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use postgres::{Config, config::SslMode};
@@ -9,7 +6,7 @@ use ratatui::{
DefaultTerminal, Frame,
layout::{Constraint, Layout, Rect},
style::{Color, Style},
text::Line,
text::{Line, Text},
widgets::{Block, Clear, List, ListItem, ListState, Paragraph, Wrap},
};
@@ -550,8 +547,14 @@ impl Form {
if self.provider == 1 {
let [path, description] =
Layout::vertical([Constraint::Length(3), Constraint::Min(1)]).areas(details);
self.path
.draw(frame, path, " Database file path ", false, self.focus == 1);
self.path.draw(
frame,
path,
" Database file path ",
false,
self.focus == 1,
None,
);
frame.render_widget(Paragraph::new("Save an existing SQLite file path.\nFiles are never created or modified.\n\nSelect the saved database to connect.").wrap(Wrap { trim: false }), description);
} else {
let rows = Layout::vertical([
@@ -584,6 +587,7 @@ impl Form {
labels[index],
index == 4,
self.focus == index + 1 && (!self.reconnect || index == 4),
None,
);
}
frame.render_widget(
@@ -753,11 +757,12 @@ impl Input {
label: &str,
secret: bool,
focused: bool,
highlighted: Option<Text<'_>>,
) {
let text: Cow<'_, str> = if secret {
Cow::Owned("•".repeat(self.value.chars().count()))
let text = if secret {
Text::raw("•".repeat(self.value.chars().count()))
} else {
Cow::Borrowed(&self.value)
highlighted.unwrap_or_else(|| Text::raw(&self.value))
};
let prefix = &self.value[..self.cursor];
let row = u16::try_from(prefix.matches('\n').count()).unwrap_or(u16::MAX);