From a872362328e89d1a2cb43642751486a52aed124c Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Sun, 16 May 2021 22:25:32 +0530 Subject: [PATCH] fmt and clippy --- src/tests/integration/basic.rs | 4 ++-- src/tests/integration/resize_down.rs | 2 +- src/tests/integration/resize_right.rs | 2 +- zellij-client/src/input_handler.rs | 6 +----- zellij-client/src/lib.rs | 5 ++++- zellij-server/src/lib.rs | 4 ++-- zellij-server/src/panes/grid.rs | 13 +++++++++++-- zellij-server/src/panes/terminal_character.rs | 12 +++++++++--- zellij-server/src/pty.rs | 2 +- zellij-server/src/route.rs | 5 ++--- zellij-server/src/tab.rs | 7 ++----- zellij-server/src/thread_bus.rs | 7 +++---- zellij-server/src/ui/pane_resizer.rs | 4 ++-- zellij-utils/src/errors.rs | 2 +- zellij-utils/src/shared.rs | 6 +++--- 15 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/tests/integration/basic.rs b/src/tests/integration/basic.rs index 1329c5b813..640b1c553c 100644 --- a/src/tests/integration/basic.rs +++ b/src/tests/integration/basic.rs @@ -1,7 +1,6 @@ -use zellij_utils::pane_size::PositionAndSize; use ::insta::assert_snapshot; +use zellij_utils::pane_size::PositionAndSize; -use zellij_utils::input::config::Config; use crate::tests::fakes::FakeInputOutput; use crate::tests::start; use crate::tests::utils::commands::{ @@ -12,6 +11,7 @@ use crate::tests::utils::commands::{ }; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; use crate::CliArgs; +use zellij_utils::input::config::Config; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { FakeInputOutput::new(fake_win_size.clone()) diff --git a/src/tests/integration/resize_down.rs b/src/tests/integration/resize_down.rs index dd9976cddf..4ef45a0692 100644 --- a/src/tests/integration/resize_down.rs +++ b/src/tests/integration/resize_down.rs @@ -1,10 +1,10 @@ use insta::assert_snapshot; -use zellij_utils::pane_size::PositionAndSize; use crate::tests::fakes::FakeInputOutput; use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; use crate::CliArgs; +use zellij_utils::pane_size::PositionAndSize; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_DOWN_IN_RESIZE_MODE, diff --git a/src/tests/integration/resize_right.rs b/src/tests/integration/resize_right.rs index 7c3fdd8580..44601f2cd6 100644 --- a/src/tests/integration/resize_right.rs +++ b/src/tests/integration/resize_right.rs @@ -1,10 +1,10 @@ use ::insta::assert_snapshot; -use zellij_utils::pane_size::PositionAndSize; use crate::tests::fakes::FakeInputOutput; use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; use crate::CliArgs; +use zellij_utils::pane_size::PositionAndSize; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_MODE, RESIZE_RIGHT_IN_RESIZE_MODE, diff --git a/zellij-client/src/input_handler.rs b/zellij-client/src/input_handler.rs index 6c6a6b0b4b..e67bdf8296 100644 --- a/zellij-client/src/input_handler.rs +++ b/zellij-client/src/input_handler.rs @@ -1,10 +1,6 @@ //! Main input logic. -use crate::{ - ClientInstruction, - CommandIsExecuting, - os_input_output::ClientOsApi, -}; +use crate::{os_input_output::ClientOsApi, ClientInstruction, CommandIsExecuting}; use zellij_utils::{ channels::{SenderWithContext, OPENCALLS}, errors::ContextType, diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 7cc2aa21f1..8ffcf72be0 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -10,7 +10,10 @@ use std::process::Command; use std::sync::mpsc; use std::thread; -use crate::{command_is_executing::CommandIsExecuting, input_handler::input_loop, os_input_output::ClientOsApi}; +use crate::{ + command_is_executing::CommandIsExecuting, input_handler::input_loop, + os_input_output::ClientOsApi, +}; use zellij_utils::cli::CliArgs; use zellij_utils::{ channels::{SenderType, SenderWithContext, SyncChannelWithContext}, diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index b92b931ff6..606bf1b0dc 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -1,6 +1,6 @@ +pub mod os_input_output; pub mod panes; pub mod tab; -pub mod os_input_output; mod pty; mod route; @@ -16,12 +16,12 @@ use wasmer::Store; use zellij_tile::data::PluginCapabilities; use crate::{ + os_input_output::ServerOsApi, pty::{pty_thread_main, Pty, PtyInstruction}, screen::{screen_thread_main, ScreenInstruction}, thread_bus::{Bus, ThreadSenders}, ui::layout::Layout, wasm_vm::{wasm_thread_main, PluginInstruction}, - os_input_output::ServerOsApi, }; use route::route_thread_main; use zellij_utils::{ diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs index b2ec365a99..83e8c70f6b 100644 --- a/zellij-server/src/panes/grid.rs +++ b/zellij-server/src/panes/grid.rs @@ -1434,13 +1434,19 @@ impl Debug for Row { } } -impl Row { - pub fn new() -> Self { +impl Default for Row { + fn default() -> Self { Row { columns: vec![], is_canonical: false, } } +} + +impl Row { + pub fn new() -> Self { + Self::default() + } pub fn from_columns(columns: Vec) -> Self { Row { columns, @@ -1526,6 +1532,9 @@ impl Row { pub fn len(&self) -> usize { self.columns.len() } + pub fn is_empty(&self) -> bool { + self.columns.is_empty() + } pub fn delete_character(&mut self, x: usize) { if x < self.columns.len() { self.columns.remove(x); diff --git a/zellij-server/src/panes/terminal_character.rs b/zellij-server/src/panes/terminal_character.rs index c9497ac239..c55569f05e 100644 --- a/zellij-server/src/panes/terminal_character.rs +++ b/zellij-server/src/panes/terminal_character.rs @@ -110,9 +110,9 @@ pub struct CharacterStyles { pub italic: Option, } -impl CharacterStyles { - pub fn new() -> Self { - CharacterStyles { +impl Default for CharacterStyles { + fn default() -> Self { + Self { foreground: None, background: None, strike: None, @@ -126,6 +126,12 @@ impl CharacterStyles { italic: None, } } +} + +impl CharacterStyles { + pub fn new() -> Self { + Self::default() + } pub fn foreground(mut self, foreground_code: Option) -> Self { self.foreground = foreground_code; self diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index 0360500344..373b5f0b50 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -8,13 +8,13 @@ use std::pin::*; use std::time::{Duration, Instant}; use crate::{ + os_input_output::ServerOsApi, panes::PaneId, screen::ScreenInstruction, thread_bus::{Bus, ThreadSenders}, ui::layout::Layout, wasm_vm::PluginInstruction, ServerInstruction, - os_input_output::ServerOsApi, }; use zellij_utils::{ errors::{get_current_ctx, ContextType, PtyContext}, diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index e161a534e5..1d25ae77c4 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -3,9 +3,8 @@ use std::sync::{Arc, RwLock}; use zellij_tile::data::Event; use crate::{ - pty::PtyInstruction, screen::ScreenInstruction, wasm_vm::PluginInstruction, ServerInstruction, - SessionMetaData, - os_input_output::ServerOsApi, + os_input_output::ServerOsApi, pty::PtyInstruction, screen::ScreenInstruction, + wasm_vm::PluginInstruction, ServerInstruction, SessionMetaData, }; use zellij_utils::{ channels::SenderWithContext, diff --git a/zellij-server/src/tab.rs b/zellij-server/src/tab.rs index ade9e1824d..e41cb530dd 100644 --- a/zellij-server/src/tab.rs +++ b/zellij-server/src/tab.rs @@ -2,13 +2,13 @@ //! as well as how they should be resized use crate::{ + os_input_output::ServerOsApi, panes::{PaneId, PluginPane, TerminalPane}, pty::{PtyInstruction, VteBytes}, thread_bus::ThreadSenders, ui::{boundaries::Boundaries, layout::Layout, pane_resizer::PaneResizer}, wasm_vm::PluginInstruction, ServerInstruction, - os_input_output::ServerOsApi, }; use serde::{Deserialize, Serialize}; use std::os::unix::io::RawFd; @@ -19,10 +19,7 @@ use std::{ collections::{BTreeMap, HashSet}, }; use zellij_tile::data::{Event, InputMode, ModeInfo, Palette}; -use zellij_utils::{ - input::parse_keys, pane_size::PositionAndSize, - shared::adjust_to_size, -}; +use zellij_utils::{input::parse_keys, pane_size::PositionAndSize, shared::adjust_to_size}; const CURSOR_HEIGHT_WIDTH_RATIO: usize = 4; // this is not accurate and kind of a magic number, TODO: look into this diff --git a/zellij-server/src/thread_bus.rs b/zellij-server/src/thread_bus.rs index ff2fcb2006..afc1d875b9 100644 --- a/zellij-server/src/thread_bus.rs +++ b/zellij-server/src/thread_bus.rs @@ -1,12 +1,11 @@ //! Definitions and helpers for sending and receiving messages between threads. use crate::{ - pty::PtyInstruction, screen::ScreenInstruction, wasm_vm::PluginInstruction, ServerInstruction, os_input_output::ServerOsApi + os_input_output::ServerOsApi, pty::PtyInstruction, screen::ScreenInstruction, + wasm_vm::PluginInstruction, ServerInstruction, }; use std::sync::mpsc; -use zellij_utils::{ - channels::SenderWithContext, errors::ErrorContext, -}; +use zellij_utils::{channels::SenderWithContext, errors::ErrorContext}; /// A container for senders to the different threads in zellij on the server side #[derive(Clone)] diff --git a/zellij-server/src/ui/pane_resizer.rs b/zellij-server/src/ui/pane_resizer.rs index 9f8b4d04cb..b2001945eb 100644 --- a/zellij-server/src/ui/pane_resizer.rs +++ b/zellij-server/src/ui/pane_resizer.rs @@ -1,9 +1,9 @@ -use crate::{panes::PaneId, os_input_output::ServerOsApi, tab::Pane}; +use crate::{os_input_output::ServerOsApi, panes::PaneId, tab::Pane}; use std::{ cmp::Ordering, collections::{BTreeMap, HashSet}, }; -use zellij_utils::{pane_size::PositionAndSize}; +use zellij_utils::pane_size::PositionAndSize; pub(crate) struct PaneResizer<'a> { panes: &'a mut BTreeMap>, diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index 9d26986c51..94a894c464 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -1,7 +1,7 @@ //! Error context system based on a thread-local representation of the call stack, itself based on //! the instructions that are sent between threads. -use crate::channels::{ASYNCOPENCALLS, OPENCALLS, SenderWithContext}; +use crate::channels::{SenderWithContext, ASYNCOPENCALLS, OPENCALLS}; use serde::{Deserialize, Serialize}; use std::fmt::{Display, Error, Formatter}; use std::panic::PanicInfo; diff --git a/zellij-utils/src/shared.rs b/zellij-utils/src/shared.rs index 94ef9fa2ff..bc8b677115 100644 --- a/zellij-utils/src/shared.rs +++ b/zellij-utils/src/shared.rs @@ -5,10 +5,10 @@ use std::{iter, str::from_utf8}; use strip_ansi_escapes::strip; use colors_transform::{Color, Rgb}; -use zellij_tile::data::{Palette, PaletteColor, PaletteSource, Theme}; -use std::os::unix::{fs::PermissionsExt}; -use std::path::{Path}; +use std::os::unix::fs::PermissionsExt; +use std::path::Path; use std::{fs, io}; +use zellij_tile::data::{Palette, PaletteColor, PaletteSource, Theme}; const UNIX_PERMISSIONS: u32 = 0o700;