Skip to content

Commit

Permalink
WIP: add cut action for git-revise
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall committed Jul 25, 2024
1 parent f9b62a4 commit e1d1a4e
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions readme/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Most keys can be changed to any printable character or supported special charact
| `inputActionPick` | p | String | Key for setting action to pick |
| `inputActionReword` | r | String | Key for setting action to reword |
| `inputActionSquash` | s | String | Key for setting action to squash |
| `inputActionCut` | x | String | Key for setting action to cut (git-revise) |
| `inputActionIndex` | i | String | Key for setting action to index (git-revise) |
| `inputConfirmNo` | n | String | Key for rejecting a confirmation |
| `inputConfirmYes` | y | String | Key for confirming a confirmation |
Expand Down
3 changes: 3 additions & 0 deletions src/config/key_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub(crate) struct KeyBindings {
pub(crate) abort: Vec<String>,
/// Key bindings for the break action.
pub(crate) action_break: Vec<String>,
/// Key bindings for the cut action.
pub(crate) action_cut: Vec<String>,
/// Key bindings for the drop action.
pub(crate) action_drop: Vec<String>,
/// Key bindings for the edit action.
Expand Down Expand Up @@ -128,6 +130,7 @@ impl KeyBindings {
Ok(Self {
abort: get_input(git_config, "interactive-rebase-tool.inputAbort", "q")?,
action_break: get_input(git_config, "interactive-rebase-tool.inputActionBreak", "b")?,
action_cut: get_input(git_config, "interactive-rebase-tool.inputActionCut", "x")?,
action_drop: get_input(git_config, "interactive-rebase-tool.inputActionDrop", "d")?,
action_edit: get_input(git_config, "interactive-rebase-tool.inputActionEdit", "e")?,
action_fixup: get_input(git_config, "interactive-rebase-tool.inputActionFixup", "f")?,
Expand Down
3 changes: 3 additions & 0 deletions src/config/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub(crate) struct Theme {
pub(crate) character_vertical_spacing: String,
/// The color for the break action.
pub(crate) color_action_break: Color,
/// The color for the cut action.
pub(crate) color_action_cut: Color,
/// The color for the drop action.
pub(crate) color_action_drop: Color,
/// The color for the edit action.
Expand Down Expand Up @@ -85,6 +87,7 @@ impl Theme {
"~",
)?,
color_action_break: get_color(git_config, "interactive-rebase-tool.breakColor", Color::LightWhite)?,
color_action_cut: get_color(git_config, "interactive-rebase-tool.cutColor", Color::DarkRed)?,
color_action_drop: get_color(git_config, "interactive-rebase-tool.dropColor", Color::LightRed)?,
color_action_edit: get_color(git_config, "interactive-rebase-tool.editColor", Color::LightBlue)?,
color_action_exec: get_color(git_config, "interactive-rebase-tool.execColor", Color::LightWhite)?,
Expand Down
10 changes: 10 additions & 0 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::config::Theme;
#[derive(Debug)]
pub(crate) struct Display<T: Tui> {
action_break: (Colors, Colors),
action_cut: (Colors, Colors),
action_drop: (Colors, Colors),
action_edit: (Colors, Colors),
action_exec: (Colors, Colors),
Expand Down Expand Up @@ -78,6 +79,12 @@ impl<T: Tui> Display<T> {
theme.color_background,
theme.color_selected_background,
);
let action_cut = register_selectable_color_pairs(
color_mode,
theme.color_action_cut,
theme.color_background,
theme.color_selected_background,
);
let action_drop = register_selectable_color_pairs(
color_mode,
theme.color_action_drop,
Expand Down Expand Up @@ -183,6 +190,7 @@ impl<T: Tui> Display<T> {

Self {
action_break,
action_cut,
action_drop,
action_edit,
action_exec,
Expand Down Expand Up @@ -244,6 +252,7 @@ impl<T: Tui> Display<T> {
if selected {
match color {
DisplayColor::ActionBreak => self.action_break.1,
DisplayColor::ActionCut => self.action_cut.1,
DisplayColor::ActionDrop => self.action_drop.1,
DisplayColor::ActionEdit => self.action_edit.1,
DisplayColor::ActionExec => self.action_exec.1,
Expand All @@ -268,6 +277,7 @@ impl<T: Tui> Display<T> {
else {
match color {
DisplayColor::ActionBreak => self.action_break.0,
DisplayColor::ActionCut => self.action_cut.0,
DisplayColor::ActionDrop => self.action_drop.0,
DisplayColor::ActionEdit => self.action_edit.0,
DisplayColor::ActionExec => self.action_exec.0,
Expand Down
2 changes: 2 additions & 0 deletions src/display/display_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
pub(crate) enum DisplayColor {
/// The color for the break action.
ActionBreak,
/// The color for the cut action.
ActionCut,
/// The color for the drop action.
ActionDrop,
/// The color for the edit action.
Expand Down
3 changes: 3 additions & 0 deletions src/input/key_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub(crate) struct KeyBindings {
pub(crate) abort: Vec<Event>,
/// Key bindings for the break action.
pub(crate) action_break: Vec<Event>,
/// Key bindings for the cut action.
pub(crate) action_cut: Vec<Event>,
/// Key bindings for the drop action.
pub(crate) action_drop: Vec<Event>,
/// Key bindings for the edit action.
Expand Down Expand Up @@ -123,6 +125,7 @@ impl KeyBindings {
search_previous: map_keybindings(&key_bindings.search_previous),
abort: map_keybindings(&key_bindings.abort),
action_break: map_keybindings(&key_bindings.action_break),
action_cut: map_keybindings(&key_bindings.action_cut),
action_drop: map_keybindings(&key_bindings.action_drop),
action_edit: map_keybindings(&key_bindings.action_edit),
action_fixup: map_keybindings(&key_bindings.action_fixup),
Expand Down
2 changes: 2 additions & 0 deletions src/input/standard_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub(crate) enum StandardEvent {
ForceRebase,
/// The break action meta event.
ActionBreak,
/// The cut (git-revise) action meta event.
ActionCut,
/// The drop action meta event.
ActionDrop,
/// The edit action meta event.
Expand Down
2 changes: 2 additions & 0 deletions src/modules/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ impl List {
match event {
e if key_bindings.abort.contains(&e) => Event::from(StandardEvent::Abort),
e if key_bindings.action_break.contains(&e) => Event::from(StandardEvent::ActionBreak),
e if key_bindings.action_cut.contains(&e) => Event::from(StandardEvent::ActionCut),
e if key_bindings.action_drop.contains(&e) => Event::from(StandardEvent::ActionDrop),
e if key_bindings.action_edit.contains(&e) => Event::from(StandardEvent::ActionEdit),
e if key_bindings.action_fixup.contains(&e) => Event::from(StandardEvent::ActionFixup),
Expand Down Expand Up @@ -643,6 +644,7 @@ impl List {
Event::Standard(standard_event) => {
match standard_event {
StandardEvent::Abort => self.abort(&mut results),
StandardEvent::ActionCut => self.set_selected_line_action(Action::Cut),
StandardEvent::ActionDrop => self.set_selected_line_action(Action::Drop),
StandardEvent::ActionEdit => self.set_selected_line_action(Action::Edit),
StandardEvent::ActionFixup => self.set_selected_line_action(Action::Fixup),
Expand Down
6 changes: 4 additions & 2 deletions src/modules/list/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl Searchable for Search {

let has_hash_match = match action {
Action::Break | Action::Noop | Action::Label | Action::Reset | Action::Merge | Action::Exec => false,
Action::Drop
Action::Cut
| Action::Drop
| Action::Edit
| Action::Fixup
| Action::Index
Expand All @@ -70,7 +71,8 @@ impl Searchable for Search {
};
let has_content_match = match action {
Action::Break | Action::Noop => false,
Action::Drop
Action::Cut
| Action::Drop
| Action::Edit
| Action::Fixup
| Action::Index
Expand Down
2 changes: 2 additions & 0 deletions src/modules/list/tests/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn normal_mode_help() {
" s |Set selected commits to be squashed",
" f |Set selected commits to be fixed-up",
" d |Set selected commits to be dropped",
" x |Set selected commits to be cut / split (git-revise)",
" i |Set selected commits to be staged in the index (git-revise)",
" E |Edit an exec, label, reset or merge action's content",
" I |Insert a new line",
Expand Down Expand Up @@ -106,6 +107,7 @@ fn visual_mode_help() {
" s |Set selected commits to be squashed",
" f |Set selected commits to be fixed-up",
" d |Set selected commits to be dropped",
" x |Set selected commits to be cut / split (git-revise)",
" i |Set selected commits to be staged in the index (git-revise)",
" Delete |Completely remove the selected lines",
" Controlz|Undo the last change",
Expand Down
10 changes: 8 additions & 2 deletions src/modules/list/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ fn build_help_lines(key_bindings: &KeyBindings, selector: HelpLinesSelector) ->
"Set selected commits to be dropped",
HelpLinesSelector::Common,
),
(
&key_bindings.action_cut,
"Set selected commits to be cut / split (git-revise)",
HelpLinesSelector::Common,
),
(
&key_bindings.action_index,
"Set selected commits to be staged in the index (git-revise)",
Expand Down Expand Up @@ -190,6 +195,7 @@ pub(super) fn get_list_visual_mode_help_lines(key_bindings: &KeyBindings) -> Vec
const fn get_action_color(action: Action) -> DisplayColor {
match action {
Action::Break => DisplayColor::ActionBreak,
Action::Cut => DisplayColor::ActionCut,
Action::Drop => DisplayColor::ActionDrop,
Action::Edit => DisplayColor::ActionEdit,
Action::Exec => DisplayColor::ActionExec,
Expand All @@ -214,7 +220,7 @@ pub(super) fn get_line_action_maximum_width(todo_file: &TodoFile) -> usize {
let action_length = match line.get_action() {
// allow these to overflow their bounds
&Action::Exec | &Action::UpdateRef => 0,
&Action::Drop | &Action::Edit | &Action::Noop | &Action::Pick => 4,
&Action::Cut | &Action::Drop | &Action::Edit | &Action::Noop | &Action::Pick => 4,
&Action::Break | &Action::Label | &Action::Reset | &Action::Merge | &Action::Index => 5,
&Action::Fixup => {
if line.option().is_some() {
Expand Down Expand Up @@ -303,7 +309,7 @@ pub(super) fn get_todo_line_segments(

// render hash
match *action {
Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
Action::Cut | Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
let action_width = if is_full_width { 8 } else { 3 };
let max_index = cmp::min(line.get_hash().len(), action_width);
let search_hash_match = search_match.map_or(false, |m| m.hash());
Expand Down
3 changes: 2 additions & 1 deletion src/todo_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ impl TodoFile {

match *action {
Action::Break | Action::Noop => {},
Action::Drop
Action::Cut
| Action::Drop
| Action::Fixup
| Action::Edit
| Action::Index
Expand Down
6 changes: 5 additions & 1 deletion src/todo_file/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::todo_file::ParseError;
pub(crate) enum Action {
/// A break action.
Break,
/// A cut action for git-revise.
Cut,
/// A drop action.
Drop,
/// An edit action.
Expand Down Expand Up @@ -43,6 +45,7 @@ impl Action {
String::from(match self {
Self::Break => "b",
Self::Drop => "d",
Self::Cut => "c",
Self::Edit => "e",
Self::Exec => "x",
Self::Fixup => "f",
Expand All @@ -63,7 +66,7 @@ impl Action {
pub(crate) const fn is_static(self) -> bool {
match self {
Self::Break | Self::Exec | Self::Noop | Self::Reset | Self::Label | Self::Merge | Self::UpdateRef => true,
Self::Drop | Self::Edit | Self::Index | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
Self::Cut | Self::Drop | Self::Edit | Self::Index | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
}
}
}
Expand All @@ -72,6 +75,7 @@ impl Display for Action {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match *self {
Self::Break => "break",
Self::Cut => "cut",
Self::Drop => "drop",
Self::Edit => "edit",
Self::Exec => "exec",
Expand Down
5 changes: 3 additions & 2 deletions src/todo_file/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Line {
Ok(match action {
Action::Noop => Self::new_noop(),
Action::Break => Self::new_break(),
Action::Pick | Action::Reword | Action::Edit | Action::Squash | Action::Drop | Action::Index => {
Action::Pick | Action::Reword | Action::Edit | Action::Squash | Action::Drop | Action::Cut | Action::Index => {
Self::new(action, line_parser.next()?, line_parser.take_remaining(), None)
},
Action::Fixup => {
Expand Down Expand Up @@ -192,6 +192,7 @@ impl Line {
match self.action {
Action::Exec | Action::Index | Action::Label | Action::Reset | Action::Merge | Action::UpdateRef => true,
Action::Break
| Action::Cut
| Action::Drop
| Action::Edit
| Action::Fixup
Expand All @@ -212,7 +213,7 @@ impl Line {
#[must_use]
pub(crate) fn to_text(&self) -> String {
match self.action {
Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
Action::Cut | Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
if let Some(opt) = self.option.as_ref() {
format!("{} {opt} {} {}", self.action, self.hash, self.content)
}
Expand Down

0 comments on commit e1d1a4e

Please sign in to comment.