Compare commits

..

No commits in common. "7434a2b94d18abc0440a995a8cad7e9b037a5b92" and "ac9e337e731cd1961cedf94504b485505ec0487a" have entirely different histories.

2 changed files with 26 additions and 68 deletions

View File

@ -28,7 +28,7 @@ impl Body {
.nextline_after_text(
0,
HorizontalAlignment::Left,
env.frame.inner_size().0,
&env.frame,
);
write!(screen, "{}", env.frame.make(echo_comps))?;
screen.flush()?;
@ -82,41 +82,25 @@ impl Page for Body {
#[derive(Debug, Clone, Default)]
pub struct SigninPage {
hostname: String,
username: String,
cursor: SigninCursorLocation,
frame: Option<Frame>,
}
#[derive(Debug, Clone)]
enum SigninCursorLocation {
Hostname,
Hostname(u16),
Ok,
}
impl Default for SigninCursorLocation {
fn default() -> Self {
Self::Hostname
Self::Ok
}
}
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,
@ -129,11 +113,6 @@ 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(
@ -147,7 +126,7 @@ impl SigninPage {
frame
.prefix_centered_goto(
self.field(
hostname_theme,
highlight,
normal,
exp_w,
"hostname",
@ -156,11 +135,18 @@ impl SigninPage {
HOSTNAME_Y,
)
.0,
vec![Component::Theme(ok_theme)],
HorizontalAlignment::Center
.align(Text::Normal("[ok]".into()), w, OK_Y)
frame
.prefix_centered_goto(
self.field(
highlight,
normal,
exp_w,
"username",
&self.username,
),
OK_Y,
)
.0,
vec![Component::Theme(normal)],
]
.into_iter()
.flatten()
@ -195,16 +181,6 @@ impl SigninPage {
]
.into()
}
#[inline]
fn char(&mut self, c: char) {
match self.cursor {
SigninCursorLocation::Hostname => {
self.hostname.push(c);
}
SigninCursorLocation::Ok => {}
}
}
}
impl Page for SigninPage {
@ -216,16 +192,10 @@ impl Page for SigninPage {
) -> Result<()> {
match event {
Event::Key(key) => match key {
termion::event::Key::Char(c) => self.char(c),
termion::event::Key::Up => self.next(),
termion::event::Key::Down => self.previous(),
termion::event::Key::Backspace => {
if let SigninCursorLocation::Hostname =
self.cursor
{
self.hostname.pop();
}
}
termion::event::Key::Char(_) => {}
termion::event::Key::Up => {}
termion::event::Key::Down => {}
termion::event::Key::Backspace => {}
termion::event::Key::Delete => {}
termion::event::Key::Left => {}
termion::event::Key::Right => {}
@ -234,19 +204,6 @@ 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(())
}

View File

@ -88,22 +88,23 @@ impl HorizontalAlignment {
pub fn align(
&self,
s: Text,
body_width: u16,
frame: &Frame,
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 - body_width, y),
Component::Goto(s.len() as u16 - width, y),
Component::String(s),
]
}
Self::Center => {
vec![
Component::Goto((body_width - s.len()) / 2, y),
Component::Goto((width - s.len()) / 2, y),
Component::String(s),
]
}
@ -172,13 +173,13 @@ impl Components {
self,
y: u16,
align: HorizontalAlignment,
body_width: u16,
frame: &Frame,
) -> 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, body_width, last_y).0
align.align(s, frame, last_y).0
}
Component::Goto(_, y) => {
last_y = y;