Skip to content

Commit

Permalink
Merge pull request #94 from acheronfail/next
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail authored Aug 9, 2023
2 parents af906fa + fae1a6c commit 47386e6
Show file tree
Hide file tree
Showing 70 changed files with 1,234 additions and 850 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
include:
- build: pinned
os: ubuntu-latest
# NOTE: clap v4 requires 1.64.0
rust: 1.64.0
# NOTE: ratatui requires 1.65.0
rust: 1.65.0
- build: stable
os: ubuntu-latest
rust: stable
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 0.14.3

- 2b2e896 Merge pull request #93 from a-kenji/chore/move-to-ratatui
- fae1250 update to 1.65.0 for ratatui
- fae1e45 use long path for type to avoid nightly errors
- fae15f4 update DEVELOPMENT_NOTES.md
- fae1791 change : to = to work around type ascription issue
- 3829e96 chore: move from unmaintained tui -> ratatui
- fae1d54 add test for different KeyEventKind variants

# 0.14.2

- fae129b fix some platforms inputting multiple characters
Expand Down
56 changes: 24 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "repgrep"
version = "0.14.2"
version = "0.14.3"
description = "An interactive command line replacer for `ripgrep`."
homepage = "https://github.com/acheronfail/repgrep"
repository = "https://github.com/acheronfail/repgrep"
Expand Down Expand Up @@ -36,7 +36,7 @@ serde = { version = "1.0.118", features = ["derive"] }
serde_derive = "1.0.118"
serde_json = "1.0.61"
tempfile = "3.1.0"
tui = { version = "0.19.0", default-features = false, features = ["crossterm"] }
ratatui = { version = "0.22.0", default-features = false, features = ["crossterm"] }
unicode-width = "0.1.8"

[build-dependencies]
Expand Down
8 changes: 8 additions & 0 deletions DEVELOPMENT_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ The README in this repository is generated from the doc comments in `src/main.rs

Once the doc comments have been updated, run `just readme` to apply the changes to the README.

## Submitting a Pull Request

Some guidelines:

* All development is done on the `next` branch, so please target that for any Pull Request.
* Make sure to run `just fmt` on each commit so formatting is consistent
* Make sure to also use `just test` to ensure each commit passes the tests

## Making a release

Mostly so I don't forget if I come back to this project after a while.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pacman -S repgrep

#### From Source (via Cargo)

**NOTE**: The minimum Rust version required is `1.64.0`.
**NOTE**: The minimum Rust version required is `1.65.0`.

```bash
git clone https://github.com/acheronfail/repgrep/
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
//!
//! ### From Source (via Cargo)
//!
//! **NOTE**: The minimum Rust version required is `1.64.0`.
//! **NOTE**: The minimum Rust version required is `1.65.0`.
//!
//! ```bash
//! git clone https://github.com/acheronfail/repgrep/
Expand Down
44 changes: 32 additions & 12 deletions src/ui/app/app_events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// Event handling for `App`.
use anyhow::Result;
use crossterm::event::{Event, KeyCode, KeyModifiers};
use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers};
use either::Either;
use tui::layout::Rect;
use ratatui::layout::Rect;

