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 { pub fn superkey(palette: ColoredElements, separator: &str) -> LinePart {
let prefix_text = if separator.len() == 0 { let prefix_text = if separator.is_empty() {
" Ctrl + " " Ctrl + "
} else { } else {
" Ctrl +" " 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) { 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 { if let Some(zellij_utils::cli::Command::Sessions(zellij_utils::cli::Sessions::Action {
action, action: Some(action),
})) = opts.command.clone() })) = opts.command.clone()
{ {
if let Some(action) = action.clone() {
let action = format!("[{}]", action); let action = format!("[{}]", action);
match zellij_utils::serde_yaml::from_str::<ActionsFromYaml>(&action).into_diagnostic() { match zellij_utils::serde_yaml::from_str::<ActionsFromYaml>(&action).into_diagnostic() {
Ok(parsed) => { Ok(parsed) => {
@ -154,8 +153,7 @@ fn attach_with_fake_client(opts: zellij_utils::cli::CliArgs, name: &str) {
process::exit(1); process::exit(1);
}, },
}; };
let os_input = let os_input = get_os_input(zellij_client::os_input_output::get_client_os_input);
get_os_input(zellij_client::os_input_output::get_client_os_input);
let actions = parsed.actions().to_vec(); let actions = parsed.actions().to_vec();
log::debug!("Starting fake Zellij client!"); 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); std::process::exit(1);
}, },
}; };
}
}; };
} }

View file

