Skip to content

Commit

Permalink
Application panics when no target is selected and return key pressed #…
Browse files Browse the repository at this point in the history
…158 (#184)

* fix

* fix

* print

* add target `ci`
  • Loading branch information
kyu08 authored Jan 3, 2024
1 parent 8846d13 commit 7454d28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ RUST_BACKTRACE=full
toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo-long-target2:
@echo "this is toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo-long-target."

.PHONY: ci
ci: # Checks same as CI
RUST_BACKTRACE=full make test; \
make check; \
make spell-check

.PHONY: test
test : # Run unit tests
RUST_BACKTRACE=full cargo nextest run
Expand Down
16 changes: 10 additions & 6 deletions src/usecase/fzf_make/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,25 @@ impl Model<'_> {
}

fn reset_selection(&mut self) {
if self.makefile.to_targets_string().is_empty() {
if self.narrow_down_targets().is_empty() {
self.targets_list_state.select(None);
}
self.targets_list_state.select(Some(0));
}

fn selected_target(&self) -> Option<String> {
self.targets_list_state
.selected()
.map(|i| self.narrow_down_targets()[i].clone())
match self.targets_list_state.selected() {
Some(i) => self.narrow_down_targets().get(i).map(|s| s.to_string()),
None => None,
}
}

pub fn should_quit(&self) -> bool {
self.app_state == AppState::ShouldQuite
}

pub fn is_target_selected(&self) -> bool {
matches!(self.app_state, AppState::ExecuteTarget(Some(_)))
matches!(self.app_state, AppState::ExecuteTarget(_))
}

pub fn target_to_execute(&self) -> Option<String> {
Expand Down Expand Up @@ -211,7 +212,10 @@ pub fn main() -> Result<()> {

Ok(())
}
None => Ok(()),
None => {
println!("{}", ("no target selected.".to_string()).red());
Ok(())
}
}
});

Expand Down

0 comments on commit 7454d28

Please sign in to comment.