Update Readme & run rustfmt

This commit is contained in:
Alexandre Bury 2016-06-25 16:36:22 -07:00
parent 8d24df5f59
commit 58bd274df0
21 changed files with 228 additions and 212 deletions

View File

@ -59,8 +59,6 @@ _(Colors may depend on your terminal configuration.)_
First off, terminals are messy. A small set of features is standard, but beyond that, almost every terminal has its own implementation.
I mostly test VTE-based terminals (Gnome & Xfce), with the occasional Konsole and xterm checks.
### Output
* **Colors**: the basic 8-colors palette should be broadly supported. User-defined colors is not supported in the raw linux TTY, but should work in most terminals, although it's still kinda experimental.
@ -73,7 +71,7 @@ Also, Cursive currently expects every codepoint to be a one-column character, so
* Keep in mind that if the terminal has shortcuts registered, they probably won't be transmitted to the app.
* UTF-8 input should work fine in a unicode-enabled terminal emulator, but raw linux TTY may be more capricious.
Here is the support table for input keys (All means Linux TTY and terminal emulators):
Here is the support table for input keys. Tested terminals are mostly Gnome terminal and Linux TTY, xterm, and a few others now and then.
| | Key | Shift+Key | Ctrl+Key | Shift+Ctrl+Key |
|--------------------------|:----:|:----------------------:|:--------------------------:|:---------------:|
@ -86,9 +84,10 @@ Here is the support table for input keys (All means Linux TTY and terminal emula
| Ins | All | None (paste clipboard) | Xterm | None |
| Del | All | VTE+Xterm | VTE+Xterm | VTE+Xterm |
| Home, End | All | Xterm | Xterm | Xterm |
| PageUp, PageDown | All | None | Xterm | None |
| Fn keys: F1-F4 | All | None (WIP) | None (WIP) | None (WIP) |
| Fn keys: F5-F12 | All | VTE+Xterm (WIP) | VTE+Xterm (WIP) | VTE+Xterm (WIP) |
| PageUp, PageDown | All | All | All | None |
| Fn keys: F1-F4 | All | All except Konsole | Gnome+XTerm | Gnome+Xterm |
| Fn keys: F5-F8 | All | All | All except TTY | All except TTY |
| Fn keys: F9-F12 | All | All except TTY | All except TTY | All except TTY |
| PrtScn, ScrollLock | None | None | None | None |
| Window, Menu | None | None | None | None |
@ -97,5 +96,6 @@ Here is the support table for input keys (All means Linux TTY and terminal emula
You want to help? Great! Here is a non-exhaustive list of things you could do:
* Provide example use-case: a good idea of application for existing or new components.
* Check compatibility: run the `key_codes` example on your favorite terminal, and report the results!
* Test and reports issues: a bug won't get fixed if we don't know it's there.
* Hack the code! If you feel confident with rust, pick an issue you like and hack away!

View File

@ -131,10 +131,10 @@ impl Key {
ncurses::KEY_SEND => Key::ShiftEnd,
ncurses::KEY_SDC => Key::ShiftDel,
// All Fn keys use the same enum with associated number
f @ ncurses::KEY_F1 ... ncurses::KEY_F15 => Key::F((f - ncurses::KEY_F0) as u8),
f @ 281 ... 291 => Key::ShiftF((f - 281 + 5) as u8),
f @ 293 ... 303 => Key::CtrlF((f - 293 + 5) as u8),
f @ 305 ... 315 => Key::CtrlShiftF((f - 305 + 5) as u8),
f @ ncurses::KEY_F1...ncurses::KEY_F12 => Key::F((f - ncurses::KEY_F0) as u8),
f @ 277...288 => Key::ShiftF((f - 281 + 5) as u8),
f @ 289...300 => Key::CtrlF((f - 293 + 5) as u8),
f @ 301...312 => Key::CtrlShiftF((f - 305 + 5) as u8),
// Shift and Ctrl F{1-4} need escape sequences...
//
// TODO: shift and ctrl Fn keys
@ -154,7 +154,8 @@ impl fmt::Display for Key {
Key::ShiftF(n) => write!(f, "Shift-F{}", n),
Key::CtrlF(n) => write!(f, "Ctrl-F{}", n),
Key::CtrlShiftF(n) => write!(f, "Ctrl-Shift-F{}", n),
key => write!(f,
key => {
write!(f,
"{}",
match key {
Key::NumpadCenter => "Numpad center",
@ -198,7 +199,8 @@ impl fmt::Display for Key {
Key::CtrlIns => "Ctrl-Ins",
Key::Esc => "Esc",
_ => "Missing key label",
}),
})
}
}
}
}

View File

@ -86,10 +86,12 @@ impl Theme {
}
match table.get("borders") {
Some(&toml::Value::String(ref borders)) => match BorderStyle::from(borders) {
Some(&toml::Value::String(ref borders)) => {
match BorderStyle::from(borders) {
Some(borders) => self.borders = borders,
None => (),
},
}
}
_ => (),
}
@ -261,14 +263,18 @@ impl Color {
Some(&toml::Value::String(ref value)) => {
self.load_value(value, new_id);
}
Some(&toml::Value::Array(ref array)) => for color in array.iter() {
Some(&toml::Value::Array(ref array)) => {
for color in array.iter() {
match color {
&toml::Value::String(ref color) => if self.load_value(color, new_id) {
&toml::Value::String(ref color) => {
if self.load_value(color, new_id) {
return;
},
}
}
_ => (),
}
},
}
}
_ => (),
}
}

