simplify status line & show cp439 in it

pull/22/head
chris west 4 years ago
parent 5df09aead9
commit 400fe770a9

@ -19,6 +19,7 @@ pub use self::{action::Action, mode::Mode, view::View};
use crate::{ use crate::{
bookmarks, color, bookmarks, color,
config::Config, config::Config,
encoding::Encoding,
gopher::{self, Type}, gopher::{self, Type},
help, history, help, history,
menu::Menu, menu::Menu,
@ -375,22 +376,41 @@ impl UI {
/// Render the connection status (TLS or Tor). /// Render the connection status (TLS or Tor).
fn render_conn_status(&self) -> Option<String> { fn render_conn_status(&self) -> Option<String> {
let view = self.views.get(self.focused)?; let view = self.views.get(self.focused)?;
let mut status = vec![];
if matches!(view.encoding(), Encoding::CP437) {
status.push("CP439");
}
if view.is_tls() { if view.is_tls() {
let status = color_string!("TLS", Black, GreenBG); if self.config.emoji {
return Some(format!( status.push("🔐");
"{}{}", } else {
terminal::Goto(self.cols() - 3, self.rows()), status.push("TLS");
if self.config.emoji { "🔐" } else { &status }, }
));
} else if view.is_tor() { } else if view.is_tor() {
let status = color_string!("TOR", Bold, White, MagentaBG); if self.config.emoji {
return Some(format!( status.push("🧅");
} else {
status.push("TOR");
}
}
if status.is_empty() {
None
} else {
let len = status.iter().fold(0, |a, s| a + s.len());
let len = len + status.len();
Some(format!(
"{}{}", "{}{}",
terminal::Goto(self.cols() - 3, self.rows()), terminal::Goto(self.cols() - len as u16, self.rows()),
if self.config.emoji { "🧅" } else { &status }, status
)); .iter()
.map(|s| color_string!(s, Bold, White))
.collect::<Vec<_>>()
.join(" "),
))
} }
None
} }
/// Render the status line. /// Render the status line.

Loading…
Cancel
Save