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

View File

@ -110,21 +110,6 @@ impl Frame {
.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 {
comp.0.into_iter().map(|c| c.make(self)).collect()
}
@ -225,10 +210,6 @@ impl Frame {
// the frame within a screen
pub fn compose(&self, body_theme: ColorSet) -> Components {
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 frame_theme = Component::Internal(self.theme.to_string());

View File

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