basic text view

pull/6/head
dvkt 5 years ago
parent 789a972019
commit e7a3ff553e

@ -4,6 +4,7 @@ extern crate termion;
mod gopher;
mod menu;
mod text;
mod types;
mod ui;
use ui::UI;

@ -277,6 +277,14 @@ impl Menu {
url.push(':');
url.push_str(parts[3].trim_end_matches('\r')); // port
}
if let Some(first_char) = parts[0].chars().nth(0) {
if first_char == '0' || first_char == '1' {
url.push_str("/");
url.push(first_char);
}
}
if parts.len() > 1 {
url.push_str(parts[1]); // selector
}

@ -0,0 +1,22 @@
use ui::{Action, Key, View};
pub struct TextView {
url: String,
raw: String,
}
impl View for TextView {
fn process_input(&mut self, c: Key) -> Action {
Action::None
}
fn render(&self, width: u16, height: u16) -> String {
self.raw.to_string()
}
}
impl TextView {
pub fn from(url: String, response: String) -> TextView {
TextView { url, raw: response }
}
}

@ -5,6 +5,7 @@ use termion::raw::IntoRawMode;
use gopher;
use gopher::Type;
use menu::MenuView;
use text::TextView;
pub type Key = termion::event::Key;
@ -84,7 +85,7 @@ impl UI {
match typ {
Type::Menu => self.add_page(MenuView::from(url.to_string(), response)),
// Type::Text => self.add_page(TextView::from(url, response)),
Type::Text => self.add_page(TextView::from(url.to_string(), response)),
_ => panic!("unknown type: {:?}", typ),
}
}

Loading…
Cancel
Save