wide mode is now session-wide

pull/14/head
chris west 4 years ago
parent 456ee0ad2d
commit c1e3bf7209

@ -1,5 +1,8 @@
use crate::gopher::{self, Type};
use crate::ui::{Action, Key, View, MAX_COLS, SCROLL_LINES};
use crate::{
config::Config,
gopher::{self, Type},
};
use std::fmt;
use termion::{clear, cursor};
@ -53,8 +56,8 @@ impl View for Menu {
self.raw.to_string()
}
fn render(&self) -> String {
self.render_lines()
fn render(&mut self, cfg: &Config) -> String {
self.render_lines(cfg)
}
fn respond(&mut self, key: Key) -> Action {
@ -149,7 +152,8 @@ impl Menu {
Some((x as u16, y as u16))
}
fn render_lines(&self) -> String {
fn render_lines(&mut self, cfg: &Config) -> String {
self.wide = cfg.wide;
let mut out = String::new();
let iter = self.lines.iter().skip(self.scroll).take(self.rows() - 1);
let indent = self.indent();
@ -655,10 +659,6 @@ impl Menu {
self.input.clear();
self.redraw_input()
}
Key::Char('w') | Key::Ctrl('w') => {
self.wide = !self.wide;
Action::Redraw
}
Key::Backspace | Key::Delete => {
if self.searching {
self.input.pop();

@ -1,4 +1,7 @@
use crate::ui::{Action, Key, View, MAX_COLS, SCROLL_LINES};
use crate::{
config::Config,
ui::{Action, Key, View, MAX_COLS, SCROLL_LINES},
};
use std::fmt;
use termion::clear;
@ -51,10 +54,6 @@ impl View for Text {
self.scroll = self.final_scroll();
Action::Redraw
}
Key::Char('w') | Key::Ctrl('w') => {
self.wide = !self.wide;
Action::Redraw
}
Key::Down | Key::Ctrl('n') | Key::Char('n') | Key::Ctrl('j') | Key::Char('j') => {
if self.scroll < self.final_scroll() {
self.scroll += 1;
@ -94,7 +93,8 @@ impl View for Text {
}
}
fn render(&self) -> String {
fn render(&mut self, cfg: &Config) -> String {
self.wide = cfg.wide;
let (cols, rows) = self.size;
let mut out = String::new();
let longest = if self.longest > MAX_COLS {

@ -276,7 +276,7 @@ impl UI {
if !self.views.is_empty() && self.focused < self.views.len() {
if let Some(page) = self.views.get_mut(self.focused) {
page.term_size(cols as usize, rows as usize);
return Ok(page.render());
return Ok(page.render(&self.config));
}
}
Err(error!(
@ -560,6 +560,10 @@ impl UI {
self.set_status(format!("Copied {} to clipboard.", url));
}
}
'w' => {
self.config.wide = !self.config.wide;
self.dirty = true;
}
'q' => self.running = false,
'\n' => (),
c => return Err(error!("Unknown keypress: {}", c)),

@ -1,9 +1,9 @@
use crate::ui;
use crate::{config::Config, ui};
use std::fmt;
pub trait View: fmt::Display {
fn respond(&mut self, key: ui::Key) -> ui::Action;
fn render(&self) -> String;
fn render(&mut self, cfg: &Config) -> String;
fn is_tls(&self) -> bool;
fn is_tor(&self) -> bool;
fn url(&self) -> String;

Loading…
Cancel
Save