use crate::model::Movement;
use crate::rg::de::RgMessageKind;
Expand All @@ -26,7 +26,7 @@ impl App {
Event::Key(key) => {
// We only care about `Press` events. Other events such as `Release` and `Repeat` aren't
// fired on every terminal, and we don't need them anyway.
if !matches!(key.kind, crossterm::event::KeyEventKind::Press) {
if !matches!(key.kind, KeyEventKind::Press) {
return Ok(());
}

Expand Down Expand Up @@ -280,7 +280,7 @@ impl App {

/// Update the UI's indicator position to point to the start of the selected item, and in the case of
/// a match which spans multiple lines and has multiple submatches, the start of the selected submatch.
/// Note that this is also the mechanism which scrolls tui-rs' list interface.
/// Note that this is also the mechanism which scrolls ratatui's list interface.
fn update_indicator(&mut self, term_size: Rect) {
let item_idx = self.list_state.selected_item();
let match_idx = self.list_state.selected_submatch();
Expand Down Expand Up @@ -395,9 +395,9 @@ impl App {

#[cfg(test)]
mod tests {
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use pretty_assertions::assert_eq;
use tui::layout::Rect;
use ratatui::layout::Rect;

use crate::model::Movement;
use crate::rg::de::test_utilities::*;
Expand All @@ -413,8 +413,6 @@ mod tests {
fn app_list_to_match_replace(app: &App) -> Vec<bool> {
app.list
.iter()
// .skip(1)
// .take_while(|i| !matches!(i.kind, RgMessageKind::End))
.filter(|i| matches!(i.kind, RgMessageKind::Match))
.map(|i| i.get_should_replace_all())
.collect::<Vec<bool>>()
Expand Down Expand Up @@ -889,11 +887,18 @@ mod tests {

macro_rules! key {
($code:expr) => {
key!($code, KeyModifiers::empty())
key!($code, modifiers = KeyModifiers::empty())
};
($code:expr, $modifiers:expr) => {
($code:expr, modifiers = $modifiers:expr) => {
Event::Key(KeyEvent::new($code, $modifiers))
};
($code:expr, kind = $kind:expr) => {
Event::Key({
let mut key = KeyEvent::new($code, KeyModifiers::empty());
key.kind = $kind;
key
})
};
}

macro_rules! send_key {
Expand All @@ -912,6 +917,21 @@ mod tests {
};
}

#[test]
fn works_with_other_key_event_kinds() {
let mut app = new_app();

// enter insert mode
send_key_assert!(app, key!(Enter, kind = KeyEventKind::Press), "", 0);
send_key_assert!(app, key!(Enter, kind = KeyEventKind::Repeat), "", 0);
send_key_assert!(app, key!(Enter, kind = KeyEventKind::Release), "", 0);

// insert text
send_key_assert!(app, key!(Char('a'), kind = KeyEventKind::Press), "a", 1);
send_key_assert!(app, key!(Char('a'), kind = KeyEventKind::Repeat), "a", 1);
send_key_assert!(app, key!(Char('a'), kind = KeyEventKind::Release), "a", 1);
}

#[test]
fn input_replacement() {
let mut app = new_app();
Expand Down Expand Up @@ -986,7 +1006,7 @@ mod tests {
send_key_assert!(app, key!(PageDown), "repgrep", 7);

// move to next mode
send_key!(app, key!(Char('s'), KeyModifiers::CONTROL));
send_key!(app, key!(Char('s'), modifiers = KeyModifiers::CONTROL));
assert_eq!(
app.ui_state,
AppUiState::ConfirmReplacement("repgrep".into(), 7)
Expand All @@ -995,7 +1015,7 @@ mod tests {
// move back and check pos
send_key_assert!(app, key!(Esc), "repgrep", 7);
send_key_assert!(app, key!(Left), "repgrep", 6);
send_key!(app, key!(Char('s'), KeyModifiers::CONTROL));
send_key!(app, key!(Char('s'), modifiers = KeyModifiers::CONTROL));
assert_eq!(
app.ui_state,
AppUiState::ConfirmReplacement("repgrep".into(), 6)
Expand Down
22 changes: 11 additions & 11 deletions src/ui/app/app_render.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// Rendering for `App`.
use clap::crate_name;
use const_format::formatcp;
use tui::backend::Backend;
use tui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Spans, Text};
use tui::widgets::{Block, Borders, List, ListItem, Paragraph, Row, Table, Wrap};
use tui::Frame;
use ratatui::backend::Backend;
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, Borders, List, ListItem, Paragraph, Row, Table, Wrap};
use ratatui::Frame;

use crate::model::Printable;
use crate::rg::de::RgMessageKind;
Expand Down Expand Up @@ -61,7 +61,7 @@ impl App {
.constraints([Constraint::Length(1), Constraint::Length(1)].as_ref())
.split(root_split[1]);

(root_split, stats_and_input_split)
(root_split.to_vec(), stats_and_input_split.to_vec())
}

pub(crate) fn is_frame_too_small(&self, frame: Rect) -> bool {
Expand Down Expand Up @@ -101,7 +101,7 @@ impl App {
)],
};

let mut render_input = |spans| f.render_widget(Paragraph::new(Spans::from(spans)), r);
let mut render_input = |spans| f.render_widget(Paragraph::new(Line::from(spans)), r);

// Draw input cursor after rendering input
if let AppUiState::InputReplacement(input, _) = &self.ui_state {
Expand Down Expand Up @@ -144,8 +144,8 @@ impl App {
.constraints([Constraint::Length(10), Constraint::Min(1)].as_ref())
.split(r);

let left_side_items = vec![Spans::from(self.ui_state.to_span())];
let right_side_items = vec![Spans::from(vec![
let left_side_items = vec![Line::from(self.ui_state.to_span())];
let right_side_items = vec![Line::from(vec![
Span::styled(
format!(" {} ", self.rg_cmdline),
Style::default().bg(Color::Blue).fg(Color::Black),
Expand Down Expand Up @@ -235,7 +235,7 @@ impl App {

let help_title = Span::styled(format!("{} help", crate_name!()), title_style);
let help_text = self.help_text_state.text(hsplit[0].height as usize);
let help_text = Text::from(help_text.as_ref());
let help_text = Text::from(help_text.as_str());
let help_paragraph = Paragraph::new(help_text)
.wrap(Wrap { trim: false })
.block(Block::default().borders(Borders::ALL).title(help_title));
Expand Down
6 changes: 3 additions & 3 deletions src/ui/app/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tui::style::{Color, Style};
use tui::text::Span;
use tui::widgets::ListState;
use ratatui::style::{Color, Style};
use ratatui::text::Span;
use ratatui::widgets::ListState;

#[derive(Debug)]
pub struct AppListState {
Expand Down
Loading

0 comments on commit 47386e6

Please sign in to comment.