Skip to content

Commit e98a129

Browse files
mouse mode setting and flag (#102)
* mouse override flag * update readme * readme * try fix clippy * remove unused import * clippy
1 parent 315fbd2 commit e98a129

File tree

7 files changed

+98
-16
lines changed

7 files changed

+98
-16
lines changed

.config/rainfrog_config.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[settings]
2+
mouse_mode = true
3+
14
[keybindings.Menu]
25
"<Ctrl-c>" = "Quit"
36
"q" = "AbortQuery"

README.md

+62-11
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,23 @@ curl -LSsf https://raw.githubusercontent.com/achristmascarl/rainfrog/main/instal
8989

9090
## usage
9191

92-
all arguments are optional; you will be prompted to provide any missing information.
93-
9492
```sh
95-
rainfrog
93+
Usage: rainfrog [OPTIONS]
94+
95+
Options:
96+
-M, --mouse <MOUSE_MODE> Whether to enable mouse event support. If enabled, your terminal\'s default mouse event handling will not
97+
work. [possible values: true, false]
98+
-u, --url <URL> Full connection URL for the database, e.g. postgres://username:password@localhost:5432/dbname
99+
--username <USERNAME> Username for database connection
100+
--password <PASSWORD> Password for database connection
101+
--host <HOST> Host for database connection (ex. localhost)
102+
--port <PORT> Port for database connection (ex. 5432)
103+
--database <DATABASE> Name of database for connection (ex. postgres)
104+
-h, --help Print help
105+
-V, --version Print version
96106
```
97107

98-
### with individual options
108+
### with connection options
99109

100110
if any options are not provided, you will be prompted to input them.
101111
if you do not provide an input, that option will
@@ -112,7 +122,8 @@ rainfrog \
112122
### with connection url
113123

114124
the `connection_url` must include all the necessary options for connecting
115-
to the database (ex. `postgres://username:password@localhost:5432/postgres`)
125+
to the database (ex. `postgres://username:password@localhost:5432/postgres`).
126+
it will take precedence over all connection options.
116127

117128
```sh
118129
rainfrog --url $(connection_url)
@@ -130,9 +141,41 @@ docker run --platform linux/amd64 -it --rm --name rainfrog \
130141
-e db_name="<db_name>" achristmascarl/rainfrog:latest
131142
```
132143

133-
## keybindings
144+
## customization
145+
146+
rainfrog can be customized by placing a `rainfrog_config.toml` file in
147+
one of the following locations depending on your os, as determined by
148+
the [directories](https://crates.io/crates/directories) crate:
149+
150+
| Platform | Value | Example |
151+
| -------- | ----------------------------------------------------------------------- | ------------------------------------------------------------- |
152+
| Linux | `$XDG_CONFIG_HOME`/`_project_path_` or `$HOME`/.config/`_project_path_` | /home/alice/.config/barapp |
153+
| macOS | `$HOME`/Library/Application Support/`_project_path_` | /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App |
154+
| Windows | `{FOLDERID_LocalAppData}`\\`_project_path_`\\config | C:\Users\Alice\AppData\Local\Foo Corp\Bar App\config |
155+
156+
you can change the default config location by exporting an environment variable.
157+
to make the change permanent, add it to your .zshrc/.bashrc/.\*rc file:
158+
159+
```sh
160+
export RAINFROG_CONFIG=~/.config
161+
```
162+
163+
### settings
164+
165+
right now, the only setting available is whether rainfrog
166+
captures mouse events by default. capturing mouse events
167+
allows you to change focus and scroll using the mouse.
168+
however, your terminal will not handle mouse events like it
169+
normally does (you won't be able to copy by highlighting, for example).
170+
171+
### keybindings
172+
173+
you can customize some of the default keybindings, but not all of
174+
them. to see a list of the ones you can customize, see the default
175+
config file at [.config/rainfrog_config.toml](./.config/rainfrog_config.toml). below
176+
are the default keybindings.
134177

135-
### general
178+
#### general
136179

137180
| keybinding | description |
138181
| ---------------------------- | ----------------------------- |
@@ -145,7 +188,7 @@ docker run --platform linux/amd64 -it --rm --name rainfrog \
145188
| `Shift+Tab` | cycle focus backwards |
146189
| `q`, `Alt+q` in query editor | abort current query |
147190

148-
### menu (list of schemas and tables)
191+
#### menu (list of schemas and tables)
149192

150193
| keybinding | description |
151194
| ---------------------------- | --------------------------------- |
@@ -163,7 +206,7 @@ docker run --platform linux/amd64 -it --rm --name rainfrog \
163206
| `Enter` with selected table | preview table (100 rows) |
164207
| `R` | reload schemas and tables |
165208

166-
### query editor
209+
#### query editor
167210

168211
Keybindings may not behave exactly like Vim. The full list of active Vim keybindings in Rainfrog can be found at [vim.rs](./src/vim.rs).
169212

@@ -197,7 +240,7 @@ Keybindings may not behave exactly like Vim. The full list of active Vim keybind
197240
| `Ctrl+e` | Scroll down |
198241
| `Ctrl+y` | Scroll up |
199242

200-
### query history
243+
#### query history
201244

202245
| keybinding | description |
203246
| ---------- | ----------------------------- |
@@ -209,7 +252,7 @@ Keybindings may not behave exactly like Vim. The full list of active Vim keybind
209252
| `I` | edit selected query in editor |
210253
| `D` | delete all history |
211254

212-
### results
255+
#### results
213256

214257
| keybinding | description |
215258
| ------------------------- | ------------------------------ |
@@ -275,6 +318,8 @@ features
275318

276319
## known issues and limitations
277320

321+
- for x11 and wayland, yanking does not copy to the system clipboard, only
322+
to the query editor's buffer. see <https://github.com/achristmascarl/rainfrog/issues/83>
278323
- in addition to the experience being subpar if the terminal window is too
279324
small, if the terminal window is too large, rainfrog will crash due to the
280325
maximum area of ratatui buffers being `u16::MAX` (65,535). more details in
@@ -293,6 +338,12 @@ features
293338
not currently support mouse events, and menu items cannot be selected using
294339
the mouse
295340

341+
## Contributing
342+
343+
for bug reports and feature requests, please [create an issue](https://github.com/achristmascarl/rainfrog/issues/new/choose).
344+
345+
please read [CONTRIBUTING.md](./CONTRIBUTING.md) before opening issues or creating PRs.
346+
296347
## acknowledgements
297348

298349
- [ratatui](https://github.com/ratatui-org/ratatui) (this project used ratatui's

src/app.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub struct QueryResultsWithMetadata {
7777
}
7878

7979
pub struct App<'a> {
80+
pub mouse_mode_override: Option<bool>,
8081
pub config: Config,
8182
pub components: Components<'static>,
8283
pub should_quit: bool,
@@ -88,7 +89,7 @@ pub struct App<'a> {
8889
}
8990

9091
impl<'a> App<'a> {
91-
pub fn new(connection_opts: PgConnectOptions) -> Result<Self> {
92+
pub fn new(connection_opts: PgConnectOptions, mouse_mode_override: Option<bool>) -> Result<Self> {
9293
let focus = Focus::Menu;
9394
let menu = Menu::new();
9495
let editor = Editor::new();
@@ -103,6 +104,7 @@ impl<'a> App<'a> {
103104
data: Box::new(data),
104105
},
105106
should_quit: false,
107+
mouse_mode_override,
106108
config,
107109
last_tick_key_events: Vec::new(),
108110
last_frame_mouse_event: None,
@@ -137,7 +139,7 @@ impl<'a> App<'a> {
137139
log::info!("{pool:?}");
138140
self.pool = Some(pool);
139141

140-
let mut tui = tui::Tui::new()?;
142+
let mut tui = tui::Tui::new()?.mouse(self.mouse_mode_override.or(self.config.settings.mouse_mode));
141143
tui.enter()?;
142144

143145
self.components.menu.register_action_handler(action_tx.clone())?;

src/cli.rs

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ use crate::utils::version;
77
#[derive(Parser, Debug, Clone)]
88
#[command(author, version = version(), about)]
99
pub struct Cli {
10+
#[arg(
11+
short = 'M',
12+
long = "mouse",
13+
value_name = "MOUSE_MODE",
14+
help = "Whether to enable mouse event support. If enabled, your terminal's default mouse event handling will not work."
15+
)]
16+
pub mouse_mode: Option<bool>,
17+
1018
#[arg(
1119
short = 'u',
1220
long = "url",

src/config.rs

+14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub struct Config {
3131
pub keybindings: KeyBindings,
3232
#[serde(default)]
3333
pub styles: Styles,
34+
#[serde(default)]
35+
pub settings: Settings,
3436
}
3537

3638
impl Config {
@@ -74,6 +76,12 @@ impl Config {
7476
user_styles.entry(style_key.clone()).or_insert_with(|| *style);
7577
}
7678
}
79+
match cfg.settings.mouse_mode {
80+
Some(mouse_mode) => {},
81+
None => {
82+
cfg.settings.mouse_mode = default_config.settings.mouse_mode;
83+
},
84+
};
7785

7886
Ok(cfg)
7987
}
@@ -270,6 +278,11 @@ pub fn parse_key_sequence(raw: &str) -> Result<Vec<KeyEvent>, String> {
270278
sequences.into_iter().map(parse_key_event).collect()
271279
}
272280

281+
#[derive(Clone, Debug, Default, Deref, DerefMut, Deserialize)]
282+
pub struct Settings {
283+
pub mouse_mode: Option<bool>,
284+
}
285+
273286
#[derive(Clone, Debug, Default, Deref, DerefMut)]
274287
pub struct Styles(pub HashMap<Focus, HashMap<String, Style>>);
275288

@@ -446,6 +459,7 @@ mod tests {
446459
c.keybindings.get(&Focus::Menu).unwrap().get(&parse_key_sequence("<q>").unwrap_or_default()).unwrap(),
447460
&Action::AbortQuery
448461
);
462+
assert_eq!(c.settings.mouse_mode, Some(true));
449463
Ok(())
450464
}
451465

src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(dead_code)]
22
#![allow(unused_imports)]
33
#![allow(unused_variables)]
4+
// for some reason, clippy thinks the tokio::main fn has a needless return...
5+
#![allow(clippy::needless_return)]
46

57
pub mod action;
68
pub mod app;
@@ -36,7 +38,7 @@ async fn tokio_main() -> Result<()> {
3638

3739
let args = Cli::parse();
3840
let connection_opts = build_connection_opts(args.clone())?;
39-
let mut app = App::new(connection_opts)?;
41+
let mut app = App::new(connection_opts, args.mouse_mode)?;
4042
app.run().await?;
4143

4244
Ok(())

src/tui.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ impl Tui {
8282
self
8383
}
8484

85-
pub fn mouse(mut self, mouse: bool) -> Self {
86-
self.mouse = mouse;
85+
pub fn mouse(mut self, mouse: Option<bool>) -> Self {
86+
if mouse.is_some() {
87+
self.mouse = mouse.unwrap();
88+
}
8789
self
8890
}
8991

0 commit comments

Comments
 (0)