mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-27 03:15:07 +00:00
Cargo fmt
This commit is contained in:
parent
35eb1ec5a2
commit
14fe6f3b36
@ -19,11 +19,7 @@ use cursive::{Cursive, Printer};
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut siv = Cursive::default();
|
let mut siv = Cursive::default();
|
||||||
|
|
||||||
siv.add_layer(
|
siv.add_layer(Canvas::new(()).with_draw(draw).fixed_size((20, 10)));
|
||||||
Canvas::new(())
|
|
||||||
.with_draw(draw)
|
|
||||||
.fixed_size((20, 10)),
|
|
||||||
);
|
|
||||||
|
|
||||||
siv.add_global_callback('q', |s| s.quit());
|
siv.add_global_callback('q', |s| s.quit());
|
||||||
|
|
||||||
|
@ -9,11 +9,7 @@ use cursive::{Cursive, Printer};
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut siv = Cursive::default();
|
let mut siv = Cursive::default();
|
||||||
siv.add_layer(
|
siv.add_layer(KeyCodeView::new(10).full_width().fixed_height(10));
|
||||||
KeyCodeView::new(10)
|
|
||||||
.full_width()
|
|
||||||
.fixed_height(10),
|
|
||||||
);
|
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
}
|
}
|
||||||
|
@ -87,11 +87,8 @@ impl View for BufferView {
|
|||||||
|
|
||||||
fn draw(&self, printer: &Printer) {
|
fn draw(&self, printer: &Printer) {
|
||||||
// Print the end of the buffer
|
// Print the end of the buffer
|
||||||
for (i, line) in self.buffer
|
for (i, line) in
|
||||||
.iter()
|
self.buffer.iter().rev().take(printer.size.y).enumerate()
|
||||||
.rev()
|
|
||||||
.take(printer.size.y)
|
|
||||||
.enumerate()
|
|
||||||
{
|
{
|
||||||
printer.print((0, printer.size.y - 1 - i), line);
|
printer.print((0, printer.size.y - 1 - i), line);
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,7 @@ fn main() {
|
|||||||
let mut siv = Cursive::default();
|
let mut siv = Cursive::default();
|
||||||
|
|
||||||
let mut styled = StyledString::plain("Isn't ");
|
let mut styled = StyledString::plain("Isn't ");
|
||||||
styled.append(StyledString::styled(
|
styled.append(StyledString::styled("that ", Color::Dark(BaseColor::Red)));
|
||||||
"that ",
|
|
||||||
Color::Dark(BaseColor::Red),
|
|
||||||
));
|
|
||||||
styled.append(StyledString::styled(
|
styled.append(StyledString::styled(
|
||||||
"cool?",
|
"cool?",
|
||||||
Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold),
|
Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold),
|
||||||
|
@ -64,8 +64,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_mut(&mut self, pos: Vec2) -> Option<&mut Cell> {
|
fn get_mut(&mut self, pos: Vec2) -> Option<&mut Cell> {
|
||||||
self.cell_id(pos)
|
self.cell_id(pos).map(move |i| &mut self.cells[i])
|
||||||
.map(move |i| &mut self.cells[i])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_id(&self, pos: Vec2) -> Option<usize> {
|
pub fn cell_id(&self, pos: Vec2) -> Option<usize> {
|
||||||
|
@ -189,9 +189,7 @@ impl cursive::view::View for BoardView {
|
|||||||
Cell::Unknown => "[]",
|
Cell::Unknown => "[]",
|
||||||
Cell::Flag => "()",
|
Cell::Flag => "()",
|
||||||
Cell::Visible(n) => {
|
Cell::Visible(n) => {
|
||||||
[
|
[" ", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8"][n]
|
||||||
" ", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8"
|
|
||||||
][n]
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,11 +87,7 @@ fn phase_2(s: &mut Cursive) {
|
|||||||
// Let's prepare the progress bars...
|
// Let's prepare the progress bars...
|
||||||
let mut linear = LinearLayout::vertical();
|
let mut linear = LinearLayout::vertical();
|
||||||
for c in &counters {
|
for c in &counters {
|
||||||
linear.add_child(
|
linear.add_child(ProgressBar::new().max(n_max).with_value(c.clone()));
|
||||||
ProgressBar::new()
|
|
||||||
.max(n_max)
|
|
||||||
.with_value(c.clone()),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.pop_layer();
|
s.pop_layer();
|
||||||
|
@ -38,10 +38,6 @@ fn on_edit(siv: &mut Cursive, _content: &str, _cursor: usize) {
|
|||||||
let matches = edit_1.get_content() == edit_2.get_content();
|
let matches = edit_1.get_content() == edit_2.get_content();
|
||||||
|
|
||||||
siv.call_on_id("match", |v: &mut TextView| {
|
siv.call_on_id("match", |v: &mut TextView| {
|
||||||
v.set_content(if matches {
|
v.set_content(if matches { "match" } else { "no match" })
|
||||||
"match"
|
|
||||||
} else {
|
|
||||||
"no match"
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,7 @@ fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// We'll add a find feature!
|
// We'll add a find feature!
|
||||||
siv.add_layer(Dialog::info(
|
siv.add_layer(Dialog::info("Hint: press Ctrl-F to find in text!"));
|
||||||
"Hint: press Ctrl-F to find in text!",
|
|
||||||
));
|
|
||||||
|
|
||||||
siv.add_global_callback(Event::CtrlChar('f'), |s| {
|
siv.add_global_callback(Event::CtrlChar('f'), |s| {
|
||||||
// When Ctrl-F is pressed, show the Find popup.
|
// When Ctrl-F is pressed, show the Find popup.
|
||||||
|
@ -6,8 +6,7 @@ use cursive::Cursive;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut siv = Cursive::default();
|
let mut siv = Cursive::default();
|
||||||
// You can load a theme from a file at runtime for fast development.
|
// You can load a theme from a file at runtime for fast development.
|
||||||
siv.load_theme_file("assets/style.toml")
|
siv.load_theme_file("assets/style.toml").unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Or you can directly load it from a string for easy deployment.
|
// Or you can directly load it from a string for easy deployment.
|
||||||
// siv.load_theme(include_str!("../assets/style.toml")).unwrap();
|
// siv.load_theme(include_str!("../assets/style.toml")).unwrap();
|
||||||
|
@ -8,9 +8,7 @@ fn main() {
|
|||||||
let mut siv = Cursive::default();
|
let mut siv = Cursive::default();
|
||||||
|
|
||||||
let layout = LinearLayout::vertical()
|
let layout = LinearLayout::vertical()
|
||||||
.child(TextView::new(
|
.child(TextView::new("This is a dynamic theme example!"))
|
||||||
"This is a dynamic theme example!",
|
|
||||||
))
|
|
||||||
.child(EditView::new().content("Woo! colors!").style(
|
.child(EditView::new().content("Woo! colors!").style(
|
||||||
ColorStyle::new(
|
ColorStyle::new(
|
||||||
Color::Rgb(200, 150, 150),
|
Color::Rgb(200, 150, 150),
|
||||||
|
@ -11,12 +11,12 @@ use self::bear_lib_terminal::terminal::{
|
|||||||
};
|
};
|
||||||
use self::bear_lib_terminal::Color as BltColor;
|
use self::bear_lib_terminal::Color as BltColor;
|
||||||
use backend;
|
use backend;
|
||||||
|
use chan;
|
||||||
use event::{Event, Key, MouseButton, MouseEvent};
|
use event::{Event, Key, MouseButton, MouseEvent};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
use theme::{BaseColor, Color, ColorPair, Effect};
|
use theme::{BaseColor, Color, ColorPair, Effect};
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use chan;
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
enum ColorRole {
|
enum ColorRole {
|
||||||
Foreground,
|
Foreground,
|
||||||
@ -52,7 +52,6 @@ impl Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_next(&mut self) -> Option<Event> {
|
fn parse_next(&mut self) -> Option<Event> {
|
||||||
|
|
||||||
// TODO: we could add backend-specific controls here.
|
// TODO: we could add backend-specific controls here.
|
||||||
// Ex: ctrl+mouse wheel cause window cellsize to change
|
// Ex: ctrl+mouse wheel cause window cellsize to change
|
||||||
terminal::read_event().map(|ev| {
|
terminal::read_event().map(|ev| {
|
||||||
@ -99,7 +98,7 @@ impl Backend {
|
|||||||
offset: Vec2::zero(),
|
offset: Vec2::zero(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or(Event::Unknown(vec![]))
|
.unwrap_or(Event::Unknown(vec![]))
|
||||||
}
|
}
|
||||||
BltEvent::ShiftReleased | BltEvent::ControlReleased => {
|
BltEvent::ShiftReleased | BltEvent::ControlReleased => {
|
||||||
Event::Refresh
|
Event::Refresh
|
||||||
@ -306,7 +305,9 @@ impl backend::Backend for Backend {
|
|||||||
terminal::print_xy(pos.x as i32, pos.y as i32, text);
|
terminal::print_xy(pos.x as i32, pos.y as i32, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_input(&mut self, event_sink: &chan::Sender<Event>, timeout: Duration) {
|
fn prepare_input(
|
||||||
|
&mut self, event_sink: &chan::Sender<Event>, timeout: Duration,
|
||||||
|
) {
|
||||||
// Wait for up to `timeout_ms`.
|
// Wait for up to `timeout_ms`.
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
while start.elapsed() < timeout {
|
while start.elapsed() < timeout {
|
||||||
|
@ -13,11 +13,11 @@ use std::collections::HashMap;
|
|||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Write};
|
use std::io::Write;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use libc;
|
|
||||||
use chan;
|
use chan;
|
||||||
|
use libc;
|
||||||
|
|
||||||
pub struct Backend {
|
pub struct Backend {
|
||||||
current_style: Cell<ColorPair>,
|
current_style: Cell<ColorPair>,
|
||||||
@ -88,7 +88,8 @@ impl InputParser {
|
|||||||
let _alt = (mevent.bstate & ncurses::BUTTON_ALT as mmask_t) != 0;
|
let _alt = (mevent.bstate & ncurses::BUTTON_ALT as mmask_t) != 0;
|
||||||
let _ctrl = (mevent.bstate & ncurses::BUTTON_CTRL as mmask_t) != 0;
|
let _ctrl = (mevent.bstate & ncurses::BUTTON_CTRL as mmask_t) != 0;
|
||||||
|
|
||||||
mevent.bstate &= !(ncurses::BUTTON_SHIFT | ncurses::BUTTON_ALT
|
mevent.bstate &= !(ncurses::BUTTON_SHIFT
|
||||||
|
| ncurses::BUTTON_ALT
|
||||||
| ncurses::BUTTON_CTRL)
|
| ncurses::BUTTON_CTRL)
|
||||||
as mmask_t;
|
as mmask_t;
|
||||||
|
|
||||||
@ -248,7 +249,6 @@ impl Backend {
|
|||||||
let style = ncurses::COLOR_PAIR(i);
|
let style = ncurses::COLOR_PAIR(i);
|
||||||
ncurses::attron(style);
|
ncurses::attron(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl backend::Backend for Backend {
|
impl backend::Backend for Backend {
|
||||||
@ -263,7 +263,10 @@ impl backend::Backend for Backend {
|
|||||||
ncurses::has_colors()
|
ncurses::has_colors()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_input_thread(&mut self, event_sink: chan::Sender<Event>, stops: chan::Receiver<bool>) {
|
fn start_input_thread(
|
||||||
|
&mut self, event_sink: chan::Sender<Event>,
|
||||||
|
stops: chan::Receiver<bool>,
|
||||||
|
) {
|
||||||
let mut parser = InputParser::new(event_sink);
|
let mut parser = InputParser::new(event_sink);
|
||||||
|
|
||||||
// Start an input thread
|
// Start an input thread
|
||||||
|
@ -3,15 +3,15 @@ extern crate pancurses;
|
|||||||
use self::super::split_i32;
|
use self::super::split_i32;
|
||||||
use self::pancurses::mmask_t;
|
use self::pancurses::mmask_t;
|
||||||
use backend;
|
use backend;
|
||||||
|
use chan;
|
||||||
use event::{Event, Key, MouseButton, MouseEvent};
|
use event::{Event, Key, MouseButton, MouseEvent};
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::thread;
|
||||||
use theme::{Color, ColorPair, Effect};
|
use theme::{Color, ColorPair, Effect};
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use std::sync::Arc;
|
|
||||||
use chan;
|
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
pub struct Backend {
|
pub struct Backend {
|
||||||
// Used
|
// Used
|
||||||
@ -36,7 +36,9 @@ struct InputParser {
|
|||||||
unsafe impl Send for InputParser {}
|
unsafe impl Send for InputParser {}
|
||||||
|
|
||||||
impl InputParser {
|
impl InputParser {
|
||||||
fn new(event_sink: chan::Sender<Event>, window: Arc<pancurses::Window>) -> Self {
|
fn new(
|
||||||
|
event_sink: chan::Sender<Event>, window: Arc<pancurses::Window>,
|
||||||
|
) -> Self {
|
||||||
InputParser {
|
InputParser {
|
||||||
key_codes: initialize_keymap(),
|
key_codes: initialize_keymap(),
|
||||||
last_mouse_button: None,
|
last_mouse_button: None,
|
||||||
@ -48,21 +50,15 @@ impl InputParser {
|
|||||||
fn parse_next(&mut self) {
|
fn parse_next(&mut self) {
|
||||||
let event = if let Some(ev) = self.window.getch() {
|
let event = if let Some(ev) = self.window.getch() {
|
||||||
match ev {
|
match ev {
|
||||||
pancurses::Input::Character('\n') => {
|
pancurses::Input::Character('\n') => Event::Key(Key::Enter),
|
||||||
Event::Key(Key::Enter)
|
|
||||||
}
|
|
||||||
// TODO: wait for a very short delay. If more keys are
|
// TODO: wait for a very short delay. If more keys are
|
||||||
// pipelined, it may be an escape sequence.
|
// pipelined, it may be an escape sequence.
|
||||||
pancurses::Input::Character('\u{7f}')
|
pancurses::Input::Character('\u{7f}')
|
||||||
| pancurses::Input::Character('\u{8}') => {
|
| pancurses::Input::Character('\u{8}') => {
|
||||||
Event::Key(Key::Backspace)
|
Event::Key(Key::Backspace)
|
||||||
}
|
|
||||||
pancurses::Input::Character('\u{9}') => {
|
|
||||||
Event::Key(Key::Tab)
|
|
||||||
}
|
|
||||||
pancurses::Input::Character('\u{1b}') => {
|
|
||||||
Event::Key(Key::Esc)
|
|
||||||
}
|
}
|
||||||
|
pancurses::Input::Character('\u{9}') => Event::Key(Key::Tab),
|
||||||
|
pancurses::Input::Character('\u{1b}') => Event::Key(Key::Esc),
|
||||||
pancurses::Input::Character(c) if (c as u32) <= 26 => {
|
pancurses::Input::Character(c) if (c as u32) <= 26 => {
|
||||||
Event::CtrlChar((b'a' - 1 + c as u8) as char)
|
Event::CtrlChar((b'a' - 1 + c as u8) as char)
|
||||||
}
|
}
|
||||||
@ -85,9 +81,7 @@ impl InputParser {
|
|||||||
pancurses::Input::KeyLeft => Event::Key(Key::Left),
|
pancurses::Input::KeyLeft => Event::Key(Key::Left),
|
||||||
pancurses::Input::KeyRight => Event::Key(Key::Right),
|
pancurses::Input::KeyRight => Event::Key(Key::Right),
|
||||||
pancurses::Input::KeyHome => Event::Key(Key::Home),
|
pancurses::Input::KeyHome => Event::Key(Key::Home),
|
||||||
pancurses::Input::KeyBackspace => {
|
pancurses::Input::KeyBackspace => Event::Key(Key::Backspace),
|
||||||
Event::Key(Key::Backspace)
|
|
||||||
}
|
|
||||||
pancurses::Input::KeyF0 => Event::Key(Key::F0),
|
pancurses::Input::KeyF0 => Event::Key(Key::F0),
|
||||||
pancurses::Input::KeyF1 => Event::Key(Key::F1),
|
pancurses::Input::KeyF1 => Event::Key(Key::F1),
|
||||||
pancurses::Input::KeyF2 => Event::Key(Key::F2),
|
pancurses::Input::KeyF2 => Event::Key(Key::F2),
|
||||||
@ -171,9 +165,7 @@ impl InputParser {
|
|||||||
pancurses::Input::KeySMove => Event::Refresh,
|
pancurses::Input::KeySMove => Event::Refresh,
|
||||||
pancurses::Input::KeySNext => Event::Shift(Key::PageDown),
|
pancurses::Input::KeySNext => Event::Shift(Key::PageDown),
|
||||||
pancurses::Input::KeySOptions => Event::Refresh,
|
pancurses::Input::KeySOptions => Event::Refresh,
|
||||||
pancurses::Input::KeySPrevious => {
|
pancurses::Input::KeySPrevious => Event::Shift(Key::PageUp),
|
||||||
Event::Shift(Key::PageUp)
|
|
||||||
}
|
|
||||||
pancurses::Input::KeySPrint => Event::Refresh,
|
pancurses::Input::KeySPrint => Event::Refresh,
|
||||||
pancurses::Input::KeySRedo => Event::Refresh,
|
pancurses::Input::KeySRedo => Event::Refresh,
|
||||||
pancurses::Input::KeySReplace => Event::Refresh,
|
pancurses::Input::KeySReplace => Event::Refresh,
|
||||||
@ -219,7 +211,8 @@ impl InputParser {
|
|||||||
let _alt = (mevent.bstate & pancurses::BUTTON_ALT as mmask_t) != 0;
|
let _alt = (mevent.bstate & pancurses::BUTTON_ALT as mmask_t) != 0;
|
||||||
let _ctrl = (mevent.bstate & pancurses::BUTTON_CTRL as mmask_t) != 0;
|
let _ctrl = (mevent.bstate & pancurses::BUTTON_CTRL as mmask_t) != 0;
|
||||||
|
|
||||||
mevent.bstate &= !(pancurses::BUTTON_SHIFT | pancurses::BUTTON_ALT
|
mevent.bstate &= !(pancurses::BUTTON_SHIFT
|
||||||
|
| pancurses::BUTTON_ALT
|
||||||
| pancurses::BUTTON_CTRL) as mmask_t;
|
| pancurses::BUTTON_CTRL) as mmask_t;
|
||||||
|
|
||||||
let make_event = |event| Event::Mouse {
|
let make_event = |event| Event::Mouse {
|
||||||
@ -348,7 +341,6 @@ impl Backend {
|
|||||||
let style = pancurses::COLOR_PAIR(i as pancurses::chtype);
|
let style = pancurses::COLOR_PAIR(i as pancurses::chtype);
|
||||||
self.window.attron(style);
|
self.window.attron(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl backend::Backend for Backend {
|
impl backend::Backend for Backend {
|
||||||
@ -417,8 +409,12 @@ impl backend::Backend for Backend {
|
|||||||
self.window.mvaddstr(pos.y as i32, pos.x as i32, text);
|
self.window.mvaddstr(pos.y as i32, pos.x as i32, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_input_thread(&mut self, event_sink: chan::Sender<Event>, stops: chan::Receiver<bool>) {
|
fn start_input_thread(
|
||||||
let mut input_parser = InputParser::new(event_sink, Arc::clone(&self.window));
|
&mut self, event_sink: chan::Sender<Event>,
|
||||||
|
stops: chan::Receiver<bool>,
|
||||||
|
) {
|
||||||
|
let mut input_parser =
|
||||||
|
InputParser::new(event_sink, Arc::clone(&self.window));
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
@ -430,7 +426,6 @@ impl backend::Backend for Backend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,9 @@ impl backend::Backend for Backend {
|
|||||||
(1, 1).into()
|
(1, 1).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_input(&mut self, event_sink: &chan::Sender<event::Event>, _timeout: Duration) {
|
fn prepare_input(
|
||||||
|
&mut self, event_sink: &chan::Sender<event::Event>, _timeout: Duration,
|
||||||
|
) {
|
||||||
event_sink.send(event::Event::Exit)
|
event_sink.send(event::Event::Exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,9 @@ pub trait Backend {
|
|||||||
fn finish(&mut self);
|
fn finish(&mut self);
|
||||||
|
|
||||||
/// Starts a thread to collect input and send it to the given channel.
|
/// Starts a thread to collect input and send it to the given channel.
|
||||||
fn start_input_thread(&mut self, event_sink: Sender<event::Event>, running: Receiver<bool>) {
|
fn start_input_thread(
|
||||||
|
&mut self, event_sink: Sender<event::Event>, running: Receiver<bool>,
|
||||||
|
) {
|
||||||
// Dummy implementation for some backends.
|
// Dummy implementation for some backends.
|
||||||
let _ = event_sink;
|
let _ = event_sink;
|
||||||
let _ = running;
|
let _ = running;
|
||||||
@ -42,7 +44,9 @@ pub trait Backend {
|
|||||||
///
|
///
|
||||||
/// This is only required for non-thread-safe backends like BearLibTerminal
|
/// This is only required for non-thread-safe backends like BearLibTerminal
|
||||||
/// where we cannot collect input in a separate thread.
|
/// where we cannot collect input in a separate thread.
|
||||||
fn prepare_input(&mut self, event_sink: &Sender<event::Event>, timeout: Duration) {
|
fn prepare_input(
|
||||||
|
&mut self, event_sink: &Sender<event::Event>, timeout: Duration,
|
||||||
|
) {
|
||||||
// Dummy implementation for most backends.
|
// Dummy implementation for most backends.
|
||||||
// Little trick to avoid unused variables.
|
// Little trick to avoid unused variables.
|
||||||
let _ = event_sink;
|
let _ = event_sink;
|
||||||
|
@ -184,13 +184,11 @@ impl Backend {
|
|||||||
pub fn init() -> Box<Self> {
|
pub fn init() -> Box<Self> {
|
||||||
print!("{}", termion::cursor::Hide);
|
print!("{}", termion::cursor::Hide);
|
||||||
|
|
||||||
|
|
||||||
// TODO: lock stdout
|
// TODO: lock stdout
|
||||||
let terminal = AlternateScreen::from(MouseTerminal::from(
|
let terminal = AlternateScreen::from(MouseTerminal::from(
|
||||||
::std::io::stdout().into_raw_mode().unwrap(),
|
::std::io::stdout().into_raw_mode().unwrap(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
let c = Backend {
|
let c = Backend {
|
||||||
terminal: terminal,
|
terminal: terminal,
|
||||||
current_style: Cell::new(theme::ColorPair::from_256colors(0, 0)),
|
current_style: Cell::new(theme::ColorPair::from_256colors(0, 0)),
|
||||||
@ -265,7 +263,10 @@ impl backend::Backend for Backend {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_input_thread(&mut self, event_sink: chan::Sender<Event>, stops: chan::Receiver<bool>) {
|
fn start_input_thread(
|
||||||
|
&mut self, event_sink: chan::Sender<Event>,
|
||||||
|
stops: chan::Receiver<bool>,
|
||||||
|
) {
|
||||||
let mut parser = InputParser::new(event_sink);
|
let mut parser = InputParser::new(event_sink);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
|
@ -5,8 +5,8 @@ use event::{Callback, Event, EventResult};
|
|||||||
use printer::Printer;
|
use printer::Printer;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::time::Duration;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::time::Duration;
|
||||||
use theme;
|
use theme;
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::{self, Finder, IntoBoxedView, Position, View};
|
use view::{self, Finder, IntoBoxedView, Position, View};
|
||||||
@ -582,10 +582,11 @@ impl Cursive {
|
|||||||
let input_channel = &self.event_source;
|
let input_channel = &self.event_source;
|
||||||
let cb_channel = &self.cb_source;
|
let cb_channel = &self.cb_source;
|
||||||
|
|
||||||
self.backend.prepare_input(&self.event_sink, Duration::from_millis(30));
|
self.backend
|
||||||
|
.prepare_input(&self.event_sink, Duration::from_millis(30));
|
||||||
|
|
||||||
if self.fps > 0 {
|
if self.fps > 0 {
|
||||||
let timeout = 1000 / self.fps;
|
let timeout = 1000 / self.fps;
|
||||||
let timeout = chan::after_ms(timeout);
|
let timeout = chan::after_ms(timeout);
|
||||||
chan_select! {
|
chan_select! {
|
||||||
input_channel.recv() -> input => {
|
input_channel.recv() -> input => {
|
||||||
@ -726,7 +727,8 @@ impl Cursive {
|
|||||||
event, position, ..
|
event, position, ..
|
||||||
} = event
|
} = event
|
||||||
{
|
{
|
||||||
if event.grabs_focus() && !self.menubar.autohide
|
if event.grabs_focus()
|
||||||
|
&& !self.menubar.autohide
|
||||||
&& !self.menubar.has_submenu()
|
&& !self.menubar.has_submenu()
|
||||||
&& position.y == 0
|
&& position.y == 0
|
||||||
{
|
{
|
||||||
@ -743,7 +745,8 @@ impl Cursive {
|
|||||||
self.menubar.on_event(event).process(self);
|
self.menubar.on_event(event).process(self);
|
||||||
} else {
|
} else {
|
||||||
let offset = if self.menubar.autohide { 0 } else { 1 };
|
let offset = if self.menubar.autohide { 0 } else { 1 };
|
||||||
match self.screen_mut()
|
match self
|
||||||
|
.screen_mut()
|
||||||
.on_event(event.relativized((0, offset)))
|
.on_event(event.relativized((0, offset)))
|
||||||
{
|
{
|
||||||
// If the event was ignored,
|
// If the event was ignored,
|
||||||
@ -757,12 +760,11 @@ impl Cursive {
|
|||||||
// Ok, we processed the event.
|
// Ok, we processed the event.
|
||||||
// Now tell the backend whether he sould keep receiving.
|
// Now tell the backend whether he sould keep receiving.
|
||||||
self.stop_sink.send(!self.running);
|
self.stop_sink.send(!self.running);
|
||||||
},
|
}
|
||||||
Interruption::Callback(cb) => {
|
Interruption::Callback(cb) => {
|
||||||
cb.call_box(self);
|
cb.call_box(self);
|
||||||
},
|
|
||||||
Interruption::Timeout => {
|
|
||||||
}
|
}
|
||||||
|
Interruption::Timeout => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,10 +368,12 @@ impl Dialog {
|
|||||||
// Add some special effect to the focused button
|
// Add some special effect to the focused button
|
||||||
let position = Vec2::new(offset, y);
|
let position = Vec2::new(offset, y);
|
||||||
button.offset.set(position);
|
button.offset.set(position);
|
||||||
button.button.draw(&printer
|
button.button.draw(
|
||||||
.offset(position)
|
&printer
|
||||||
.cropped(size)
|
.offset(position)
|
||||||
.focused(self.focus == DialogFocus::Button(i)));
|
.cropped(size)
|
||||||
|
.focused(self.focus == DialogFocus::Button(i)),
|
||||||
|
);
|
||||||
// Keep 1 blank between two buttons
|
// Keep 1 blank between two buttons
|
||||||
offset += size.x + 1;
|
offset += size.x + 1;
|
||||||
// Also keep 1 blank above the buttons
|
// Also keep 1 blank above the buttons
|
||||||
@ -392,10 +394,12 @@ impl Dialog {
|
|||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.content.draw(&printer
|
self.content.draw(
|
||||||
.offset(self.borders.top_left() + self.padding.top_left())
|
&printer
|
||||||
.cropped(inner_size)
|
.offset(self.borders.top_left() + self.padding.top_left())
|
||||||
.focused(self.focus == DialogFocus::Content));
|
.cropped(inner_size)
|
||||||
|
.focused(self.focus == DialogFocus::Content),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_title(&self, printer: &Printer) {
|
fn draw_title(&self, printer: &Printer) {
|
||||||
@ -575,6 +579,7 @@ impl View for Dialog {
|
|||||||
|
|
||||||
fn important_area(&self, _: Vec2) -> Rect {
|
fn important_area(&self, _: Vec2) -> Rect {
|
||||||
self.content.important_area(self.content.size)
|
self.content.important_area(self.content.size)
|
||||||
+ self.borders.top_left() + self.padding.top_left()
|
+ self.borders.top_left()
|
||||||
|
+ self.padding.top_left()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,9 +273,9 @@ impl View for ListView {
|
|||||||
.draw(printer, |printer, i| match self.children[i] {
|
.draw(printer, |printer, i| match self.children[i] {
|
||||||
ListChild::Row(ref label, ref view) => {
|
ListChild::Row(ref label, ref view) => {
|
||||||
printer.print((0, 0), label);
|
printer.print((0, 0), label);
|
||||||
view.draw(&printer
|
view.draw(
|
||||||
.offset((offset, 0))
|
&printer.offset((offset, 0)).focused(i == self.focus),
|
||||||
.focused(i == self.focus));
|
);
|
||||||
}
|
}
|
||||||
ListChild::Delimiter => (),
|
ListChild::Delimiter => (),
|
||||||
});
|
});
|
||||||
@ -407,14 +407,10 @@ impl View for ListView {
|
|||||||
Event::Key(Key::PageDown) => {
|
Event::Key(Key::PageDown) => {
|
||||||
self.move_focus(10, direction::Direction::up())
|
self.move_focus(10, direction::Direction::up())
|
||||||
}
|
}
|
||||||
Event::Key(Key::Home) | Event::Ctrl(Key::Home) => self.move_focus(
|
Event::Key(Key::Home) | Event::Ctrl(Key::Home) => self
|
||||||
usize::max_value(),
|
.move_focus(usize::max_value(), direction::Direction::back()),
|
||||||
direction::Direction::back(),
|
Event::Key(Key::End) | Event::Ctrl(Key::End) => self
|
||||||
),
|
.move_focus(usize::max_value(), direction::Direction::front()),
|
||||||
Event::Key(Key::End) | Event::Ctrl(Key::End) => self.move_focus(
|
|
||||||
usize::max_value(),
|
|
||||||
direction::Direction::front(),
|
|
||||||
),
|
|
||||||
Event::Key(Key::Tab) => {
|
Event::Key(Key::Tab) => {
|
||||||
self.move_focus(1, direction::Direction::front())
|
self.move_focus(1, direction::Direction::front())
|
||||||
}
|
}
|
||||||
|
@ -107,26 +107,26 @@ impl<V> ScrollView<V> {
|
|||||||
pub fn scroll_x(self, enabled: bool) -> Self {
|
pub fn scroll_x(self, enabled: bool) -> Self {
|
||||||
self.with(|s| s.set_scroll_x(enabled))
|
self.with(|s| s.set_scroll_x(enabled))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Programmatically scroll to the top of the view.
|
/// Programmatically scroll to the top of the view.
|
||||||
pub fn scroll_to_top(&mut self) {
|
pub fn scroll_to_top(&mut self) {
|
||||||
let curr_x = self.offset.x;
|
let curr_x = self.offset.x;
|
||||||
self.set_offset((curr_x,0));
|
self.set_offset((curr_x, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Programmatically scroll to the bottom of the view.
|
/// Programmatically scroll to the bottom of the view.
|
||||||
pub fn scroll_to_bottom(&mut self) {
|
pub fn scroll_to_bottom(&mut self) {
|
||||||
let max_y = self.inner_size.saturating_sub(self.available_size()).y;
|
let max_y = self.inner_size.saturating_sub(self.available_size()).y;
|
||||||
let curr_x = self.offset.x;
|
let curr_x = self.offset.x;
|
||||||
self.set_offset((curr_x, max_y));
|
self.set_offset((curr_x, max_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Programmatically scroll to the leftmost side of the view.
|
/// Programmatically scroll to the leftmost side of the view.
|
||||||
pub fn scroll_to_left(&mut self) {
|
pub fn scroll_to_left(&mut self) {
|
||||||
let curr_y = self.offset.y;
|
let curr_y = self.offset.y;
|
||||||
self.set_offset((0, curr_y));
|
self.set_offset((0, curr_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Programmatically scroll to the rightmost side of the view.
|
/// Programmatically scroll to the rightmost side of the view.
|
||||||
pub fn scroll_to_right(&mut self) {
|
pub fn scroll_to_right(&mut self) {
|
||||||
let max_x = self.inner_size.saturating_sub(self.available_size()).x;
|
let max_x = self.inner_size.saturating_sub(self.available_size()).x;
|
||||||
|
@ -459,10 +459,12 @@ impl StackView {
|
|||||||
StackPositionIterator::new(self.layers.iter(), printer.size)
|
StackPositionIterator::new(self.layers.iter(), printer.size)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
{
|
{
|
||||||
v.view.draw(&printer
|
v.view.draw(
|
||||||
.offset(offset)
|
&printer
|
||||||
.cropped(v.size)
|
.offset(offset)
|
||||||
.focused(i + 1 == last));
|
.cropped(v.size)
|
||||||
|
.focused(i + 1 == last),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user