aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-07-19 06:25:52 +0100
committerAkshay <[email protected]>2020-07-19 06:25:52 +0100
commite46a6819b5f6a83ae81b3484369d2072c7f09d35 (patch)
tree2ab58c7c0ac8fb28e0982a8d45a711403d6b6890
parent6efda9445a89ccbe30aff30f846119129bf3e53c (diff)
improve command mode positioning/ux
-rw-r--r--src/app/impl_self.rs4
-rw-r--r--src/command.rs90
-rw-r--r--src/main.rs8
-rw-r--r--src/theme.rs6
4 files changed, 60 insertions, 48 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index 7bf9ab0..b82dfb9 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -237,9 +237,7 @@ impl App {
237 Command::Quit => self.save_state(), 237 Command::Quit => self.save_state(),
238 Command::MonthNext => self.sift_forward(), 238 Command::MonthNext => self.sift_forward(),
239 Command::MonthPrev => self.sift_backward(), 239 Command::MonthPrev => self.sift_backward(),
240 _ => { 240 Command::Blank => {}
241 eprintln!("UNKNOWN COMMAND!");
242 }
243 }, 241 },
244 Err(e) => { 242 Err(e) => {
245 self.message.set_message(e.to_string()); 243 self.message.set_message(e.to_string());
diff --git a/src/command.rs b/src/command.rs
index d285138..f856b00 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -1,21 +1,46 @@
1use std::fmt; 1use std::fmt;
2 2
3use cursive::theme::{BaseColor, Color, ColorStyle};
3use cursive::view::Resizable; 4use cursive::view::Resizable;
4use cursive::views::{Dialog, EditView}; 5use cursive::views::{EditView, LinearLayout, TextView};
5use cursive::Cursive; 6use cursive::Cursive;
6 7
7use crate::app::App; 8use crate::{app::App, CONFIGURATION};
8 9
9pub fn open_command_window(s: &mut Cursive) { 10pub fn open_command_window(s: &mut Cursive) {
10 let command_window = Dialog::around(EditView::new().on_submit(call_on_app).fixed_width(40)); 11 let command_window = EditView::new()
11 s.add_layer(command_window); 12 .filler(" ")
13 .on_submit(call_on_app)
14 .style(ColorStyle::new(
15 Color::Dark(BaseColor::Black),
16 Color::Dark(BaseColor::White),
17 ))
18 .fixed_width(CONFIGURATION.view_width * CONFIGURATION.grid_width);
19 s.call_on_name("Frame", |view: &mut LinearLayout| {
20 let mut commandline = LinearLayout::horizontal()
21 .child(TextView::new(":"))
22 .child(command_window);
23 commandline.set_focus_index(1);
24 view.add_child(commandline);
25 view.set_focus_index(1);
26 });
12} 27}
13 28
14fn call_on_app(s: &mut Cursive, input: &str) { 29fn call_on_app(s: &mut Cursive, input: &str) {
30 // things to do after recieving the command
31 // 1. parse the command
32 // 2. clean existing command messages
33 // 3. remove the command window
34 // 4. handle quit command
15 s.call_on_name("Main", |view: &mut App| { 35 s.call_on_name("Main", |view: &mut App| {
16 let cmd = Command::from_string(input); 36 let cmd = Command::from_string(input);
37 view.clear_message();
17 view.parse_command(cmd); 38 view.parse_command(cmd);
18 }); 39 });
40 s.call_on_name("Frame", |view: &mut LinearLayout| {
41 view.set_focus_index(0);
42 view.remove_child(view.get_focus_index());
43 });
19 44
20 // special command that requires access to 45 // special command that requires access to
21 // our main cursive object, has to be parsed again 46 // our main cursive object, has to be parsed again
@@ -24,8 +49,6 @@ fn call_on_app(s: &mut Cursive, input: &str) {
24 if let Ok(Command::Quit) = Command::from_string(input) { 49 if let Ok(Command::Quit) = Command::from_string(input) {
25 s.quit(); 50 s.quit();
26 } 51 }
27
28 s.pop_layer();
29} 52}
30 53
31#[derive(PartialEq)] 54#[derive(PartialEq)]
@@ -72,41 +95,27 @@ impl Command {
72 95
73 let first = strings.first().unwrap().to_string(); 96 let first = strings.first().unwrap().to_string();
74 let mut args: Vec<String> = strings.iter_mut().skip(1).map(|s| s.to_string()).collect(); 97 let mut args: Vec<String> = strings.iter_mut().skip(1).map(|s| s.to_string()).collect();
75 match first.as_ref() { 98 let mut _add = |auto: bool, first: String| {
76 "add" | "a" => { 99 if args.is_empty() {
77 if args.is_empty() { 100 return Err(CommandLineError::NotEnoughArgs(first, 1));
78 return Err(CommandLineError::NotEnoughArgs(first, 1));
79 }
80 let goal = args
81 .get(1)
82 .map(|x| {
83 x.parse::<u32>()
84 .map_err(|_| CommandLineError::InvalidArg(1))
85 })
86 .transpose()?;
87 return Ok(Command::Add(
88 args.get_mut(0).unwrap().to_string(),
89 goal,
90 false,
91 ));
92 }
93 "add-auto" | "aa" => {
94 if args.is_empty() {
95 return Err(CommandLineError::NotEnoughArgs(first, 1));
96 }
97 let goal = args
98 .get(1)
99 .map(|x| {
100 x.parse::<u32>()
101 .map_err(|_| CommandLineError::InvalidArg(1))
102 })
103 .transpose()?;
104 return Ok(Command::Add(
105 args.get_mut(0).unwrap().to_string(),
106 goal,
107 true,
108 ));
109 } 101 }
102 let goal = args
103 .get(1)
104 .map(|x| {
105 x.parse::<u32>()
106 .map_err(|_| CommandLineError::InvalidArg(2))
107 })
108 .transpose()?;
109 return Ok(Command::Add(
110 args.get_mut(0).unwrap().to_string(),
111 goal,
112 auto,
113 ));
114 };
115
116 match first.as_ref() {
117 "add" | "a" => _add(false, first),
118 "add-auto" | "aa" => _add(true, first),
110 "delete" | "d" => { 119 "delete" | "d" => {
111 if args.is_empty() { 120 if args.is_empty() {
112 return Err(CommandLineError::NotEnoughArgs(first, 1)); 121 return Err(CommandLineError::NotEnoughArgs(first, 1));
@@ -128,6 +137,7 @@ impl Command {
128 "mprev" | "month-prev" => return Ok(Command::MonthPrev), 137 "mprev" | "month-prev" => return Ok(Command::MonthPrev),
129 "mnext" | "month-next" => return Ok(Command::MonthNext), 138 "mnext" | "month-next" => return Ok(Command::MonthNext),
130 "q" | "quit" => return Ok(Command::Quit), 139 "q" | "quit" => return Ok(Command::Quit),
140 "" => return Ok(Command::Blank),
131 s => return Err(CommandLineError::InvalidCommand(s.into())), 141 s => return Err(CommandLineError::InvalidCommand(s.into())),
132 } 142 }
133 } 143 }
diff --git a/src/main.rs b/src/main.rs
index f83fc83..d96119e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,7 +13,7 @@ use crate::utils::{load_configuration_file, AppConfig};
13 13
14use clap::{App as ClapApp, Arg}; 14use clap::{App as ClapApp, Arg};
15use cursive::termion; 15use cursive::termion;
16use cursive::views::NamedView; 16use cursive::views::{LinearLayout, NamedView};
17use lazy_static::lazy_static; 17use lazy_static::lazy_static;
18 18
19lazy_static! { 19lazy_static! {
@@ -52,7 +52,11 @@ fn main() {
52 } else { 52 } else {
53 let mut s = termion().unwrap(); 53 let mut s = termion().unwrap();
54 let app = App::load_state(); 54 let app = App::load_state();
55 s.add_layer(NamedView::new("Main", app)); 55 let layout = NamedView::new(
56 "Frame",
57 LinearLayout::vertical().child(NamedView::new("Main", app)),
58 );
59 s.add_layer(layout);
56 s.add_global_callback(':', |s| open_command_window(s)); 60 s.add_global_callback(':', |s| open_command_window(s));
57 61
58 s.set_theme(theme::theme_gen()); 62 s.set_theme(theme::theme_gen());
diff --git a/src/theme.rs b/src/theme.rs
index 5c4072b..f29b273 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -1,6 +1,6 @@
1use cursive::theme::Color::*; 1use cursive::theme::Color::*;
2use cursive::theme::PaletteColor::*; 2use cursive::theme::PaletteColor::*;
3use cursive::theme::{BaseColor, BorderStyle, Palette, Theme}; 3use cursive::theme::{BaseColor, BorderStyle, ColorStyle, Palette, Theme};
4 4
5pub fn pallete_gen() -> Palette { 5pub fn pallete_gen() -> Palette {
6 let mut p = Palette::default(); 6 let mut p = Palette::default();
@@ -8,7 +8,7 @@ pub fn pallete_gen() -> Palette {
8 p[Shadow] = Light(BaseColor::Black); 8 p[Shadow] = Light(BaseColor::Black);
9 p[View] = Dark(BaseColor::Black); 9 p[View] = Dark(BaseColor::Black);
10 p[Primary] = Dark(BaseColor::White); 10 p[Primary] = Dark(BaseColor::White);
11 p[Secondary] = Light(BaseColor::Black); 11 p[Secondary] = Dark(BaseColor::Black);
12 p[Tertiary] = Dark(BaseColor::Green); 12 p[Tertiary] = Dark(BaseColor::Green);
13 p[TitlePrimary] = Light(BaseColor::White); 13 p[TitlePrimary] = Light(BaseColor::White);
14 p[Highlight] = Dark(BaseColor::Red); 14 p[Highlight] = Dark(BaseColor::Red);
@@ -20,7 +20,7 @@ pub fn pallete_gen() -> Palette {
20pub fn theme_gen() -> Theme { 20pub fn theme_gen() -> Theme {
21 let mut t = Theme::default(); 21 let mut t = Theme::default();
22 t.shadow = false; 22 t.shadow = false;
23 t.borders = BorderStyle::Simple; 23 t.borders = BorderStyle::None;
24 t.palette = pallete_gen(); 24 t.palette = pallete_gen();
25 return t; 25 return t;
26} 26}