Compare commits
No commits in common. "7434a2b94d18abc0440a995a8cad7e9b037a5b92" and "ac9e337e731cd1961cedf94504b485505ec0487a" have entirely different histories.
7434a2b94d
...
ac9e337e73
|
@ -28,7 +28,7 @@ impl Body {
|
||||||
.nextline_after_text(
|
.nextline_after_text(
|
||||||
0,
|
0,
|
||||||
HorizontalAlignment::Left,
|
HorizontalAlignment::Left,
|
||||||
env.frame.inner_size().0,
|
&env.frame,
|
||||||
);
|
);
|
||||||
write!(screen, "{}", env.frame.make(echo_comps))?;
|
write!(screen, "{}", env.frame.make(echo_comps))?;
|
||||||
screen.flush()?;
|
screen.flush()?;
|
||||||
|
@ -82,41 +82,25 @@ 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,
|
Hostname(u16),
|
||||||
Ok,
|
Ok,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SigninCursorLocation {
|
impl Default for SigninCursorLocation {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Hostname
|
Self::Ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
@ -129,11 +113,6 @@ 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(
|
||||||
|
@ -147,7 +126,7 @@ impl SigninPage {
|
||||||
frame
|
frame
|
||||||
.prefix_centered_goto(
|
.prefix_centered_goto(
|
||||||
self.field(
|
self.field(
|
||||||
hostname_theme,
|
highlight,
|
||||||
normal,
|
normal,
|
||||||
exp_w,
|
exp_w,
|
||||||
"hostname",
|
"hostname",
|
||||||
|
@ -156,11 +135,18 @@ impl SigninPage {
|
||||||
HOSTNAME_Y,
|
HOSTNAME_Y,
|
||||||
)
|
)
|
||||||
.0,
|
.0,
|
||||||
vec![Component::Theme(ok_theme)],
|
frame
|
||||||
HorizontalAlignment::Center
|
.prefix_centered_goto(
|
||||||
.align(Text::Normal("[ok]".into()), w, OK_Y)
|
self.field(
|
||||||
|
highlight,
|
||||||
|
normal,
|
||||||
|
exp_w,
|
||||||
|
"username",
|
||||||
|
&self.username,
|
||||||
|
),
|
||||||
|
OK_Y,
|
||||||
|
)
|
||||||
.0,
|
.0,
|
||||||
vec![Component::Theme(normal)],
|
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
@ -195,16 +181,6 @@ 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 {
|
||||||
|
@ -216,16 +192,10 @@ impl Page for SigninPage {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
match event {
|
match event {
|
||||||
Event::Key(key) => match key {
|
Event::Key(key) => match key {
|
||||||
termion::event::Key::Char(c) => self.char(c),
|
termion::event::Key::Char(_) => {}
|
||||||
termion::event::Key::Up => self.next(),
|
termion::event::Key::Up => {}
|
||||||
termion::event::Key::Down => self.previous(),
|
termion::event::Key::Down => {}
|
||||||
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 => {}
|
||||||
|
@ -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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,22 +88,23 @@ impl HorizontalAlignment {
|
||||||
pub fn align(
|
pub fn align(
|
||||||
&self,
|
&self,
|
||||||
s: Text,
|
s: Text,
|
||||||
body_width: u16,
|
frame: &Frame,
|
||||||
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 - body_width, y),
|
Component::Goto(s.len() as u16 - width, y),
|
||||||
Component::String(s),
|
Component::String(s),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Self::Center => {
|
Self::Center => {
|
||||||
vec![
|
vec![
|
||||||
Component::Goto((body_width - s.len()) / 2, y),
|
Component::Goto((width - s.len()) / 2, y),
|
||||||
Component::String(s),
|
Component::String(s),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -172,13 +173,13 @@ impl Components {
|
||||||
self,
|
self,
|
||||||
y: u16,
|
y: u16,
|
||||||
align: HorizontalAlignment,
|
align: HorizontalAlignment,
|
||||||
body_width: u16,
|
frame: &Frame,
|
||||||
) -> 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, body_width, last_y).0
|
align.align(s, frame, last_y).0
|
||||||
}
|
}
|
||||||
Component::Goto(_, y) => {
|
Component::Goto(_, y) => {
|
||||||
last_y = y;
|
last_y = y;
|
||||||
|
|
Loading…
Reference in New Issue