@ -57,10 +57,8 @@ fn assert_socket(name: &str) -> bool {
sender.send(ClientToServerMsg::ConnStatus); sender.send(ClientToServerMsg::ConnStatus);
let mut receiver: IpcReceiverWithContext<ServerToClientMsg> = sender.get_receiver(); let mut receiver: IpcReceiverWithContext<ServerToClientMsg> = sender.get_receiver();
match receiver.recv() { match receiver.recv() {
Some((instruction, _)) => { Some((ServerToClientMsg::Connected, _)) => true,
matches!(instruction, ServerToClientMsg::Connected) None | Some((_, _)) => false,
},
None => false,
} }
}, },
Err(e) if e.kind() == io::ErrorKind::ConnectionRefused => { 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::Alt(CharOrArrow::Char('\\')) => true, Key::Alt(CharOrArrow::Char('\\')) => true,
Key::Char(c) => { Key::Char(c) => {
if let '0'..='9' | 'a'..='f' = c { matches!(c, '0'..='9' | 'a'..='f')
true
} else {
false
}
}, },
_ => false, _ => false,
} }
@ -117,7 +113,7 @@ pub enum AnsiStdinInstructionOrKeys {
} }
impl 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! { lazy_static! {
static ref RE: Regex = Regex::new(r"^\u{1b}\[(\d+);(\d+);(\d+)t$").unwrap(); static ref RE: Regex = Regex::new(r"^\u{1b}\[(\d+);(\d+);(\d+)t$").unwrap();
} }
@ -172,7 +168,7 @@ impl AnsiStdinInstructionOrKeys {
Err("invalid sequence") 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! { lazy_static! {
static ref BACKGROUND_RE: Regex = Regex::new(r"11;(.*)$").unwrap(); 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(); static ref FOREGROUND_RE: Regex = Regex::new(r"10;(.*)$").unwrap();
} }
let key_string = keys.iter().fold(String::new(), |mut acc, (key, _)| { let key_string = keys.iter().fold(String::new(), |mut acc, (key, _)| {
match key { if let Key::Char(c) = key {
Key::Char(c) => acc.push(*c), acc.push(*c)
_ => {},
}; };
acc acc
}); });

View file

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

View file

@ -720,12 +720,10 @@ impl Grid {
} }
self.cursor.y = new_cursor_y; self.cursor.y = new_cursor_y;
self.cursor.x = new_cursor_x; self.cursor.x = new_cursor_x;
self.saved_cursor_position if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
.as_mut()
.map(|saved_cursor_position| {
saved_cursor_position.y = new_cursor_y; saved_cursor_position.y = new_cursor_y;
saved_cursor_position.x = new_cursor_x; saved_cursor_position.x = new_cursor_x;
}); };
} else if new_columns != self.width } else if new_columns != self.width
&& self.alternate_lines_above_viewport_and_cursor.is_some() && 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; let rows_pulled = self.viewport.len() - current_viewport_row_count;
self.cursor.y += rows_pulled; self.cursor.y += rows_pulled;
self.saved_cursor_position if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
.as_mut() saved_cursor_position.y += rows_pulled
.map(|saved_cursor_position| saved_cursor_position.y += rows_pulled); };
}, },
Ordering::Greater => { Ordering::Greater => {
let row_count_to_transfer = current_viewport_row_count - new_rows; let row_count_to_transfer = current_viewport_row_count - new_rows;
if row_count_to_transfer > self.cursor.y { if row_count_to_transfer > self.cursor.y {
self.cursor.y = 0; self.cursor.y = 0;
self.saved_cursor_position if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
.as_mut() saved_cursor_position.y = 0
.map(|saved_cursor_position| saved_cursor_position.y = 0); };
} else { } else {
self.cursor.y -= row_count_to_transfer; self.cursor.y -= row_count_to_transfer;
self.saved_cursor_position if let Some(saved_cursor_position) = self.saved_cursor_position.as_mut() {
.as_mut()
.map(|saved_cursor_position| {
saved_cursor_position.y -= row_count_to_transfer saved_cursor_position.y -= row_count_to_transfer
}); };
} }
if self.alternate_lines_above_viewport_and_cursor.is_none() { if self.alternate_lines_above_viewport_and_cursor.is_none() {
transfer_rows_from_viewport_to_lines_above( transfer_rows_from_viewport_to_lines_above(
@ -868,7 +864,7 @@ impl Grid {
pub fn rotate_scroll_region_up(&mut self, count: usize) { pub fn rotate_scroll_region_up(&mut self, count: usize) {
if let Some((scroll_region_top, scroll_region_bottom)) = self if let Some((scroll_region_top, scroll_region_bottom)) = self
.scroll_region .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); self.pad_lines_until(scroll_region_bottom, EMPTY_TERMINAL_CHARACTER);
for _ in 0..count { for _ in 0..count {
@ -889,7 +885,7 @@ impl Grid {
pub fn rotate_scroll_region_down(&mut self, count: usize) { pub fn rotate_scroll_region_down(&mut self, count: usize) {
if let Some((scroll_region_top, scroll_region_bottom)) = self if let Some((scroll_region_top, scroll_region_bottom)) = self
.scroll_region .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); self.pad_lines_until(scroll_region_bottom, EMPTY_TERMINAL_CHARACTER);
let mut pad_character = 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> { pub fn output_osc8(&self, link_anchor: Option<LinkAnchor>) -> Option<String> {
link_anchor link_anchor.and_then(|link| match link {
.map(|link| match link {
LinkAnchor::Start(index) => { LinkAnchor::Start(index) => {
let link = self.links.get(&index); let link = self.links.get(&index);
@ -74,7 +73,6 @@ impl LinkHandler {
}, },
LinkAnchor::End => Some(format!("\u{1b}]8;;{}", TERMINATOR)), 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 // 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. // their `reflow_lines()` method. Drop a Box<dyn ServerOsApi> in here somewhere.
#[allow(clippy::too_many_arguments)]
pub struct TerminalPane { pub struct TerminalPane {
pub grid: Grid, pub grid: Grid,
pub pid: RawFd, pub pid: RawFd,
@ -488,6 +489,7 @@ impl Pane for TerminalPane {
} }
impl TerminalPane { impl TerminalPane {
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
pid: RawFd, pid: RawFd,
position_and_size: PaneGeom, position_and_size: PaneGeom,

View file

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

View file

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

View file

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