mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix clippy warnings
This commit is contained in:
parent
f4f2759df2
commit
7e9609826c
@ -28,7 +28,7 @@ impl KeyCodeView {
|
|||||||
impl View for KeyCodeView {
|
impl View for KeyCodeView {
|
||||||
fn draw(&self, printer: &Printer) {
|
fn draw(&self, printer: &Printer) {
|
||||||
for (y, line) in self.history.iter().enumerate() {
|
for (y, line) in self.history.iter().enumerate() {
|
||||||
printer.print((0, y), &line);
|
printer.print((0, y), line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ use cursive::prelude::*;
|
|||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::iter::Chain;
|
||||||
|
use std::slice::Iter;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// As usual, create the Cursive root
|
// As usual, create the Cursive root
|
||||||
@ -37,9 +39,8 @@ fn generate_logs(tx: mpsc::Sender<String>) {
|
|||||||
i += 1;
|
i += 1;
|
||||||
// The send will fail when the other side is dropped.
|
// The send will fail when the other side is dropped.
|
||||||
// (When the application ends).
|
// (When the application ends).
|
||||||
match tx.send(line) {
|
if tx.send(line).is_err() {
|
||||||
Err(_) => return,
|
return;
|
||||||
Ok(_) => (),
|
|
||||||
}
|
}
|
||||||
thread::sleep(Duration::from_millis(30));
|
thread::sleep(Duration::from_millis(30));
|
||||||
}
|
}
|
||||||
@ -76,10 +77,8 @@ impl BufferView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Chain together the two parts of the buffer to appear as a circular one.
|
// Chain together the two parts of the buffer to appear as a circular one.
|
||||||
// The signature is quite ugly, but basically we return an iterator:
|
// TODO: Use `-> impl Iterator<Item=String>`...
|
||||||
// a Chain of two slice iterators.
|
fn ring(&self) -> Chain<Iter<String>, Iter<String>> {
|
||||||
fn ring<'a>(&'a self)
|
|
||||||
-> std::iter::Chain<std::slice::Iter<'a, String>, std::slice::Iter<'a, String>> {
|
|
||||||
// The main buffer is "circular" starting at self.pos
|
// The main buffer is "circular" starting at self.pos
|
||||||
// So we chain the two parts as one
|
// So we chain the two parts as one
|
||||||
self.buffer[self.pos..].iter().chain(self.buffer[..self.pos].iter())
|
self.buffer[self.pos..].iter().chain(self.buffer[..self.pos].iter())
|
||||||
@ -94,9 +93,10 @@ impl View for BufferView {
|
|||||||
|
|
||||||
fn draw(&self, printer: &Printer) {
|
fn draw(&self, printer: &Printer) {
|
||||||
|
|
||||||
// If the buffer is large enough, we'll discard the beginning and keep the end.
|
// If the buffer is large, we'll discard the beginning and keep the end.
|
||||||
// If the buffer is too small, only print a part of it with an offset.
|
// If the buffer is too small, only print a part of it with an offset.
|
||||||
let (discard, offset) = if self.buffer.len() > printer.size.y as usize {
|
let (discard, offset) = if self.buffer.len() >
|
||||||
|
printer.size.y as usize {
|
||||||
(self.buffer.len() - printer.size.y as usize, 0)
|
(self.buffer.len() - printer.size.y as usize, 0)
|
||||||
} else {
|
} else {
|
||||||
(0, printer.size.y - self.buffer.len())
|
(0, printer.size.y - self.buffer.len())
|
||||||
|
@ -24,7 +24,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Let's put the callback in a separate function to keep it clean, but it's not required.
|
// Let's put the callback in a separate function to keep it clean, but it's not required.
|
||||||
fn show_next_window(siv: &mut Cursive, city: &String) {
|
fn show_next_window(siv: &mut Cursive, city: &str) {
|
||||||
siv.pop_layer();
|
siv.pop_layer();
|
||||||
let text = format!("{} is a great city!", city);
|
let text = format!("{} is a great city!", city);
|
||||||
siv.add_layer(Dialog::new(TextView::new(text))
|
siv.add_layer(Dialog::new(TextView::new(text))
|
||||||
|
Loading…
Reference in New Issue
Block a user