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