Skip to content

Commit 8d305d0

Browse files
TimelordUKclaude
andcommitted
feat: major TUI improvements with clipboard, cell mode, and configuration system
This commit introduces significant enhancements to the TUI application: Clipboard functionality: - Vim-like yank operations (y, yy, yc, ya) for copying data - Cross-platform clipboard support using arboard crate - Copy cells, rows, columns, or all filtered data - Status line shows last yanked content Cell mode vs Row mode: - Toggle between cell and row selection with 'v' key - Cell mode for copying individual values (e.g., trade IDs) - Row mode for traditional record-based operations - Visual highlighting adapts to current mode - Yellow foreground highlighting for better readability on dark themes Configuration system: - TOML-based configuration file support - Configurable glyph vs ASCII mode for better compatibility - Theme customization including cell selection styling - Behavior settings (auto-execute, case sensitivity, etc.) - Keybinding configuration support UI improvements: - Cleaner, mode-specific status line - Shows pinned column count in status - Removed clutter from navigation mode - Better visual feedback for current operation Buffer system design: - Architecture for multi-file support (not yet integrated) - Independent state preservation per buffer - Tab-based interface preparation Documentation: - Added CELL_MODE.md explaining selection modes - Added CONFIG.md with configuration details - Added BUFFER_DESIGN.md outlining buffer architecture These changes optimize the tool for professional technical workflows, particularly for copying identifiers between systems and working with multiple data sources. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d8a246a commit 8d305d0

10 files changed

Lines changed: 2140 additions & 253 deletions

File tree

