Skip to content

Commit

Permalink
Add system info page
Browse files Browse the repository at this point in the history
We gather information from various sources:
- Environment variables.
- The `sysinfo` and `statvfs` system calls.
- The outputs of `scripts/ip.sh`.
- The outputs of `ntx_hwconfig -s /dev/mmcblk0`.

The TOC is now opened with the built-in HTML renderer.

Ephemeral documents can now be saved.
  • Loading branch information
baskerville committed Sep 15, 2020
1 parent 17c7420 commit dbb6a6c
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 51 deletions.
97 changes: 97 additions & 0 deletions css/html.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
html > head {
display: none;
}

a {
color: #444;
}

i, em, cite, var, address {
font-style: italic;
}

b, strong {
font-weight: bold;
}

h1 {
font-size: 2em;
margin: 0.67em 0;
}

h2 {
font-size: 1.5em;
margin: 0.75em 0;
}

h3 {
font-size: 1.17em;
margin: 0.83em 0;
}

h4, p, blockquote, dl {
margin: 1.12em 0;
}

h5 {
font-size: 0.83em;
margin: 1.5em 0;
}

h6 {
font-size: 0.75em;
margin: 1.67em 0;
}

dt {
margin-top: 1.12em;
}

dd {
margin-left: 1.5em;
}

pre, code, samp, kbd {
font-family: monospace;
font-size: 0.891em;
}

ul, ol {
margin-left: 1.5em;
margin-top: 0.6rem;
margin-bottom: 0.6rem;
}

li > ul, li > ol {
margin-top: 0;
margin-bottom: 0;
}

svg {
text-align: center;
}

sub, sup {
font-size: 0.83em;
}

sub {
vertical-align: sub;
}

sup {
vertical-align: super;
}

table {
text-align: left;
}

th {
font-weight: bold;
text-align: center;
}

th, td {
padding: 0.67em;
}
21 changes: 21 additions & 0 deletions css/sysinfo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
body {
font-family: sans-serif;
font-size: 8.1875pt;
text-align: center;
}

table {
display: inline-table;
}

tr {
padding-bottom: 0.5em;
}

tr.sep {
padding-top: 0.5em;
}

td {
padding: 0 0.5em 0;
}
6 changes: 3 additions & 3 deletions css/toc.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ ul {
padding: 0;
}

ul ul {
ul > ul {
padding-left: 2em;
}

ul li {
ul > li {
list-style-type: none;
padding-top: 0.5em;
}

body > ul > li {
ul.top > li {
padding-top: 1em;
}

Expand Down
16 changes: 15 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::view::keyboard::{Layout};
use crate::view::dictionary::Dictionary as DictionaryApp;
use crate::view::calculator::Calculator;
use crate::view::sketch::Sketch;
use crate::document::sys_info_as_html;
use crate::input::{DeviceEvent, PowerSource, ButtonCode, ButtonStatus, VAL_RELEASE, VAL_PRESS};
use crate::input::{raw_events, device_events, usb_events, display_rotate_event, button_scheme_event};
use crate::gesture::{GestureEvent, gesture_events};
Expand Down Expand Up @@ -857,6 +858,19 @@ pub fn run() -> Result<(), Error> {
rq.add(RenderData::new(dialog.id(), *dialog.rect(), UpdateMode::Gui));
view.children_mut().push(Box::new(dialog) as Box<dyn View>);
},
Event::Select(EntryId::SystemInfo) => {
view.children_mut().retain(|child| !child.is::<Menu>());
let html = sys_info_as_html();
let r = Reader::from_html(context.fb.rect(), &html, &tx, &mut context);
let mut next_view = Box::new(r) as Box<dyn View>;
transfer_notifications(view.as_mut(), next_view.as_mut(), &mut rq, &mut context);
history.push(HistoryItem {
view,
rotation: context.display.rotation,
monochrome: context.fb.monochrome(),
});
view = next_view;
},
Event::Select(EntryId::Launch(app_cmd)) => {
view.children_mut().retain(|child| !child.is::<Menu>());
let monochrome = context.fb.monochrome();
Expand Down Expand Up @@ -995,7 +1009,7 @@ pub fn run() -> Result<(), Error> {
Event::Select(EntryId::TakeScreenshot) => {
let name = Local::now().format("screenshot-%Y%m%d_%H%M%S.png");
let msg = match context.fb.save(&name.to_string()) {
Err(e) => format!("Couldn't take screenshot: {}).", e),
Err(e) => format!("{}", e),
Ok(_) => format!("Saved {}.", name),
};
let notif = Notification::new(ViewId::TakeScreenshotNotif,
Expand Down
30 changes: 20 additions & 10 deletions src/document/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod style;
pub mod layout;
pub mod engine;

use std::io::Read;
use std::io::{Read, Write};
use std::fs::{self, File};
use std::path::{Path, PathBuf};
use fxhash::FxHashMap;
Expand All @@ -29,6 +29,7 @@ const USER_STYLESHEET: &str = "css/html-user.css";
type UriCache = FxHashMap<String, usize>;

pub struct HtmlDocument {
text: String,
content: Node,
engine: Engine,
pages: Vec<Page>,
Expand All @@ -55,13 +56,14 @@ impl HtmlDocument {
pub fn new<P: AsRef<Path>>(path: P) -> Result<HtmlDocument, Error> {
let mut file = File::open(&path)?;
let size = file.metadata()?.len() as usize;
let mut content = String::new();
file.read_to_string(&mut content)?;
let mut content = XmlParser::new(&content).parse();
let mut text = String::new();
file.read_to_string(&mut text)?;
let mut content = XmlParser::new(&text).parse();
content.wrap_lost_inlines();
let parent = path.as_ref().parent().unwrap_or_else(|| Path::new(""));

Ok(HtmlDocument {
text,
content,
engine: Engine::new(),
pages: Vec::new(),
Expand All @@ -73,12 +75,13 @@ impl HtmlDocument {
})
}

pub fn new_from_memory(content: &str) -> HtmlDocument {
let size = content.len();
let mut content = XmlParser::new(content).parse();
pub fn new_from_memory(text: &str) -> HtmlDocument {
let size = text.len();
let mut content = XmlParser::new(text).parse();
content.wrap_lost_inlines();

HtmlDocument {
text: text.to_string(),
content,
engine: Engine::new(),
pages: Vec::new(),
Expand All @@ -90,10 +93,11 @@ impl HtmlDocument {
}
}

pub fn update(&mut self, content: &str) {
self.size = content.len();
self.content = XmlParser::new(content).parse();
pub fn update(&mut self, text: &str) {
self.size = text.len();
self.content = XmlParser::new(text).parse();
self.content.wrap_lost_inlines();
self.text = text.to_string();
self.pages.clear();
}

Expand Down Expand Up @@ -420,6 +424,12 @@ impl Document for HtmlDocument {
.and_then(|child| child.attr("content").map(|s| decode_entities(s).into_owned()))
}

fn save(&self, path: &str) -> Result<(), Error> {
let mut file = File::create(path)?;
file.write_all(self.text.as_bytes())
.map_err(Into::into)
}

fn is_reflowable(&self) -> bool {
true
}
Expand Down
Loading

0 comments on commit dbb6a6c

Please sign in to comment.