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.
pub(crate) enum Encoding {
#[derive(Copy, Clone)]
pub enum Encoding {
/// Unicode
UTF8,
/// https://en.wikipedia.org/wiki/Code_page_437
CP437,
}
impl Default for Encoding {
fn default() -> Self {
Encoding::UTF8
}
}

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

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

Loading…
Cancel
Save