|
|
@ -41,7 +41,10 @@ use termion::{
|
|
|
|
terminal_size,
|
|
|
|
terminal_size,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Alias for a termion Key event.
|
|
|
|
pub type Key = termion::event::Key;
|
|
|
|
pub type Key = termion::event::Key;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Alias for either a Menu or Text View.
|
|
|
|
pub type Page = Box<dyn View>;
|
|
|
|
pub type Page = Box<dyn View>;
|
|
|
|
|
|
|
|
|
|
|
|
/// How many lines to jump by when using page up/down.
|
|
|
|
/// How many lines to jump by when using page up/down.
|
|
|
@ -54,17 +57,25 @@ pub const MAX_COLS: usize = 77;
|
|
|
|
/// UI is mainly concerned with drawing to the screen, managing the
|
|
|
|
/// UI is mainly concerned with drawing to the screen, managing the
|
|
|
|
/// active Views/pages, and responding to user input.
|
|
|
|
/// active Views/pages, and responding to user input.
|
|
|
|
pub struct UI {
|
|
|
|
pub struct UI {
|
|
|
|
views: Vec<Page>, // loaded views
|
|
|
|
/// Current loaded Gopher views. Menu or Text
|
|
|
|
focused: usize, // currently focused view
|
|
|
|
views: Vec<Page>,
|
|
|
|
dirty: bool, // redraw?
|
|
|
|
/// Index of currently focused View
|
|
|
|
running: bool, // main ui loop running?
|
|
|
|
focused: usize,
|
|
|
|
pub size: (usize, usize), // cols, rows
|
|
|
|
/// Does the UI need to be entirely redrawn?
|
|
|
|
status: String, // status message, if any
|
|
|
|
dirty: bool,
|
|
|
|
config: Config, // user config
|
|
|
|
/// Is the UI running?
|
|
|
|
|
|
|
|
running: bool,
|
|
|
|
|
|
|
|
/// Size of screen (cols, rows)
|
|
|
|
|
|
|
|
pub size: (usize, usize),
|
|
|
|
|
|
|
|
/// Status message to display on screen, if any
|
|
|
|
|
|
|
|
status: String,
|
|
|
|
|
|
|
|
/// User config. Command line options + phetch.conf
|
|
|
|
|
|
|
|
config: Config,
|
|
|
|
out: RefCell<RawTerminal<Stdout>>,
|
|
|
|
out: RefCell<RawTerminal<Stdout>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl UI {
|
|
|
|
impl UI {
|
|
|
|
|
|
|
|
/// Create a new phetch application from a user provided config.
|
|
|
|
pub fn new(config: Config) -> UI {
|
|
|
|
pub fn new(config: Config) -> UI {
|
|
|
|
let mut size = (0, 0);
|
|
|
|
let mut size = (0, 0);
|
|
|
|
if let Ok((cols, rows)) = terminal_size() {
|
|
|
|
if let Ok((cols, rows)) = terminal_size() {
|
|
|
|