mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix clippy lints
This commit is contained in:
parent
b7d71e8381
commit
349756e514
@ -8,16 +8,14 @@ use crate::vec::Vec2;
|
|||||||
use crate::{backend, theme};
|
use crate::{backend, theme};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor, execute, input, queue, terminal, AlternateScreen, AsyncReader,
|
cursor, execute, input, queue, terminal, AlternateScreen, AsyncReader,
|
||||||
Attribute, Clear, ClearType, Color, Colored, Command, Goto, Hide,
|
Attribute, Clear, ClearType, Color, Goto, InputEvent as CInputEvent,
|
||||||
InputEvent as CInputEvent, KeyEvent as CKeyEvent,
|
KeyEvent as CKeyEvent, MouseButton as CMouseButton,
|
||||||
MouseButton as CMouseButton, MouseEvent as CMouseEvent, Output, RawScreen,
|
MouseEvent as CMouseEvent, SetAttr, SetBg, SetFg, Show, Terminal,
|
||||||
SetAttr, SetBg, SetFg, Show, Terminal, TerminalCursor,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::event::{Event, Key, MouseButton, MouseEvent};
|
use crate::event::{Event, Key, MouseButton, MouseEvent};
|
||||||
use core::borrow::BorrowMut;
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::io::{self, BufWriter, Stdout, StdoutLock, Write};
|
use std::io::{self, BufWriter, Stdout, Write};
|
||||||
|
|
||||||
/// Backend using crossterm
|
/// Backend using crossterm
|
||||||
pub struct Backend {
|
pub struct Backend {
|
||||||
@ -27,7 +25,6 @@ pub struct Backend {
|
|||||||
async_reader: AsyncReader,
|
async_reader: AsyncReader,
|
||||||
_alternate_screen: AlternateScreen,
|
_alternate_screen: AlternateScreen,
|
||||||
stdout: RefCell<BufWriter<Stdout>>,
|
stdout: RefCell<BufWriter<Stdout>>,
|
||||||
cursor: TerminalCursor,
|
|
||||||
terminal: Terminal,
|
terminal: Terminal,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,17 +49,18 @@ impl Backend {
|
|||||||
_alternate_screen,
|
_alternate_screen,
|
||||||
stdout: RefCell::new(BufWriter::new(io::stdout())),
|
stdout: RefCell::new(BufWriter::new(io::stdout())),
|
||||||
terminal: terminal(),
|
terminal: terminal(),
|
||||||
cursor: cursor(),
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_colors(&self, colors: theme::ColorPair) {
|
fn apply_colors(&self, colors: theme::ColorPair) {
|
||||||
with_color(colors.front, |c| {
|
with_color(colors.front, |c| {
|
||||||
queue!(self.stdout.borrow_mut(), SetFg(*c))
|
queue!(self.stdout.borrow_mut(), SetFg(*c))
|
||||||
});
|
})
|
||||||
|
.unwrap();
|
||||||
with_color(colors.back, |c| {
|
with_color(colors.back, |c| {
|
||||||
queue!(self.stdout.borrow_mut(), SetBg(*c))
|
queue!(self.stdout.borrow_mut(), SetBg(*c))
|
||||||
});
|
})
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write<T>(&self, content: T)
|
fn write<T>(&self, content: T)
|
||||||
@ -74,7 +72,7 @@ impl Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_attr(&self, attr: Attribute) {
|
fn set_attr(&self, attr: Attribute) {
|
||||||
queue!(self.stdout.borrow_mut(), SetAttr(attr));
|
queue!(self.stdout.borrow_mut(), SetAttr(attr)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_key(&mut self, event: CInputEvent) -> Event {
|
fn map_key(&mut self, event: CInputEvent) -> Event {
|
||||||
@ -183,7 +181,8 @@ impl backend::Backend for Backend {
|
|||||||
SetFg(Color::Reset),
|
SetFg(Color::Reset),
|
||||||
SetAttr(Attribute::Reset),
|
SetAttr(Attribute::Reset),
|
||||||
Show
|
Show
|
||||||
);
|
)
|
||||||
|
.unwrap();
|
||||||
input().disable_mouse_mode().unwrap();
|
input().disable_mouse_mode().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use crate::backend::puppet::observed::ObservedStyle;
|
|||||||
use crate::event::Event;
|
use crate::event::Event;
|
||||||
use crate::theme;
|
use crate::theme;
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use std::cell::RefCell;
|
use std::cell::{Cell, RefCell};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
@ -25,7 +25,7 @@ pub struct Backend {
|
|||||||
inner_receiver: Receiver<Option<Event>>,
|
inner_receiver: Receiver<Option<Event>>,
|
||||||
prev_frame: RefCell<Option<ObservedScreen>>,
|
prev_frame: RefCell<Option<ObservedScreen>>,
|
||||||
current_frame: RefCell<ObservedScreen>,
|
current_frame: RefCell<ObservedScreen>,
|
||||||
size: RefCell<Vec2>,
|
size: Cell<Vec2>,
|
||||||
current_style: RefCell<Rc<ObservedStyle>>,
|
current_style: RefCell<Rc<ObservedStyle>>,
|
||||||
screen_channel: (Sender<ObservedScreen>, Receiver<ObservedScreen>),
|
screen_channel: (Sender<ObservedScreen>, Receiver<ObservedScreen>),
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ impl Backend {
|
|||||||
inner_receiver,
|
inner_receiver,
|
||||||
prev_frame: RefCell::new(None),
|
prev_frame: RefCell::new(None),
|
||||||
current_frame: RefCell::new(ObservedScreen::new(size)),
|
current_frame: RefCell::new(ObservedScreen::new(size)),
|
||||||
size: RefCell::new(size),
|
size: Cell::new(size),
|
||||||
current_style: RefCell::new(Rc::new(
|
current_style: RefCell::new(Rc::new(
|
||||||
DEFAULT_OBSERVED_STYLE.clone(),
|
DEFAULT_OBSERVED_STYLE.clone(),
|
||||||
)),
|
)),
|
||||||
@ -87,7 +87,7 @@ impl backend::Backend for Backend {
|
|||||||
fn finish(&mut self) {}
|
fn finish(&mut self) {}
|
||||||
|
|
||||||
fn refresh(&mut self) {
|
fn refresh(&mut self) {
|
||||||
let size = self.size.get_mut().clone();
|
let size = self.size.get();
|
||||||
let current_frame =
|
let current_frame =
|
||||||
self.current_frame.replace(ObservedScreen::new(size));
|
self.current_frame.replace(ObservedScreen::new(size));
|
||||||
self.prev_frame.replace(Some(current_frame.clone()));
|
self.prev_frame.replace(Some(current_frame.clone()));
|
||||||
@ -99,7 +99,7 @@ impl backend::Backend for Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn screen_size(&self) -> Vec2 {
|
fn screen_size(&self) -> Vec2 {
|
||||||
self.size.borrow().clone()
|
self.size.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_at(&self, pos: Vec2, text: &str) {
|
fn print_at(&self, pos: Vec2, text: &str) {
|
||||||
|
@ -31,24 +31,24 @@ pub enum GraphemePart {
|
|||||||
impl GraphemePart {
|
impl GraphemePart {
|
||||||
/// Returns true iff GraphemePart is Continuation
|
/// Returns true iff GraphemePart is Continuation
|
||||||
pub fn is_continuation(&self) -> bool {
|
pub fn is_continuation(&self) -> bool {
|
||||||
match self {
|
match *self {
|
||||||
&GraphemePart::Continuation => true,
|
GraphemePart::Continuation => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Some(String) if GraphemePart is Begin(String), else None.
|
/// Returns Some(String) if GraphemePart is Begin(String), else None.
|
||||||
pub fn as_option(&self) -> Option<&String> {
|
pub fn as_option(&self) -> Option<&String> {
|
||||||
match self {
|
match *self {
|
||||||
&GraphemePart::Begin(ref string) => Some(string),
|
GraphemePart::Begin(ref string) => Some(string),
|
||||||
&GraphemePart::Continuation => None,
|
GraphemePart::Continuation => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns String if GraphemePart is Begin(String), panics otherwise.
|
/// Returns String if GraphemePart is Begin(String), panics otherwise.
|
||||||
pub fn unwrap(&self) -> String {
|
pub fn unwrap(&self) -> String {
|
||||||
match self {
|
match *self {
|
||||||
&GraphemePart::Begin(ref s) => s.clone(),
|
GraphemePart::Begin(ref s) => s.clone(),
|
||||||
_ => panic!("unwrapping GraphemePart::Continuation"),
|
_ => panic!("unwrapping GraphemePart::Continuation"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,8 +199,7 @@ impl ObservedScreen {
|
|||||||
loop {
|
loop {
|
||||||
let pattern_symbol = pattern
|
let pattern_symbol = pattern
|
||||||
.graphemes(true)
|
.graphemes(true)
|
||||||
.skip(pattern_cursor)
|
.nth(pattern_cursor)
|
||||||
.next()
|
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
panic!(
|
panic!(
|
||||||
"Found no char at cursor {} in {}",
|
"Found no char at cursor {} in {}",
|
||||||
@ -277,10 +276,11 @@ pub trait ObservedPieceInterface {
|
|||||||
for x in self.min().x..self.max().x {
|
for x in self.min().x..self.max().x {
|
||||||
match &self.parent()[Vec2::new(x, y)] {
|
match &self.parent()[Vec2::new(x, y)] {
|
||||||
None => s.push(' '),
|
None => s.push(' '),
|
||||||
Some(cell) => match &cell.letter {
|
Some(cell) => {
|
||||||
GraphemePart::Begin(lex) => s.push_str(&lex),
|
if let GraphemePart::Begin(lex) = &cell.letter {
|
||||||
_ => {}
|
s.push_str(&lex);
|
||||||
},
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.push(s);
|
v.push(s);
|
||||||
|
@ -15,7 +15,7 @@ use crate::vec::Vec2;
|
|||||||
use crate::view::{self, Finder, IntoBoxedView, Position, View};
|
use crate::view::{self, Finder, IntoBoxedView, Position, View};
|
||||||
use crate::views::{self, LayerPosition};
|
use crate::views::{self, LayerPosition};
|
||||||
|
|
||||||
static DEBUG_VIEW_ID: &'static str = "_cursive_debug_view";
|
static DEBUG_VIEW_ID: &str = "_cursive_debug_view";
|
||||||
|
|
||||||
// How long we wait between two empty input polls
|
// How long we wait between two empty input polls
|
||||||
const INPUT_POLL_DELAY_MS: u64 = 30;
|
const INPUT_POLL_DELAY_MS: u64 = 30;
|
||||||
|
Loading…
Reference in New Issue
Block a user