Compare commits
2 Commits
ac9e337e73
...
7434a2b94d
Author | SHA1 | Date |
---|---|---|
emilis | 7434a2b94d | |
emilis | b749733fb7 |
|
@ -28,7 +28,7 @@ impl Body {
|
||||||
.nextline_after_text(
|
.nextline_after_text(
|
||||||
0,
|
0,
|
||||||
HorizontalAlignment::Left,
|
HorizontalAlignment::Left,
|
||||||
&env.frame,
|
env.frame.inner_size().0,
|
||||||
);
|
);
|
||||||
write!(screen, "{}", env.frame.make(echo_comps))?;
|
write!(screen, "{}", env.frame.make(echo_comps))?;
|
||||||
screen.flush()?;
|
screen.flush()?;
|
||||||
|
@ -82,25 +82,41 @@ impl Page for Body {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct SigninPage {
|
pub struct SigninPage {
|
||||||
hostname: String,
|
hostname: String,
|
||||||
username: String,
|
|
||||||
cursor: SigninCursorLocation,
|
cursor: SigninCursorLocation,
|
||||||
frame: Option<Frame>,
|
frame: Option<Frame>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum SigninCursorLocation {
|
enum SigninCursorLocation {
|
||||||
Hostname(u16),
|
Hostname,
|
||||||
Ok,
|
Ok,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SigninCursorLocation {
|
impl Default for SigninCursorLocation {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Ok
|
Self::Hostname
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SigninPage {
|
impl SigninPage {
|
||||||
#[inline]
|
#[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(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
highlight: ColorSet,
|
highlight: ColorSet,
|
||||||
|
@ -113,6 +129,11 @@ impl SigninPage {
|
||||||
let (w, _) = frame.inner_size();
|
let (w, _) = frame.inner_size();
|
||||||
let exp_w = w / 3;
|
let exp_w = w / 3;
|
||||||
|
|
||||||
|
let (hostname_theme, ok_theme) = match self.cursor {
|
||||||
|
SigninCursorLocation::Hostname => (highlight, normal),
|
||||||
|
SigninCursorLocation::Ok => (normal, highlight),
|
||||||
|
};
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
frame
|
frame
|
||||||
.prefix_centered_goto(
|
.prefix_centered_goto(
|
||||||
|
@ -126,7 +147,7 @@ impl SigninPage {
|
||||||
frame
|
frame
|
||||||
.prefix_centered_goto(
|
.prefix_centered_goto(
|
||||||
self.field(
|
self.field(
|
||||||
highlight,
|
hostname_theme,
|
||||||
normal,
|
normal,
|
||||||
exp_w,
|
exp_w,
|
||||||
"hostname",
|
"hostname",
|
||||||
|
@ -135,18 +156,11 @@ impl SigninPage {
|
||||||
HOSTNAME_Y,
|
HOSTNAME_Y,
|
||||||
)
|
)
|
||||||
.0,
|
.0,
|
||||||
frame
|
vec![Component::Theme(ok_theme)],
|
||||||
.prefix_centered_goto(
|
HorizontalAlignment::Center
|
||||||
self.field(
|
.align(Text::Normal("[ok]".into()), w, OK_Y)
|
||||||
highlight,
|
|
||||||
normal,
|
|
||||||
exp_w,
|
|
||||||
"username",
|
|
||||||
&self.username,
|
|
||||||
),
|
|
||||||
OK_Y,
|
|
||||||
)
|
|
||||||
.0,
|
.0,
|
||||||
|
vec![Component::Theme(normal)],
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
@ -181,6 +195,16 @@ impl SigninPage {
|
||||||
]
|
]
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn char(&mut self, c: char) {
|
||||||
|
match self.cursor {
|
||||||
|
SigninCursorLocation::Hostname => {
|
||||||
|
self.hostname.push(c);
|
||||||
|
}
|
||||||
|
SigninCursorLocation::Ok => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Page for SigninPage {
|
impl Page for SigninPage {
|
||||||
|
@ -192,10 +216,16 @@ impl Page for SigninPage {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
match event {
|
match event {
|
||||||
Event::Key(key) => match key {
|
Event::Key(key) => match key {
|
||||||
termion::event::Key::Char(_) => {}
|
termion::event::Key::Char(c) => self.char(c),
|
||||||
termion::event::Key::Up => {}
|
termion::event::Key::Up => self.next(),
|
||||||
termion::event::Key::Down => {}
|
termion::event::Key::Down => self.previous(),
|
||||||
termion::event::Key::Backspace => {}
|
termion::event::Key::Backspace => {
|
||||||
|
if let SigninCursorLocation::Hostname =
|
||||||
|
self.cursor
|
||||||
|
{
|
||||||
|
self.hostname.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
termion::event::Key::Delete => {}
|
termion::event::Key::Delete => {}
|
||||||
termion::event::Key::Left => {}
|
termion::event::Key::Left => {}
|
||||||
termion::event::Key::Right => {}
|
termion::event::Key::Right => {}
|
||||||
|
@ -204,6 +234,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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,23 +88,22 @@ impl HorizontalAlignment {
|
||||||
pub fn align(
|
pub fn align(
|
||||||
&self,
|
&self,
|
||||||
s: Text,
|
s: Text,
|
||||||
frame: &Frame,
|
body_width: u16,
|
||||||
y: u16,
|
y: u16,
|
||||||
) -> Components {
|
) -> Components {
|
||||||
let (width, _) = frame.size();
|
|
||||||
match self {
|
match self {
|
||||||
Self::Left => {
|
Self::Left => {
|
||||||
vec![Component::Goto(0, y), Component::String(s)]
|
vec![Component::Goto(0, y), Component::String(s)]
|
||||||
}
|
}
|
||||||
Self::Right => {
|
Self::Right => {
|
||||||
vec![
|
vec![
|
||||||
Component::Goto(s.len() as u16 - width, y),
|
Component::Goto(s.len() as u16 - body_width, y),
|
||||||
Component::String(s),
|
Component::String(s),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Self::Center => {
|
Self::Center => {
|
||||||
vec![
|
vec![
|
||||||
Component::Goto((width - s.len()) / 2, y),
|
Component::Goto((body_width - s.len()) / 2, y),
|
||||||
Component::String(s),
|
Component::String(s),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -173,13 +172,13 @@ impl Components {
|
||||||
self,
|
self,
|
||||||
y: u16,
|
y: u16,
|
||||||
align: HorizontalAlignment,
|
align: HorizontalAlignment,
|
||||||
frame: &Frame,
|
body_width: u16,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut last_y = y;
|
let mut last_y = y;
|
||||||
let xxx = self.0.into_iter().map(|comp| match comp {
|
let xxx = self.0.into_iter().map(|comp| match comp {
|
||||||
Component::String(s) => {
|
Component::String(s) => {
|
||||||
last_y += 1;
|
last_y += 1;
|
||||||
align.align(s, frame, last_y).0
|
align.align(s, body_width, last_y).0
|
||||||
}
|
}
|
||||||
Component::Goto(_, y) => {
|
Component::Goto(_, y) => {
|
||||||
last_y = y;
|
last_y = y;
|
||||||
|
|
Loading…
Reference in New Issue