sql-cli/BUFFER_DESIGN.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Buffer System Design for SQL CLI
2+
3+
## Overview
4+
5+
The buffer system allows multiple files to be loaded simultaneously, with each maintaining its own independent state. This is similar to vim's buffer system or browser tabs.
6+
7+
## Key Features
8+
9+
### 1. Independent State Per Buffer
10+
Each buffer maintains:
11+
- Loaded data (CSV/JSON)
12+
- Current SQL query
13+
- All filters and searches
14+
- Cursor position and scroll state
15+
- Sort order
16+
- Column pins
17+
- View preferences (compact mode, row numbers, etc.)
18+
19+
### 2. Quick Switching
20+
Switch between buffers without losing any state:
21+
- Your position in the data
22+
- Active filters
23+
- Current query
24+
- Everything is preserved
25+
26+
## Keybindings
27+
28+
### Buffer Navigation (Vim-style)
29+
- `gt` or `Ctrl+Tab` - Next buffer
30+
- `gT` or `Ctrl+Shift+Tab` - Previous buffer
31+
- `{n}gt` - Go to buffer n (e.g., `2gt` for second buffer)
32+
- `Alt+1` through `Alt+9` - Quick jump to buffer 1-9
33+
34+
### Buffer Management
35+
- `:e filename.csv` - Open file in new buffer
36+
- `:edit filename.json` - Same as :e
37+
- `:bd` or `:bdelete` - Close current buffer
38+
- `:ls` or `:buffers` - List all open buffers
39+
- `:b {n}` or `:buffer {n}` - Switch to buffer n
40+
- `:bn` or `:bnext` - Next buffer
41+
- `:bp` or `:bprev` - Previous buffer
42+
43+
## Visual Design
44+
45+
### Tab Bar
46+
```
47+
┌─────────────────────────────────────────────────────┐
48+
│ [1:trades.csv] [2:products.json*] [3:customers.csv] │
49+
├─────────────────────────────────────────────────────┤
50+
│ SELECT * FROM products WHERE price > 100 │
51+
└─────────────────────────────────────────────────────┘
52+
```
53+
54+
- Current buffer is highlighted
55+
- `*` indicates modified/filtered state
56+
- Number prefix for quick jumping
57+
58+
### Status Line Addition
59+
```
60+
[NAV] Row 45/1000 | 📁 FILE | Buffer 2/3 | Enter:Run
61+
```
62+
63+
## Implementation Strategy
64+
65+
### Phase 1: Basic Buffer Support
66+
1. Extract current state into Buffer struct
67+
2. Add BufferManager to handle multiple buffers
68+
3. Implement basic switching (gt/gT)
69+
70+
### Phase 2: File Operations
71+
1. Add :e command to open files
72+
2. Implement :bd to close buffers
73+
3. Add duplicate file detection
74+
75+
### Phase 3: Visual Polish
76+
1. Add tab bar widget
77+
2. Show buffer indicators in status line
78+
3. Add buffer list view (:ls)
79+
80+
## Use Cases
81+
82+
### Comparing Data
83+
```
84+
1. Load trades.csv
85+
2. Filter to specific date range
86+
3. :e reference_data.csv
87+
4. Search for specific values
88+
5. gt to switch back to trades
89+
6. Your filter is still active!
90+
```
91+
92+
### Multi-File Analysis
93+
```
94+
1. Open main dataset
95+
2. :e lookup_table.csv for reference
96+
3. :e config.json for settings
97+
4. Use Alt+1, Alt+2, Alt+3 to quickly jump between them
98+
```
99+
100+
## Benefits
101+
102+
1. **No Context Loss** - Each file keeps its state
103+
2. **Quick Comparison** - Rapidly switch between datasets
104+
3. **Familiar Interface** - Vim users will feel at home
105+
4. **Efficient Workflow** - No need to restart for new files
106+
107+
## Technical Considerations
108+
109+
### Memory Management
110+
- Each buffer holds its own data copy
111+
- Consider max buffer limit for large files
112+
- Lazy loading possible for unused buffers
113+
114+
### State Preservation
115+
- All UI state moves into Buffer struct
116+
- App becomes primarily a buffer manager
117+
- Clean separation of concerns
118+
119+
### Ratatui Compatibility
120+
- Fully compatible with ratatui's architecture
121+
- Tab bar is just another widget
122+
- State management remains straightforward
123+
124+
## Future Enhancements
125+
126+
### Advanced Features (Not Initial Scope)
127+
- Split panes (view 2 buffers side by side)
128+
- Buffer groups/sessions
129+
- Save/restore buffer sessions
130+
- Quick buffer switching with fuzzy finder
131+
132+
### Integration Ideas
133+
- Open query results in new buffer
134+
- Compare buffers with diff view
135+
- Transfer filters between buffers
136+
- Linked scrolling for comparison
137+
138+
## Command Examples
139+
140+
```sql
141+
-- In buffer 1 (trades.csv)
142+
SELECT * FROM trades WHERE date > '2024-01-01'
143+
144+
-- User presses :e products.csv
145+
-- Now in buffer 2 (products.csv)
146+
SELECT * FROM products
147+
148+
-- User presses gt
149+
-- Back in buffer 1, filter still active
150+
151+
-- User types :ls
152+
-- Output:
153+
1: trades.csv (filtered)
154+
2: products.csv
155+
3: customers.csv
156+
157+
-- User types :b3
158+
-- Switches to customers.csv
159+
```
160+
161+
This design keeps the tool focused on its core purpose (simple SQL queries over flat files) while adding powerful multi-file capabilities that don't complicate the interface.

