Skip to content

Commit

Permalink
feat: add quit button to config screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Terkwood committed Jun 19, 2022
1 parent 414075e commit 424e2f1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zeditor"
version = "0.1.5"
version = "0.1.6-a"
edition = "2021"

[dependencies]
Expand Down
21 changes: 16 additions & 5 deletions src/config_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use std::{
sync::{Arc, Mutex},
};

use crate::{db::Db, screens::ZeditorScreens};
use crate::{db::Db, msg::Msg, quit::quit_button, replace::ReplaceHits, screens::ZeditorScreens};
use cursive::{
event::Event,
reexports::crossbeam_channel::Sender,
traits::*,
views::{
Button, Dialog, DummyView, LinearLayout, ListView, OnEventView, ScrollView, TextArea,
Expand All @@ -19,7 +20,12 @@ const EXISTING_REPLACE_INPUTS: &str = "existing replace inputs";
const NEW_SEARCH_INPUT: &str = "new search input";
const NEW_REPLACE_INPUT: &str = "new replace input";

pub fn render(siv: &mut Cursive, screens: ZeditorScreens, db: Arc<Mutex<Db>>) {
pub fn render(
siv: &mut Cursive,
screens: ZeditorScreens,
db: Arc<Mutex<Db>>,
replace_s: Sender<Msg<ReplaceHits>>,
) {
siv.set_screen(screens.config);

use cursive::utils::markup::StyledString;
Expand Down Expand Up @@ -81,9 +87,14 @@ pub fn render(siv: &mut Cursive, screens: ZeditorScreens, db: Arc<Mutex<Db>>) {
LinearLayout::horizontal()
.child(inputs_with_header)
.child(DummyView)
.child(Button::new("Home", move |s| {
s.set_screen(screens.home);
})),
.child(
LinearLayout::vertical()
.child(Button::new("Home", move |s| {
s.set_screen(screens.home);
}))
.child(DummyView)
.child(quit_button(replace_s)),
),
)
.title("zeditor"),
);
Expand Down
7 changes: 2 additions & 5 deletions src/home_screen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::msg::Msg;
use crate::quit::quit_button;
use crate::replace::ReplaceHits;
use crate::screens::ZeditorScreens;
use crate::search::{Hit, SearchFiles};
Expand Down Expand Up @@ -68,11 +69,7 @@ pub fn render(
s.set_screen(screens.config);
}))
.child(DummyView)
.child(Button::new("Quit", move |s| {
replace_s2.send(Msg::Quit).expect("send");

Cursive::quit(s)
})),
.child(quit_button(replace_s2)),
)
};

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod db;
mod env;
pub mod home_screen;
pub mod msg;
mod quit;
pub mod replace;
pub mod screens;
pub mod search;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() {
config: siv.add_screen(),
};

config_screen::render(&mut siv, zeditor_screens, db3);
config_screen::render(&mut siv, zeditor_screens, db3, replace_hits_s.clone());

home_screen::render(
&mut siv,
Expand Down
11 changes: 11 additions & 0 deletions src/quit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cursive::{reexports::crossbeam_channel::Sender, views::Button, Cursive};

use crate::{msg::Msg, replace::ReplaceHits};

pub fn quit_button(replace: Sender<Msg<ReplaceHits>>) -> Button {
Button::new("Quit", move |s| {
replace.send(Msg::Quit).expect("send");

Cursive::quit(s)
})
}

0 comments on commit 424e2f1

Please sign in to comment.