diff --git a/src/display/body.rs b/src/display/body.rs index 80a4438..5e33df9 100644 --- a/src/display/body.rs +++ b/src/display/body.rs @@ -102,7 +102,11 @@ impl SigninPage { #[inline] fn draw(&self) -> String { let frame = self.frame.unwrap(); - frame.write_centered("login kk", 1) + format!( + "{header}{hostname}", + header = frame.write_centered("login kk", 1) + hostname = frame.write_centered("instance:", 3), + ) } } @@ -142,7 +146,7 @@ impl Page for SigninPage { )); write!( screen, - "{theme}{clear}{frame}{subframe}{hide_cursor}{content}", + "{theme}{clear}{frame}{subframe}{show_cursor}{content}", theme = env.theme.frame(), clear = clear::All, frame = env.frame.frame_str(env.theme.primary()), @@ -150,7 +154,7 @@ impl Page for SigninPage { .frame .unwrap() .frame_str(ColorSet::default().to_string()), - hide_cursor = cursor::Hide, + show_cursor = cursor::Show, content = self.draw(), )?; screen.flush()?; diff --git a/src/display/frame.rs b/src/display/frame.rs index 520499b..0ce7a2e 100644 --- a/src/display/frame.rs +++ b/src/display/frame.rs @@ -58,6 +58,27 @@ impl Frame { .into() } + #[inline(always)] + fn write_centered_clear(&self, s: &str) -> String { + let width = self.size().0 as usize; + let len = s.len(); + let base_size = ((width - len) / 2) - self.border as usize; + format!( + "{left}{line}{right}", + left = " ".repeat(base_size + ((width - len) % 2)), + line = s, + right = " ".repeat(base_size) + ) + } + + #[inline(always)] + fn write_frame_line(&self, y: u16, length: u16) -> String { + self.goto_internal(0, y) + + &FRAME_CHAR_HORIZONTAL + .to_string() + .repeat(length as usize) + } + #[inline(always)] fn write_clear_to_end(&self, s: &str) -> String { let clear_length = self.size().0 as usize @@ -79,25 +100,14 @@ impl Frame { out_words.concat() } - #[inline(always)] - fn write_frame_line(&self, y: u16, length: u16) -> String { - self.goto_internal(0, y) - + &FRAME_CHAR_HORIZONTAL - .to_string() - .repeat(length as usize) - } - pub fn write_centered(&self, s: &str, y: u16) -> String { - let (width, _) = self.size(); let words = s.split('\n').collect::>(); let mut out_words = Vec::with_capacity(words.len()); for i in 0..words.len() { - let word = words[i]; - let x = width - (word.len() as u16).min(width); out_words.push(format!( "{ret}{str}", - str = word, - ret = self.goto(x / 2, y + i as u16), + ret = self.goto(0, y + i as u16), + str = self.write_centered_clear(words[i]), )); } out_words.concat()