sql-cli/CELL_MODE.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Cell Mode vs Row Mode
2+
3+
SQL CLI now supports two selection modes, similar to csvlens, optimized for different workflows.
4+
5+
## Quick Start
6+
7+
Press `v` to toggle between Cell and Row mode.
8+
9+
## Cell Mode
10+
11+
**Purpose**: Focus on individual cell values, perfect for copying IDs or specific values to other systems.
12+
13+
### Visual Indicators
14+
- Only the selected cell is highlighted
15+
- Status line shows `[CELL]` mode indicator
16+
- Current cell value displayed in status line
17+
- Cell highlighted with yellow text, bold and underlined (by default)
18+
19+
### Key Behaviors
20+
- `y` - Instantly yanks the current cell value
21+
- Navigation moves cell by cell
22+
- Clear visual focus on exactly what will be copied
23+
24+
### Status Line Example
25+
```
26+
[NAV] [CELL] Row 45/1000 | Col: platformOrderId = TRD-2024-0042 | Yanked: dealId=DEAL-789
27+
```
28+
29+
## Row Mode (Default)
30+
31+
**Purpose**: Traditional row-based selection for working with entire records.
32+
33+
### Visual Indicators
34+
- Entire row is highlighted with dark gray background
35+
- Status line shows `[ROW]` mode indicator
36+
- Row selection arrow `` shows current row
37+
38+
### Key Behaviors
39+
- `y` - Enters yank mode (yy for row, yc for column, ya for all)
40+
- Navigation moves row by row
41+
- Column highlighting shows current field
42+
43+
## Customizing Cell Highlighting
44+
45+
The cell highlighting style can be customized in your config file to work better with your terminal color scheme.
46+
47+
### Default Style (Yellow Foreground)
48+
```toml
49+
[theme.cell_selection_style]
50+
foreground = "yellow"
51+
use_background = false
52+
bold = true
53+
underline = true
54+
```
55+
56+
### Alternative Styles
57+
58+
#### Orange/Amber for Gruvbox
59+
```toml
60+
[theme.cell_selection_style]
61+
foreground = "yellow" # Often renders as orange in Gruvbox
62+
use_background = false
63+
bold = true
64+
underline = false # Less visual noise
65+
```
66+
67+
#### High Contrast
68+
```toml
69+
[theme.cell_selection_style]
70+
foreground = "black"
71+
use_background = true
72+
background = "yellow"
73+
bold = true
74+
underline = false
75+
```
76+
77+
#### Subtle Style
78+
```toml
79+
[theme.cell_selection_style]
80+
foreground = "cyan"
81+
use_background = false
82+
bold = false
83+
underline = true
84+
```
85+
86+
#### Minimal
87+
```toml
88+
[theme.cell_selection_style]
89+
foreground = "white"
90+
use_background = false
91+
bold = true
92+
underline = false
93+
```
94+
95+
## Color Options
96+
97+
Available colors for `foreground` and `background`:
98+
- `"black"`
99+
- `"red"`
100+
- `"green"`
101+
- `"yellow"` (often orange in many themes)
102+
- `"blue"`
103+
- `"magenta"`
104+
- `"cyan"`
105+
- `"white"`
106+
- `"gray"` / `"grey"`
107+
- `"dark_gray"` / `"dark_grey"`
108+
109+
## Use Cases
110+
111+
### Cell Mode - Copying IDs
112+
1. Load trades data
113+
2. Press `v` to enter cell mode
114+
3. Navigate to the `tradeId` column
115+
4. Press `y` to copy just that ID
116+
5. Paste into another application
117+
118+
### Row Mode - Analyzing Records
119+
1. Load data (default row mode)
120+
2. Navigate through records
121+
3. Press `yy` to copy entire row
122+
4. Or press `yc` to copy entire column
123+
124+
## Tips
125+
126+
1. **Quick ID Copy**: In cell mode, `y` immediately copies - no need for `yy`
127+
2. **Visual Clarity**: The highlighting makes it crystal clear what will be yanked
128+
3. **Status Feedback**: Always shows what was last yanked
129+
4. **Terminal Compatibility**: If colors are hard to read, customize the style in your config
130+
131+
## Troubleshooting
132+
133+
### Cell Highlighting Hard to Read?
134+
135+
If the default yellow text is hard to read on your color scheme:
136+
137+
1. Generate a config file if you don't have one:
138+
```bash
139+
sql-cli --generate-config
140+
```
141+
142+
2. Edit `~/.config/sql-cli/config.toml` (Linux/Mac) or `%APPDATA%\sql-cli\config.toml` (Windows)
143+
144+
3. Try different color combinations:
145+
- For dark themes: `foreground = "cyan"` or `foreground = "magenta"`
146+
- For light themes: `foreground = "blue"` or `foreground = "red"`
147+
- Disable underline if it's too busy: `underline = false`
148+
149+
4. Restart SQL CLI to apply changes

0 commit comments

Comments
 (0)