stims wore off and i have no idea what i did for the past 3 hours

This commit is contained in:
emilis 2023-01-16 01:47:24 +00:00
parent 7434a2b94d
commit 0918ffea90
3 changed files with 66 additions and 40 deletions

View File

@ -82,6 +82,7 @@ impl Page for Body {
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct SigninPage { pub struct SigninPage {
hostname: String, hostname: String,
token: String,
cursor: SigninCursorLocation, cursor: SigninCursorLocation,
frame: Option<Frame>, frame: Option<Frame>,
} }
@ -89,6 +90,7 @@ pub struct SigninPage {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum SigninCursorLocation { enum SigninCursorLocation {
Hostname, Hostname,
Token,
Ok, Ok,
} }
@ -103,8 +105,9 @@ impl SigninPage {
fn next(&mut self) { fn next(&mut self) {
self.cursor = match self.cursor { self.cursor = match self.cursor {
SigninCursorLocation::Hostname => { SigninCursorLocation::Hostname => {
SigninCursorLocation::Ok SigninCursorLocation::Token
} }
SigninCursorLocation::Token => SigninCursorLocation::Ok,
SigninCursorLocation::Ok => { SigninCursorLocation::Ok => {
SigninCursorLocation::Hostname SigninCursorLocation::Hostname
} }
@ -113,8 +116,15 @@ impl SigninPage {
#[inline] #[inline]
fn previous(&mut self) { fn previous(&mut self) {
// Don't tell them this neat trick self.cursor = match self.cursor {
self.next() SigninCursorLocation::Hostname => {
SigninCursorLocation::Ok
}
SigninCursorLocation::Token => {
SigninCursorLocation::Hostname
}
SigninCursorLocation::Ok => SigninCursorLocation::Token,
}
} }
fn draw( fn draw(
@ -124,14 +134,22 @@ impl SigninPage {
) -> Components { ) -> Components {
const HEADER_Y: u16 = 1; const HEADER_Y: u16 = 1;
const HOSTNAME_Y: u16 = 3; const HOSTNAME_Y: u16 = 3;
const OK_Y: u16 = 5; const TOKEN_Y: u16 = 4;
const OK_Y: u16 = 6;
let frame = self.frame.unwrap(); let frame = self.frame.unwrap();
let (w, _) = frame.inner_size(); let (w, _) = frame.inner_size();
let exp_w = w / 3; let exp_w = w - (w / 3);
let (hostname_theme, ok_theme) = match self.cursor { let (hostname_theme, token_theme, ok_theme) = match self
SigninCursorLocation::Hostname => (highlight, normal), .cursor
SigninCursorLocation::Ok => (normal, highlight), {
SigninCursorLocation::Hostname => {
(highlight, normal, normal)
}
SigninCursorLocation::Token => {
(normal, highlight, normal)
}
SigninCursorLocation::Ok => (normal, normal, highlight),
}; };
vec![ vec![
@ -156,6 +174,18 @@ impl SigninPage {
HOSTNAME_Y, HOSTNAME_Y,
) )
.0, .0,
frame
.prefix_centered_goto(
self.field(
token_theme,
normal,
exp_w,
"token",
&self.token,
),
TOKEN_Y,
)
.0,
vec![Component::Theme(ok_theme)], vec![Component::Theme(ok_theme)],
HorizontalAlignment::Center HorizontalAlignment::Center
.align(Text::Normal("[ok]".into()), w, OK_Y) .align(Text::Normal("[ok]".into()), w, OK_Y)
@ -196,12 +226,27 @@ impl SigninPage {
.into() .into()
} }
fn del(&mut self) {
match self.cursor {
SigninCursorLocation::Hostname => {
self.hostname.pop();
}
SigninCursorLocation::Token => {
self.token.pop();
}
SigninCursorLocation::Ok => {}
}
}
#[inline] #[inline]
fn char(&mut self, c: char) { fn char(&mut self, c: char) {
match self.cursor { match self.cursor {
SigninCursorLocation::Hostname => { SigninCursorLocation::Hostname => {
self.hostname.push(c); self.hostname.push(c);
} }
SigninCursorLocation::Token => {
self.token.push(c);
}
SigninCursorLocation::Ok => {} SigninCursorLocation::Ok => {}
} }
} }
@ -217,8 +262,8 @@ impl Page for SigninPage {
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(c) => self.char(c),
termion::event::Key::Up => self.next(), termion::event::Key::Up => self.previous(),
termion::event::Key::Down => self.previous(), termion::event::Key::Down => self.next(),
termion::event::Key::Backspace => { termion::event::Key::Backspace => {
if let SigninCursorLocation::Hostname = if let SigninCursorLocation::Hostname =
self.cursor self.cursor
@ -257,8 +302,8 @@ impl Page for SigninPage {
) -> Result<()> { ) -> Result<()> {
self.frame = Some(env.frame.sub( self.frame = Some(env.frame.sub(
env.theme.colors.subframe, env.theme.colors.subframe,
super::frame::FrameSize::ByPercent(50, 50), super::frame::FrameSize::ByAbsolute(70, 15),
2, 1,
)); ));
write!( write!(
screen, screen,

View File

@ -110,21 +110,6 @@ impl Frame {
.into() .into()
} }
#[inline]
pub fn to_end(&self, s: &str, x: u16, y: u16) -> Components {
// FIXME: handle the fucking newlines grrrr i hate this
let width = self.inner_size().0;
vec![
Component::Goto(x, y),
Component::String(Text::LimitedOrPadded(
s.into(),
' ',
width - x,
)),
]
.into()
}
pub fn make(&self, comp: Components) -> String { pub fn make(&self, comp: Components) -> String {
comp.0.into_iter().map(|c| c.make(self)).collect() comp.0.into_iter().map(|c| c.make(self)).collect()
} }
@ -225,10 +210,6 @@ impl Frame {
// the frame within a screen // the frame within a screen
pub fn compose(&self, body_theme: ColorSet) -> Components { pub fn compose(&self, body_theme: ColorSet) -> Components {
let body_theme = Component::Internal(body_theme.to_string()); let body_theme = Component::Internal(body_theme.to_string());
if self.border == 0 {
// FIXME: this will fuck up subframes
return vec![body_theme, Component::Clear].into();
}
let (w_len, h_len) = self.size(); let (w_len, h_len) = self.size();
let frame_theme = Component::Internal(self.theme.to_string()); let frame_theme = Component::Internal(self.theme.to_string());

View File

@ -81,24 +81,24 @@ impl Default for Theme {
Self { Self {
colors: Colors { colors: Colors {
primary: ColorSet { primary: ColorSet {
fg: "#ffe6ff".into(), fg: "#330033".into(),
bg: "#3b224c".into(), bg: "#a006d3".into(),
}, },
frame: ColorSet { frame: ColorSet {
fg: "#ffe6ff".into(), fg: "#ffe6ff".into(),
bg: "#330033".into(), bg: "#9005c2".into(),
}, },
subframe: ColorSet{ subframe: ColorSet {
fg: "#ffe6ff".into(), fg: "#ffe6ff".into(),
bg: "#110011".into() bg: "#7003a0".into(),
}, },
highlight: ColorSet{ highlight: ColorSet {
fg: "#ffffff".into(), fg: "#ffffff".into(),
bg: "#0000ff".into() bg: "#0000ff".into(),
}, },
subwin: ColorSet{ subwin: ColorSet {
fg: "#ffffff".into(), fg: "#ffffff".into(),
bg: "#000000".into(), bg: "#500170".into(),
}, },
}, },
} }