fix(clippy): clippy fixes (#1508)

* fix(clippy): clippy fixes

* chore(fmt): cargo fmt
This commit is contained in:
a-kenji 2022-06-15 14:03:11 +02:00 committed by GitHub
parent 7314b62321
commit 3de59dac42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 86 additions and 103 deletions

View file

@ -303,7 +303,7 @@ fn key_indicators(
}
pub fn superkey(palette: ColoredElements, separator: &str) -> LinePart {
let prefix_text = if separator.len() == 0 {
let prefix_text = if separator.is_empty() {
" Ctrl + "
} else {
" Ctrl +"

View file

@ -140,10 +140,9 @@ pub(crate) fn send_action_to_session(opts: zellij_utils::cli::CliArgs) {
fn attach_with_fake_client(opts: zellij_utils::cli::CliArgs, name: &str) {
if let Some(zellij_utils::cli::Command::Sessions(zellij_utils::cli::Sessions::Action {
action,
action: Some(action),
})) = opts.command.clone()
{
if let Some(action) = action.clone() {
let action = format!("[{}]", action);
match zellij_utils::serde_yaml::from_str::<ActionsFromYaml>(&action).into_diagnostic() {
Ok(parsed) => {
@ -154,8 +153,7 @@ fn attach_with_fake_client(opts: zellij_utils::cli::CliArgs, name: &str) {
process::exit(1);
},
};
let os_input =
get_os_input(zellij_client::os_input_output::get_client_os_input);
let os_input = get_os_input(zellij_client::os_input_output::get_client_os_input);
let actions = parsed.actions().to_vec();
log::debug!("Starting fake Zellij client!");
@ -176,7 +174,6 @@ fn attach_with_fake_client(opts: zellij_utils::cli::CliArgs, name: &str) {
std::process::exit(1);
},
};
}
};
}

View file

@ -57,10 +57,8 @@ fn assert_socket(name: &str) -> bool {
sender.send(ClientToServerMsg::ConnStatus);
let mut receiver: IpcReceiverWithContext<ServerToClientMsg> = sender.get_receiver();
match receiver.recv() {
Some((instruction, _)) => {
matches!(instruction, ServerToClientMsg::Connected)
},
None => false,
Some((ServerToClientMsg::Connected, _)) => true,
None | Some((_, _)) => false,
}
},
Err(e) if e.kind() == io::ErrorKind::ConnectionRefused => {

View file

@ -97,11 +97,7 @@ impl StdinAnsiParser {
Key::Alt(CharOrArrow::Char(']')) => true,
Key::Alt(CharOrArrow::Char('\\')) => true,
Key::Char(c) => {
if let '0'..='9' | 'a'..='f' = c {
true
} else {
false
}
matches!(c, '0'..='9' | 'a'..='f')
},
_ => false,
}
@ -117,7 +113,7 @@ pub enum AnsiStdinInstructionOrKeys {
}
impl AnsiStdinInstructionOrKeys {
pub fn pixel_dimensions_from_keys(keys: &Vec<(Key, Vec<u8>)>) -> Result<Self, &'static str> {
pub fn pixel_dimensions_from_keys(keys: &[(Key, Vec<u8>)]) -> Result<Self, &'static str> {
lazy_static! {
static ref RE: Regex = Regex::new(r"^\u{1b}\[(\d+);(\d+);(\d+)t$").unwrap();
}
@ -172,7 +168,7 @@ impl AnsiStdinInstructionOrKeys {
Err("invalid sequence")
}
}
pub fn color_sequence_from_keys(keys: &Vec<(Key, Vec<u8>)>) -> Result<Self, &'static str> {
pub fn color_sequence_from_keys(keys: &[(Key, Vec<u8>)]) -> Result<Self, &'static str> {
lazy_static! {
static ref BACKGROUND_RE: Regex = Regex::new(r"11;(.*)$").unwrap();
}
@ -180,9 +176,8 @@ impl AnsiStdinInstructionOrKeys {
static ref FOREGROUND_RE: Regex = Regex::new(r"10;(.*)$").unwrap();
}
let key_string = keys.iter().fold(String::new(), |mut acc, (key, _)| {
match key {
Key::Char(c) => acc.push(*c),
_ => {},
if let Key::Char(c) = key {
acc.push(*c)
};
acc
});

View file

@ -389,11 +389,10 @@ impl ServerOsApi for ServerOsInputOutput {
None
}
fn write_to_file(&mut self, buf: String, name: Option<String>) {
let mut f: File;
match name {
Some(x) => f = File::create(x).unwrap(),
None => f = tempfile().unwrap(),
}
let mut f: File = match name {
Some(x) => File::create(x).unwrap(),
None => tempfile().unwrap(),
};
if let Err(e) = write!(f, "{}", buf) {
log::error!("could not write to file: {}", e);
}

View file

@ -720,12 +720,10 @@ impl Grid {
}
self.cursor.y = new_cursor_y;
self.cursor.x = new_cursor_x;
self.saved_cursor_position
.as_mut()
.map(|saved_cursor_position| {
if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
saved_cursor_position.y = new_cursor_y;
saved_cursor_position.x = new_cursor_x;
});
};
} else if new_columns != self.width
&& self.alternate_lines_above_viewport_and_cursor.is_some()
{
@ -750,24 +748,22 @@ impl Grid {
);
let rows_pulled = self.viewport.len() - current_viewport_row_count;
self.cursor.y += rows_pulled;
self.saved_cursor_position
.as_mut()
.map(|saved_cursor_position| saved_cursor_position.y += rows_pulled);
if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
saved_cursor_position.y += rows_pulled
};
},
Ordering::Greater => {
let row_count_to_transfer = current_viewport_row_count - new_rows;
if row_count_to_transfer > self.cursor.y {
self.cursor.y = 0;
self.saved_cursor_position
.as_mut()
.map(|saved_cursor_position| saved_cursor_position.y = 0);
if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
saved_cursor_position.y = 0
};
} else {
self.cursor.y -= row_count_to_transfer;
self.saved_cursor_position
.as_mut()
.map(|saved_cursor_position| {
if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
saved_cursor_position.y -= row_count_to_transfer
});
};
}
if self.alternate_lines_above_viewport_and_cursor.is_none() {
transfer_rows_from_viewport_to_lines_above(
@ -868,7 +864,7 @@ impl Grid {
pub fn rotate_scroll_region_up(&mut self, count: usize) {
if let Some((scroll_region_top, scroll_region_bottom)) = self
.scroll_region
.or(Some((0, self.height.saturating_sub(1))))
.or_else(|| Some((0, self.height.saturating_sub(1))))
{
self.pad_lines_until(scroll_region_bottom, EMPTY_TERMINAL_CHARACTER);
for _ in 0..count {
@ -889,7 +885,7 @@ impl Grid {
pub fn rotate_scroll_region_down(&mut self, count: usize) {
if let Some((scroll_region_top, scroll_region_bottom)) = self
.scroll_region
.or(Some((0, self.height.saturating_sub(1))))
.or_else(|| Some((0, self.height.saturating_sub(1))))
{
self.pad_lines_until(scroll_region_bottom, EMPTY_TERMINAL_CHARACTER);
let mut pad_character = EMPTY_TERMINAL_CHARACTER;

View file

@ -50,8 +50,7 @@ impl LinkHandler {
}
pub fn output_osc8(&self, link_anchor: Option<LinkAnchor>) -> Option<String> {
link_anchor
.map(|link| match link {
link_anchor.and_then(|link| match link {
LinkAnchor::Start(index) => {
let link = self.links.get(&index);
@ -74,7 +73,6 @@ impl LinkHandler {
},
LinkAnchor::End => Some(format!("\u{1b}]8;;{}", TERMINATOR)),
})
.flatten()
}
}

View file

@ -36,6 +36,7 @@ pub enum PaneId {
// FIXME: This should hold an os_api handle so that terminal panes can set their own size via FD in
// their `reflow_lines()` method. Drop a Box<dyn ServerOsApi> in here somewhere.
#[allow(clippy::too_many_arguments)]
pub struct TerminalPane {
pub grid: Grid,
pub pid: RawFd,
@ -488,6 +489,7 @@ impl Pane for TerminalPane {
}
impl TerminalPane {
#[allow(clippy::too_many_arguments)]
pub fn new(
pid: RawFd,
position_and_size: PaneGeom,

View file

@ -792,7 +792,7 @@ impl Screen {
self.render();
}
fn unblock_input(&self) -> () {
fn unblock_input(&self) {
self.bus
.senders
.send_to_server(ServerInstruction::UnblockInputThread)

View file

@ -844,8 +844,7 @@ impl Tab {
|| self
.suppressed_panes
.values()
.find(|s_p| s_p.pid() == PaneId::Terminal(pid))
.is_some()
.any(|s_p| s_p.pid() == PaneId::Terminal(pid))
}
pub fn handle_pty_bytes(&mut self, pid: RawFd, bytes: VteBytes) {
if let Some(terminal_output) = self

View file

@ -90,11 +90,10 @@ impl ServerOsApi for FakeInputOutput {
unimplemented!()
}
fn write_to_file(&mut self, buf: String, name: Option<String>) {
let f: String;
match name {
Some(x) => f = x,
None => f = "tmp-name".to_owned(),
}
let f: String = match name {
Some(x) => x,
None => "tmp-name".to_owned(),
};
self.file_dumps.lock().unwrap().insert(f, buf);
}
}