diff --git a/src/display/body.rs b/src/display/body.rs index d71189d..f1cffe8 100644 --- a/src/display/body.rs +++ b/src/display/body.rs @@ -28,7 +28,7 @@ impl Body { .nextline_after_text( 0, HorizontalAlignment::Left, - &env.frame, + env.frame.inner_size().0, ); write!(screen, "{}", env.frame.make(echo_comps))?; screen.flush()?; @@ -82,25 +82,41 @@ impl Page for Body { #[derive(Debug, Clone, Default)] pub struct SigninPage { hostname: String, - username: String, cursor: SigninCursorLocation, frame: Option, } #[derive(Debug, Clone)] enum SigninCursorLocation { - Hostname(u16), + Hostname, Ok, } impl Default for SigninCursorLocation { fn default() -> Self { - Self::Ok + Self::Hostname } } impl SigninPage { #[inline] + fn next(&mut self) { + self.cursor = match self.cursor { + SigninCursorLocation::Hostname => { + SigninCursorLocation::Ok + } + SigninCursorLocation::Ok => { + SigninCursorLocation::Hostname + } + } + } + + #[inline] + fn previous(&mut self) { + // Don't tell them this neat trick + self.next() + } + fn draw( &self, highlight: ColorSet, @@ -113,6 +129,11 @@ impl SigninPage { let (w, _) = frame.inner_size(); let exp_w = w / 3; + let (hostname_theme, ok_theme) = match self.cursor { + SigninCursorLocation::Hostname => (highlight, normal), + SigninCursorLocation::Ok => (normal, highlight), + }; + vec![ frame .prefix_centered_goto( @@ -126,7 +147,7 @@ impl SigninPage { frame .prefix_centered_goto( self.field( - highlight, + hostname_theme, normal, exp_w, "hostname", @@ -135,18 +156,11 @@ impl SigninPage { HOSTNAME_Y, ) .0, - frame - .prefix_centered_goto( - self.field( - highlight, - normal, - exp_w, - "username", - &self.username, - ), - OK_Y, - ) + vec![Component::Theme(ok_theme)], + HorizontalAlignment::Center + .align(Text::Normal("[ok]".into()), w, OK_Y) .0, + vec![Component::Theme(normal)], ] .into_iter() .flatten() @@ -193,8 +207,8 @@ impl Page for SigninPage { match event { Event::Key(key) => match key { termion::event::Key::Char(_) => {} - termion::event::Key::Up => {} - termion::event::Key::Down => {} + termion::event::Key::Up => self.next(), + termion::event::Key::Down => self.previous(), termion::event::Key::Backspace => {} termion::event::Key::Delete => {} termion::event::Key::Left => {} @@ -204,6 +218,19 @@ impl Page for SigninPage { }, } + let fr = self.frame.unwrap(); + write!( + screen, + "{}{}{}", + env.primary_frame(), + fr.frame_str(env.theme.colors.subwin), + fr.make(self.draw( + env.theme.colors.highlight, + env.theme.colors.subwin + )) + )?; + screen.flush()?; + Ok(()) } diff --git a/src/display/compose.rs b/src/display/compose.rs index bd50c0e..c481e18 100644 --- a/src/display/compose.rs +++ b/src/display/compose.rs @@ -88,23 +88,22 @@ impl HorizontalAlignment { pub fn align( &self, s: Text, - frame: &Frame, + body_width: u16, y: u16, ) -> Components { - let (width, _) = frame.size(); match self { Self::Left => { vec![Component::Goto(0, y), Component::String(s)] } Self::Right => { vec![ - Component::Goto(s.len() as u16 - width, y), + Component::Goto(s.len() as u16 - body_width, y), Component::String(s), ] } Self::Center => { vec![ - Component::Goto((width - s.len()) / 2, y), + Component::Goto((body_width - s.len()) / 2, y), Component::String(s), ] } @@ -173,13 +172,13 @@ impl Components { self, y: u16, align: HorizontalAlignment, - frame: &Frame, + body_width: u16, ) -> Self { let mut last_y = y; let xxx = self.0.into_iter().map(|comp| match comp { Component::String(s) => { last_y += 1; - align.align(s, frame, last_y).0 + align.align(s, body_width, last_y).0 } Component::Goto(_, y) => { last_y = y;