View File

@ -26,7 +26,6 @@ impl <T: View> BoxView<T> {
}
impl<T: View> ViewWrapper for BoxView<T> {
wrap_impl!(&self.view);
fn wrap_get_min_size(&self, mut req: SizeRequest) -> Vec2 {

View File

@ -27,7 +27,6 @@ impl Button {
}
impl View for Button {
fn draw(&mut self, printer: &Printer) {
let style = if !printer.focused {
ColorPair::Primary

View File

@ -97,7 +97,6 @@ impl Dialog {
self
}
}
impl View for Dialog {
@ -207,8 +206,10 @@ impl View for Dialog {
fn on_event(&mut self, event: Event) -> EventResult {
match self.focus {
// If we are on the content, we can only go down.
Focus::Content => match self.content.on_event(event) {
EventResult::Ignored if !self.buttons.is_empty() => match event {
Focus::Content => {
match self.content.on_event(event) {
EventResult::Ignored if !self.buttons.is_empty() => {
match event {
Event::KeyEvent(Key::Down) => {
// Default to leftmost button when going down.
self.focus = Focus::Button(0);
@ -219,12 +220,16 @@ impl View for Dialog {
EventResult::Consumed(None)
}
_ => EventResult::Ignored,
},
}
}
res => res,
},
}
}
// If we are on a button, we have more choice
Focus::Button(i) => match self.buttons[i].on_event(event) {
EventResult::Ignored => match event {
Focus::Button(i) => {
match self.buttons[i].on_event(event) {
EventResult::Ignored => {
match event {
// Up goes back to the content
Event::KeyEvent(Key::Up) => {
if self.content.take_focus() {
@ -252,9 +257,11 @@ impl View for Dialog {
EventResult::Consumed(None)
}
_ => EventResult::Ignored,
},
}
}
res => res,
},
}
}
}
}

View File

@ -32,7 +32,7 @@ impl EditView {
cursor: 0,
offset: 0,
min_length: 1,
last_length: 0, /* scrollable: false, */
last_length: 0, // scrollable: false,
}
}
@ -138,7 +138,8 @@ impl View for EditView {
// TODO: handle wide (CJK) chars
self.cursor += 1;
}
Event::KeyEvent(key) => match key {
Event::KeyEvent(key) => {
match key {
Key::Home => self.cursor = 0,
Key::End => self.cursor = self.content.chars().count(),
Key::Left if self.cursor > 0 => self.cursor -= 1,
@ -151,7 +152,8 @@ impl View for EditView {
remove_char(&mut self.content, self.cursor);
}
_ => return EventResult::Ignored,
},
}
}
}
// Keep cursor in [offset, offset+last_length] by changing offset

View File

@ -33,17 +33,17 @@ impl KeyEventView {
}
impl ViewWrapper for KeyEventView {
wrap_impl!(self.content);
fn wrap_on_event(&mut self, event: Event) -> EventResult {
match self.content.on_event(event) {
EventResult::Ignored => match self.callbacks.get(&event) {
EventResult::Ignored => {
match self.callbacks.get(&event) {
None => EventResult::Ignored,
Some(cb) => EventResult::Consumed(Some(cb.clone())),
},
}
}
res => res,
}
}
}

View File

@ -180,7 +180,8 @@ impl View for LinearLayout {
fn on_event(&mut self, event: Event) -> EventResult {
match self.children[self.focus].view.on_event(event) {
EventResult::Ignored => match event {
EventResult::Ignored => {
match event {
Event::KeyEvent(Key::Tab) if self.focus > 0 => {
self.focus -= 1;
EventResult::Consumed(None)
@ -210,7 +211,8 @@ impl View for LinearLayout {
EventResult::Consumed(None)
}
_ => EventResult::Ignored,
},
}
}
res => res,
}
}

View File

@ -60,8 +60,7 @@ pub trait View {
/// Called once the size for this view has been decided, so it can
/// propagate the information to its children.
fn layout(&mut self, Vec2) {
}
fn layout(&mut self, Vec2) {}
/// Draws the view with the given printer (includes bounds) and focus.
fn draw(&mut self, printer: &Printer);

View File

@ -118,7 +118,6 @@ impl SelectView<String> {
pub fn item_str(self, label: &str) -> Self {
self.item(label, label.to_string())
}
}
impl<T: 'static> View for SelectView<T> {
@ -175,8 +174,9 @@ impl <T: 'static> View for SelectView<T> {
Event::KeyEvent(Key::Up) if self.focus > 0 => self.focus -= 1,
Event::KeyEvent(Key::Down) if self.focus + 1 < self.items.len() => self.focus += 1,
Event::KeyEvent(Key::PageUp) => self.focus -= min(self.focus, 10),
Event::KeyEvent(Key::PageDown) =>
self.focus = min(self.focus + 10, self.items.len() - 1),
Event::KeyEvent(Key::PageDown) => {
self.focus = min(self.focus + 10, self.items.len() - 1)
}
Event::KeyEvent(Key::Home) => self.focus = 0,
Event::KeyEvent(Key::End) => self.focus = self.items.len() - 1,
Event::KeyEvent(Key::Enter) if self.select_cb.is_some() => {

View File

@ -19,7 +19,6 @@ impl <T: View> ShadowView<T> {
}
impl<T: View> ViewWrapper for ShadowView<T> {
wrap_impl!(&self.view);
fn wrap_get_min_size(&self, req: SizeRequest) -> Vec2 {

View File

@ -146,7 +146,6 @@ impl <'a> LinesIterator<'a> {
}
impl<'a> Iterator for LinesIterator<'a> {
type Item = Row;
fn next(&mut self) -> Option<Row> {
@ -230,10 +229,12 @@ impl View for TextView {
match event {
Event::KeyEvent(Key::Home) => self.scrollbase.scroll_top(),
Event::KeyEvent(Key::End) => self.scrollbase.scroll_bottom(),
Event::KeyEvent(Key::Up) if self.scrollbase.can_scroll_up() =>
self.scrollbase.scroll_up(1),
Event::KeyEvent(Key::Down) if self.scrollbase.can_scroll_down() =>
self.scrollbase.scroll_down(1),
Event::KeyEvent(Key::Up) if self.scrollbase.can_scroll_up() => {
self.scrollbase.scroll_up(1)
}
Event::KeyEvent(Key::Down) if self.scrollbase.can_scroll_down() => {
self.scrollbase.scroll_down(1)
}
Event::KeyEvent(Key::PageDown) => self.scrollbase.scroll_down(10),
Event::KeyEvent(Key::PageUp) => self.scrollbase.scroll_up(10),
_ => return EventResult::Ignored,