center content

pull/6/head
dvkt 4 years ago
parent 75ce7796f5
commit bf9b33788f

@ -2,7 +2,7 @@ use gopher;
use gopher::Type;
use std::io::stdout;
use std::io::Write;
use ui::{Action, Key, View};
use ui::{Action, Key, View, MAX_COLS, SCROLL_LINES};
pub struct MenuView {
pub input: String, // user's inputted value
@ -25,8 +25,6 @@ pub struct Line {
link: usize, // link #, if any
}
const SCROLL_LINES: usize = 15;
impl View for MenuView {
fn render(&self, cols: usize, rows: usize) -> String {
self.render_lines(cols, rows)
@ -73,11 +71,15 @@ impl MenuView {
}
let iter = self.lines().iter().skip(self.scroll).take(rows - 1);
let indent = if self.menu.longest > cols {
let longest = if self.menu.longest > MAX_COLS {
MAX_COLS
} else {
self.menu.longest
};
let indent = if longest > cols {
String::from("")
} else {
let left = (cols - self.menu.longest) / 2;
let left = (cols - longest) / 2;
if left > 6 {
" ".repeat(left - 6)
} else {

@ -1,4 +1,4 @@
use ui::{Action, Key, View};
use ui::{Action, Key, View, MAX_COLS, SCROLL_LINES};
pub struct TextView {
url: String,
@ -8,8 +8,6 @@ pub struct TextView {
longest: usize, // longest line
}
const SCROLL_LINES: usize = 15;
impl View for TextView {
fn url(&self) -> String {
self.url.to_string()
@ -77,15 +75,16 @@ impl View for TextView {
fn render(&self, cols: usize, rows: usize) -> String {
let mut out = String::new();
let indent = if self.longest > cols {
let longest = if self.longest > MAX_COLS {
MAX_COLS
} else {
self.longest
};
let indent = if longest > cols {
String::from("")
} else {
let left = (cols - self.longest) / 2;
if left > 6 {
" ".repeat(left - 6)
} else {
String::from("")
}
let left = (cols - longest) / 2;
" ".repeat(left)
};
let iter = self
.raw

@ -10,6 +10,9 @@ use text::TextView;
pub type Key = termion::event::Key;
pub const SCROLL_LINES: usize = 15;
pub const MAX_COLS: usize = 72;
pub struct UI {
pages: Vec<Box<dyn View>>,
page: usize, // currently focused page

Loading…
Cancel
Save