clippy styling
Some checks failed
Test Rust project / test (ubuntu-latest, stable) (push) Failing after 2m29s
Some checks failed
Test Rust project / test (ubuntu-latest, stable) (push) Failing after 2m29s
This commit is contained in:
@@ -97,8 +97,8 @@ impl Widget for &App {
|
|||||||
fn center_text(text: &str, avaliable_space: i32) -> String {
|
fn center_text(text: &str, avaliable_space: i32) -> String {
|
||||||
let margin = avaliable_space - text.len() as i32;
|
let margin = avaliable_space - text.len() as i32;
|
||||||
let margin = margin / 2;
|
let margin = margin / 2;
|
||||||
let l_margin = (0..margin).into_iter().map(|_| ' ').collect::<String>();
|
let l_margin = (0..margin).map(|_| ' ').collect::<String>();
|
||||||
let r_margin = (0..(margin - (l_margin.len() as i32))).into_iter().map(|_| ' ').collect::<String>();
|
let r_margin = (0..(margin - (l_margin.len() as i32))).map(|_| ' ').collect::<String>();
|
||||||
format!("{l_margin}{text}{r_margin}")
|
format!("{l_margin}{text}{r_margin}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ impl Widget for &App {
|
|||||||
|
|
||||||
let bg = if y_idx == self.grid.cursor().1 {
|
let bg = if y_idx == self.grid.cursor().1 {
|
||||||
Color::DarkGray
|
Color::DarkGray
|
||||||
} else if y_idx % 2 == 0 {
|
} else if y_idx.is_multiple_of(2) {
|
||||||
ORANGE1
|
ORANGE1
|
||||||
} else {
|
} else {
|
||||||
ORANGE2
|
ORANGE2
|
||||||
@@ -127,7 +127,7 @@ impl Widget for &App {
|
|||||||
|
|
||||||
let bg = if x_idx == self.grid.cursor().0 {
|
let bg = if x_idx == self.grid.cursor().0 {
|
||||||
Color::DarkGray
|
Color::DarkGray
|
||||||
} else if x_idx % 2 == 0 {
|
} else if x_idx.is_multiple_of(2) {
|
||||||
ORANGE1
|
ORANGE1
|
||||||
} else {
|
} else {
|
||||||
ORANGE2
|
ORANGE2
|
||||||
@@ -173,7 +173,7 @@ impl Widget for &App {
|
|||||||
suggest_upper_bound = Some(display.len() as u16);
|
suggest_upper_bound = Some(display.len() as u16);
|
||||||
// check for cells to the right, see if we should truncate the cell width
|
// check for cells to the right, see if we should truncate the cell width
|
||||||
for i in 1..(display.len() as f32 / cell_width as f32).ceil() as usize {
|
for i in 1..(display.len() as f32 / cell_width as f32).ceil() as usize {
|
||||||
if let Some(_) = self.grid.get_cell_raw(x_idx + i, y_idx) {
|
if self.grid.get_cell_raw(x_idx + i, y_idx).is_some() {
|
||||||
suggest_upper_bound = Some(cell_width * i as u16);
|
suggest_upper_bound = Some(cell_width * i as u16);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ impl Widget for &App {
|
|||||||
} else if let Some(suggestion) = suggest_upper_bound {
|
} else if let Some(suggestion) = suggest_upper_bound {
|
||||||
let max_available_width = area.width - x_off;
|
let max_available_width = area.width - x_off;
|
||||||
// draw the biggest cell possible, without going OOB off the screen
|
// draw the biggest cell possible, without going OOB off the screen
|
||||||
let width = min(max_available_width, suggestion as u16);
|
let width = min(max_available_width, suggestion);
|
||||||
// Don't draw too small tho, we want full-sized cells, minium
|
// Don't draw too small tho, we want full-sized cells, minium
|
||||||
let width = max(cell_width, width);
|
let width = max(cell_width, width);
|
||||||
|
|
||||||
@@ -280,22 +280,19 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn file_name_display(&self) -> String {
|
fn file_name_display(&self) -> String {
|
||||||
let file_name_status = {
|
let mut file_name = "[No Name]";
|
||||||
let mut file_name = "[No Name]";
|
let mut icon = "";
|
||||||
let mut icon = "";
|
if let Some(file) = &self.file {
|
||||||
if let Some(file) = &self.file {
|
if let Some(f) = file.file_name() {
|
||||||
if let Some(f) = file.file_name() {
|
if let Some(f) = f.to_str() {
|
||||||
if let Some(f) = f.to_str() {
|
file_name = f;
|
||||||
file_name = f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.grid.needs_to_be_saved() {
|
}
|
||||||
icon = "[+]";
|
if self.grid.needs_to_be_saved() {
|
||||||
}
|
icon = "[+]";
|
||||||
format!("{file_name}{icon}")
|
}
|
||||||
};
|
format!("{file_name}{icon}")
|
||||||
file_name_status
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self, frame: &mut Frame) {
|
fn draw(&self, frame: &mut Frame) {
|
||||||
@@ -362,7 +359,7 @@ impl App {
|
|||||||
event::KeyCode::Char(c) => chord.add_char(c),
|
event::KeyCode::Char(c) => chord.add_char(c),
|
||||||
event::KeyCode::Enter => {
|
event::KeyCode::Enter => {
|
||||||
// tmp is to get around reference issues.
|
// tmp is to get around reference issues.
|
||||||
let tmp = pos.clone();
|
let tmp = *pos;
|
||||||
Mode::process_cmd(self);
|
Mode::process_cmd(self);
|
||||||
self.mode = Mode::Visual(tmp)
|
self.mode = Mode::Visual(tmp)
|
||||||
}
|
}
|
||||||
@@ -421,7 +418,7 @@ impl App {
|
|||||||
},
|
},
|
||||||
Mode::Normal => match event::read()? {
|
Mode::Normal => match event::read()? {
|
||||||
event::Event::Key(key_event) => match key_event.code {
|
event::Event::Key(key_event) => match key_event.code {
|
||||||
event::KeyCode::F(n) => {},
|
event::KeyCode::F(_n) => {}
|
||||||
event::KeyCode::Char(c) => Mode::process_key(self, c),
|
event::KeyCode::Char(c) => Mode::process_key(self, c),
|
||||||
// Pretend that the arrow keys are vim movement keys
|
// Pretend that the arrow keys are vim movement keys
|
||||||
event::KeyCode::Left => Mode::process_key(self, 'h'),
|
event::KeyCode::Left => Mode::process_key(self, 'h'),
|
||||||
@@ -432,12 +429,14 @@ impl App {
|
|||||||
event::KeyCode::PageUp => self.grid.redo(),
|
event::KeyCode::PageUp => self.grid.redo(),
|
||||||
event::KeyCode::PageDown => self.grid.undo(),
|
event::KeyCode::PageDown => self.grid.undo(),
|
||||||
event::KeyCode::Modifier(modifier_key_code) => {
|
event::KeyCode::Modifier(modifier_key_code) => {
|
||||||
if let event::ModifierKeyCode::LeftControl | event::ModifierKeyCode::RightControl = modifier_key_code {
|
if let event::ModifierKeyCode::LeftControl | event::ModifierKeyCode::RightControl =
|
||||||
|
modifier_key_code
|
||||||
|
{
|
||||||
// TODO my terminal (alacritty) isn't showing me ctrl presses. I know
|
// TODO my terminal (alacritty) isn't showing me ctrl presses. I know
|
||||||
// that they work tho, since ctrl+r works here in neovim.
|
// that they work tho, since ctrl+r works here in neovim.
|
||||||
// panic!("heard ctrl");
|
// panic!("heard ctrl");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ impl Widget for &StatusMessage {
|
|||||||
let msg = if self.start.elapsed().as_secs() > 3 {
|
let msg = if self.start.elapsed().as_secs() > 3 {
|
||||||
String::new()
|
String::new()
|
||||||
} else {
|
} else {
|
||||||
self.msg.clone().unwrap_or(String::new())
|
self.msg.clone().unwrap_or_default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let style = match self.msg_type {
|
let style = match self.msg_type {
|
||||||
@@ -57,4 +57,4 @@ impl Widget for &StatusMessage {
|
|||||||
|
|
||||||
Paragraph::new(msg).style(style).render(area, buf);
|
Paragraph::new(msg).style(style).render(area, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ use crate::app::app::App;
|
|||||||
use crate::app::mode::Mode;
|
use crate::app::mode::Mode;
|
||||||
|
|
||||||
pub fn get_header_size() -> usize {
|
pub fn get_header_size() -> usize {
|
||||||
let row_header_width = LEN.to_string().len();
|
LEN.to_string().len()
|
||||||
row_header_width
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LEN: usize = 1001;
|
pub const LEN: usize = 1001;
|
||||||
@@ -216,7 +215,7 @@ impl Grid {
|
|||||||
if let Ok(val) = self.evaluate(&cell.to_string())
|
if let Ok(val) = self.evaluate(&cell.to_string())
|
||||||
&& resolve_values
|
&& resolve_values
|
||||||
{
|
{
|
||||||
format!("{}{}", val.to_string(), delim)
|
format!("{val}{delim}")
|
||||||
} else {
|
} else {
|
||||||
format!("{}{}", cell.escaped_csv_string(), delim)
|
format!("{}{}", cell.escaped_csv_string(), delim)
|
||||||
}
|
}
|
||||||
@@ -232,7 +231,7 @@ impl Grid {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_grid<'a>(&'a self) -> &'a CellGrid {
|
pub fn get_grid(&self) -> &CellGrid {
|
||||||
&self.grid_history[self.current_grid]
|
&self.grid_history[self.current_grid]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +245,7 @@ impl Grid {
|
|||||||
|
|
||||||
pub fn transact_on_grid<F>(&mut self, mut action: F)
|
pub fn transact_on_grid<F>(&mut self, mut action: F)
|
||||||
where
|
where
|
||||||
F: FnMut(&mut CellGrid) -> (),
|
F: FnMut(&mut CellGrid),
|
||||||
{
|
{
|
||||||
// push on a new reality
|
// push on a new reality
|
||||||
let new = self.get_grid().clone();
|
let new = self.get_grid().clone();
|
||||||
@@ -377,7 +376,7 @@ impl Grid {
|
|||||||
f.custom_translate_cell((0, 0), (0, 1), |rolling, old, new| {
|
f.custom_translate_cell((0, 0), (0, 1), |rolling, old, new| {
|
||||||
if let Some((_, arg_y)) = Grid::parse_to_idx(old) {
|
if let Some((_, arg_y)) = Grid::parse_to_idx(old) {
|
||||||
if arg_y < insertion_y { rolling.to_owned() } else { rolling.replace(old, new) }
|
if arg_y < insertion_y { rolling.to_owned() } else { rolling.replace(old, new) }
|
||||||
} else if let Some(_) = Grid::range_as_indices(old) {
|
} else if Grid::range_as_indices(old).is_some() {
|
||||||
// ranges are not changed when moved vertically
|
// ranges are not changed when moved vertically
|
||||||
rolling.to_string()
|
rolling.to_string()
|
||||||
} else {
|
} else {
|
||||||
@@ -454,7 +453,7 @@ impl Grid {
|
|||||||
return Err(format!("\"{eq}\" is not an equation"));
|
return Err(format!("\"{eq}\" is not an equation"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ctx = ctx::CallbackContext::new(&self);
|
let ctx = ctx::CallbackContext::new(self);
|
||||||
|
|
||||||
let prep_for_return = |v: Value| {
|
let prep_for_return = |v: Value| {
|
||||||
if v.is_number() {
|
if v.is_number() {
|
||||||
@@ -505,13 +504,12 @@ impl Grid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn char_to_idx(i: &str) -> usize {
|
pub fn char_to_idx(i: &str) -> usize {
|
||||||
let x_idx = i
|
i
|
||||||
.chars()
|
.chars()
|
||||||
.filter(|f| f.is_alphabetic())
|
.filter(|f| f.is_alphabetic())
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, c)| ((c.to_ascii_lowercase() as usize).saturating_sub(97)) + (26 * idx))
|
.map(|(idx, c)| ((c.to_ascii_lowercase() as usize).saturating_sub(97)) + (26 * idx))
|
||||||
.fold(0, |a, b| a + b);
|
.sum()
|
||||||
x_idx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse values in the format of A0, C10 ZZ99, etc, and
|
/// Parse values in the format of A0, C10 ZZ99, etc, and
|
||||||
@@ -564,7 +562,7 @@ impl Grid {
|
|||||||
if x >= LEN || y >= LEN {
|
if x >= LEN || y >= LEN {
|
||||||
return &None;
|
return &None;
|
||||||
}
|
}
|
||||||
&self.get_grid().get_cell_raw(x, y)
|
self.get_grid().get_cell_raw(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn num_to_char(idx: usize) -> String {
|
pub fn num_to_char(idx: usize) -> String {
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ pub enum CellType {
|
|||||||
Equation(String),
|
Equation(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<CellType> for f64 {
|
impl From<f64> for CellType {
|
||||||
fn into(self) -> CellType {
|
fn from(value: f64) -> Self {
|
||||||
CellType::duck_type(self.to_string())
|
CellType::duck_type(value.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<CellType> for String {
|
impl From<String> for CellType {
|
||||||
fn into(self) -> CellType {
|
fn from(value: String) -> Self {
|
||||||
CellType::duck_type(self)
|
CellType::duck_type(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ impl CellType {
|
|||||||
if display.contains(CSV_DELIMITER) { format!("\"{display}\"") } else { display }
|
if display.contains(CSV_DELIMITER) { format!("\"{display}\"") } else { display }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn duck_type<'a>(value: impl Into<String>) -> Self {
|
fn duck_type(value: impl Into<String>) -> Self {
|
||||||
let value = value.into();
|
let value = value.into();
|
||||||
|
|
||||||
if let Ok(parse) = value.parse::<f64>() {
|
if let Ok(parse) = value.parse::<f64>() {
|
||||||
@@ -109,9 +109,9 @@ impl CellType {
|
|||||||
let x2 = x2 as i32;
|
let x2 = x2 as i32;
|
||||||
let y2 = y2 as i32;
|
let y2 = y2 as i32;
|
||||||
|
|
||||||
let dest_x = if lock_x { src_x as usize } else { (src_x as i32 + (x2 - x1)) as usize };
|
let dest_x = if lock_x { src_x } else { (src_x as i32 + (x2 - x1)) as usize };
|
||||||
|
|
||||||
let dest_y = if lock_y { src_y as usize } else { (src_y as i32 + (y2 - y1)) as usize };
|
let dest_y = if lock_y { src_y } else { (src_y as i32 + (y2 - y1)) as usize };
|
||||||
|
|
||||||
let alpha = Grid::num_to_char(dest_x);
|
let alpha = Grid::num_to_char(dest_x);
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl Mode {
|
|||||||
path.file_name().map(|f| f.to_str().unwrap_or("n/a")).unwrap_or("n/a")
|
path.file_name().map(|f| f.to_str().unwrap_or("n/a")).unwrap_or("n/a")
|
||||||
));
|
));
|
||||||
|
|
||||||
if let None = app.file {
|
if app.file.is_none() {
|
||||||
app.file = Some(path)
|
app.file = Some(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ impl Mode {
|
|||||||
}
|
}
|
||||||
"export" => {
|
"export" => {
|
||||||
if let Some(arg1) = args.get(1) {
|
if let Some(arg1) = args.get(1) {
|
||||||
save_range(&arg1);
|
save_range(arg1);
|
||||||
} else {
|
} else {
|
||||||
app.msg = StatusMessage::error("export <path.csv>")
|
app.msg = StatusMessage::error("export <path.csv>")
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ impl Mode {
|
|||||||
'i' | 'a' => {
|
'i' | 'a' => {
|
||||||
let (x, y) = app.grid.cursor();
|
let (x, y) = app.grid.cursor();
|
||||||
|
|
||||||
let val = app.grid.get_cell_raw(x, y).as_ref().map(|f| f.to_string()).unwrap_or(String::new());
|
let val = app.grid.get_cell_raw(x, y).as_ref().map(|f| f.to_string()).unwrap_or_default();
|
||||||
|
|
||||||
app.mode = Mode::Insert(Chord::from(val));
|
app.mode = Mode::Insert(Chord::from(val));
|
||||||
}
|
}
|
||||||
@@ -477,14 +477,12 @@ impl Mode {
|
|||||||
let len = match &self {
|
let len = match &self {
|
||||||
Mode::Insert(edit) | Mode::VisualCmd(_, edit) | Mode::Command(edit) | Mode::Chord(edit) => edit.len(),
|
Mode::Insert(edit) | Mode::VisualCmd(_, edit) | Mode::Command(edit) | Mode::Chord(edit) => edit.len(),
|
||||||
Mode::Normal => {
|
Mode::Normal => {
|
||||||
let len = cell.as_ref().map(|f| f.to_string().len()).unwrap_or_default();
|
cell.as_ref().map(|f| f.to_string().len()).unwrap_or_default()
|
||||||
len
|
|
||||||
}
|
}
|
||||||
Mode::Visual(_) => 0,
|
Mode::Visual(_) => 0,
|
||||||
};
|
};
|
||||||
// min 20 chars, expand if needed
|
// min 20 chars, expand if needed
|
||||||
let len = max(len as u16 + 1, 20);
|
max(len as u16 + 1, 20)
|
||||||
len
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&self, f: &mut ratatui::Frame, area: prelude::Rect, cell: &Option<CellType>) {
|
pub fn render(&self, f: &mut ratatui::Frame, area: prelude::Rect, cell: &Option<CellType>) {
|
||||||
@@ -498,8 +496,7 @@ impl Mode {
|
|||||||
Mode::Chord(chord) => f.render_widget(chord, area),
|
Mode::Chord(chord) => f.render_widget(chord, area),
|
||||||
Mode::Normal => f.render_widget(
|
Mode::Normal => f.render_widget(
|
||||||
Paragraph::new({
|
Paragraph::new({
|
||||||
let cell = cell.as_ref().map(|f| f.to_string()).unwrap_or_default();
|
cell.as_ref().map(|f| f.to_string()).unwrap_or_default()
|
||||||
cell
|
|
||||||
}),
|
}),
|
||||||
area,
|
area,
|
||||||
),
|
),
|
||||||
@@ -522,8 +519,7 @@ impl From<String> for Chord {
|
|||||||
|
|
||||||
impl Chord {
|
impl Chord {
|
||||||
pub fn new(inital: char) -> Self {
|
pub fn new(inital: char) -> Self {
|
||||||
let mut buf = Vec::new();
|
let buf = vec![inital];
|
||||||
buf.push(inital);
|
|
||||||
|
|
||||||
Self { buf }
|
Self { buf }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,11 +48,11 @@ impl ScreenSpace {
|
|||||||
// ======= X =======
|
// ======= X =======
|
||||||
// screen seems to be 2 cells smaller than it should be
|
// screen seems to be 2 cells smaller than it should be
|
||||||
// this is probably related to issue #6
|
// this is probably related to issue #6
|
||||||
let x_cells = (screen_size.0 / self.get_cell_width(vars) as usize) -2;
|
let x_cells = (screen_size.0 / self.get_cell_width(vars)) -2;
|
||||||
// ======= Y =======
|
// ======= Y =======
|
||||||
// screen seems to be 2 cells smaller than it should be
|
// screen seems to be 2 cells smaller than it should be
|
||||||
// this is probably related to issue #6
|
// this is probably related to issue #6
|
||||||
let y_cells = (screen_size.1 / self.get_cell_height(vars) as usize) -2;
|
let y_cells = (screen_size.1 / self.get_cell_height(vars)) -2;
|
||||||
(x_cells,y_cells)
|
(x_cells,y_cells)
|
||||||
} else {
|
} else {
|
||||||
(0,0)
|
(0,0)
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
#![allow(clippy::needless_return)]
|
||||||
|
#![allow(clippy::len_zero)]
|
||||||
|
#![allow(clippy::collapsible_if)]
|
||||||
|
#![allow(clippy::collapsible_else_if)]
|
||||||
|
#![allow(clippy::collapsible_match)]
|
||||||
|
#![allow(clippy::single_match)]
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
|
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
|
|||||||
Reference in New Issue
Block a user