5 releases (3 breaking)
| 0.4.0 | Dec 18, 2025 |
|---|---|
| 0.3.1 | Dec 16, 2025 |
| 0.3.0 | Dec 14, 2025 |
| 0.2.0 | Dec 14, 2025 |
| 0.1.0 | Dec 13, 2025 |
#1415 in Command-line interface
Used in tsql
33KB
954 lines
tui-syntax
Tree-sitter based syntax highlighting for TUI applications.
This crate provides syntax highlighting that integrates with ratatui,
returning styled Line and Span types ready for rendering.
Features
- Tree-sitter based highlighting (accurate, fast)
- Helix-compatible TOML theme format
- Built-in themes (One Dark, GitHub Light)
- SQL language support built-in
- Extensible to other languages via tree-sitter grammars
Example
use tui_syntax::{Highlighter, themes, sql};
// Create highlighter with default dark theme
let mut highlighter = Highlighter::new(themes::one_dark());
// Register SQL language
highlighter.register_language(sql()).unwrap();
// Highlight some SQL
let lines = highlighter.highlight("sql", "SELECT * FROM users WHERE id = 1;").unwrap();
// `lines` is Vec<ratatui::text::Line> ready to render
tsql
A modern, keyboard-first PostgreSQL CLI with a TUI interface.
If you like this crate show some support by following fcoury (me) on X

Features
- Full-screen TUI - Split-pane interface with query editor and results grid
- Vim-style keybindings - Navigate and edit with familiar modal commands
- Syntax highlighting - SQL and JSON highlighting powered by tree-sitter
- Smart completion - Schema-aware autocomplete for tables, columns, and keywords
- Results grid - Scrollable, searchable data grid with column resizing
- Inline editing - Edit cells directly in the grid with automatic SQL generation
- JSON support - Detect, format, and edit JSON/JSONB columns with syntax highlighting
- psql compatibility - Familiar commands like
\dt,\d,\dn,\l, and more - Query history - Persistent history with fuzzy search
- Configurable - Customize keybindings and appearance via config file
Installation
Homebrew (macOS/Linux)
brew tap fcoury/tap
brew install tsql
Cargo (from source)
cargo install tsql
Binary Download
Download pre-built binaries from the GitHub Releases page.
Quick Start
# Connect with a connection URL
tsql postgres://user:password@localhost:5432/mydb
# Or set DATABASE_URL environment variable
export DATABASE_URL=postgres://user:password@localhost:5432/mydb
tsql
# Or configure a default connection in ~/.config/tsql/config.toml
tsql
Once connected:
- Type a SQL query in the editor pane
- Press
Enterto execute - Use
Tabto switch between editor and results grid - Press
?for help with all keybindings
Keybindings
Global
| Key | Action |
|---|---|
Tab |
Switch focus between query editor and results grid |
? |
Toggle help popup |
Ctrl+Shift+B / Ctrl+\ / Ctrl+4 |
Toggle sidebar |
q |
Quit application |
Esc |
Return to normal mode / close popups |
Query Editor (Normal Mode)
| Key | Action |
|---|---|
h/j/k/l |
Move cursor |
i/a/I/A |
Enter insert mode |
o/O |
Open line below/above |
dd |
Delete line |
yy |
Yank (copy) line |
p/P |
Paste after/before |
u |
Undo |
Ctrl-r |
Redo |
/ |
Search |
Enter |
Execute query |
: |
Command mode |
Results Grid
| Key | Action |
|---|---|
h/j/k/l |
Navigate cells |
H/L |
Scroll horizontally |
gg/G |
First/last row |
Space |
Toggle row selection |
y |
Copy row |
c |
Copy cell |
e |
Edit cell |
/ |
Search in results |
+/- |
Widen/narrow column |
= |
Fit/collapse column |
Troubleshooting keybindings
If a key combo isn't working in your terminal, you can inspect what tsql is actually receiving:
tsql --debug-keys
To also print mouse events:
tsql --debug-keys --mouse
Commands
| Command | Description |
|---|---|
:connect <url> |
Connect to database |
:disconnect |
Disconnect |
:export csv|json|tsv <path> |
Export results |
:q / :quit |
Quit |
:\dt |
List tables |
:\d <table> |
Describe table |
:\dn |
List schemas |
:\di |
List indexes |
:\l |
List databases |
:\du |
List roles |
Configuration
tsql looks for configuration at ~/.config/tsql/config.toml.
[connection]
# Default connection URL (can be overridden by CLI arg or DATABASE_URL)
default_url = "postgres://localhost/mydb"
[keybindings]
# Custom keybindings (see config.example.toml for options)
See config.example.toml for all available options.
Requirements
- PostgreSQL 12 or later
- Terminal with 256-color support recommended
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~28–43MB
~1M SLoC