add encoding() to View trait

pull/22/head
chris west 4 years ago
parent 41324a0ff3
commit 5df09aead9

@ -1,7 +1,14 @@
/// Encoding of Gopher response. Only UTF8 and CP437 are supported. /// Encoding of Gopher response. Only UTF8 and CP437 are supported.
pub(crate) enum Encoding { #[derive(Copy, Clone)]
pub enum Encoding {
/// Unicode /// Unicode
UTF8, UTF8,
/// https://en.wikipedia.org/wiki/Code_page_437 /// https://en.wikipedia.org/wiki/Code_page_437
CP437, CP437,
} }
impl Default for Encoding {
fn default() -> Self {
Encoding::UTF8
}
}

@ -72,6 +72,10 @@ impl View for Text {
self.wide self.wide
} }
fn encoding(&self) -> Encoding {
self.encoding
}
fn respond(&mut self, c: Key) -> Action { fn respond(&mut self, c: Key) -> Action {
match c { match c {
Key::Home => { Key::Home => {
@ -200,7 +204,7 @@ impl Text {
mode: config.mode, mode: config.mode,
tls, tls,
tor: config.tor, tor: config.tor,
encoding: Encoding::UTF8, encoding: Encoding::default(),
wide: config.wide, wide: config.wide,
} }
} }

@ -1,5 +1,7 @@
use crate::ui; use {
use std::fmt; crate::{encoding::Encoding, ui},
std::fmt,
};
/// Views represent what's on screen, a Gopher Menu/Text/etc item. /// Views represent what's on screen, a Gopher Menu/Text/etc item.
pub trait View: fmt::Display { pub trait View: fmt::Display {
@ -23,4 +25,8 @@ pub trait View: fmt::Display {
fn wide(&mut self) -> bool; fn wide(&mut self) -> bool;
/// Set the current screen size. /// Set the current screen size.
fn term_size(&mut self, cols: usize, rows: usize); fn term_size(&mut self, cols: usize, rows: usize);
/// The current encoding.
fn encoding(&self) -> Encoding {
Encoding::default()
}
} }

Loading…
Cancel
Save