Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #31

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Rust Build

on: [ push, pull_request ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
55 changes: 55 additions & 0 deletions .github/workflows/rust-clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# rust-clippy is a tool that runs a bunch of lints to catch common
# mistakes in your Rust code and help improve your Rust code.
# More details at https://github.com/rust-lang/rust-clippy
# and https://rust-lang.github.io/rust-clippy/

name: rust-clippy analyze

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '31 20 * * 1'

jobs:
rust-clippy-analyze:
name: Run rust-clippy analyzing
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true

- name: Install required cargo
run: cargo install clippy-sarif sarif-fmt

- name: Run rust-clippy
run:
cargo clippy
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
1 change: 0 additions & 1 deletion .travis.yml

This file was deleted.

64 changes: 52 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "icepick"
version = "0.0.1"
version = "0.0.3"
authors = ["Felipe Sere <felipesere@gmail.com>",
"Uku Taht <uku.taht@gmail.com>",
"Carol Nichols <cnichols@thinkthroughmath.com>"]
"Carol Nichols <cnichols@thinkthroughmath.com>",
"Erwin van Eijk <erwinvaneijk@gmail.com>"]

description = "A command-line fuzzy matcher based on Gary Bernheards selecta"
homepage = "http://github.com/felipesere/icepick"
Expand All @@ -22,11 +23,9 @@ test = true
doc = false

[dependencies]
libc = "0.2.4"
getopts = "0.2.14"

[dependencies.ansi_term]
git = "https://github.com/ogham/rust-ansi-term.git"
libc = "0.2.139"
getopts = "0.2.21"
ansi_term = "0.12"

[profile.release]
opt-level = 3
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Icepick is a reimplementation of Selecta in Rust

[![Build Status](https://travis-ci.org/felipesere/icepick.svg?branch=master)](https://travis-ci.org/felipesere/icepick)
![Build Status](https://github.com/erwinvaneijk/icepick/actions/workflows/build.yml/badge.svg)

A fuzzy text selector for files and anything else you need to select.
Use it from vim, from the command line, or anywhere you can run a shell command.
Expand All @@ -23,7 +23,7 @@ Then you can pipe input to it and fuzzy select on it:
find . -name "*.css" | icepick | xargs rm
```

The above commend would allow you to match on all CSS files in your current
The above commend would allow you to match on all CSS files in your current
directory and remove the selected one.

For more uses see [the original Ruby implementation](https://github.com/garybernhardt/selecta) by Gary Bernhardt.
Expand All @@ -45,4 +45,5 @@ If you have an idea to improve performance, run `cargo bench` and see how the re
@felipesere
@heruku
@carols10cents
@erwinvaneijk

2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ install: build
uninstall:
rm $(prefix)/bin/icepick

bench:
rustup run nightly cargo bench
21 changes: 15 additions & 6 deletions src/ansi.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use tty::IO;
use crate::tty::IO;

pub struct Ansi<'a> {
pub io: Box<(IO + 'a)>,
pub io: Box<(dyn IO + 'a)>,
}

impl <'a> Ansi<'a> {
impl<'a> Ansi<'a> {
pub fn escape(&mut self, message: &str) {
let out = Ansi::esc(message);
self.io.write(out.as_ref());
match self.io.write(out.as_ref()) {
Ok(_) => (),
Err(e) => panic!("{}", e),
};
}

fn esc(input: &str) -> String {
Expand All @@ -33,11 +36,17 @@ impl <'a> Ansi<'a> {

pub fn inverted(&mut self, line: &str) {
let compound = format!("{}{}{}", Ansi::esc("7m"), line, Ansi::esc("0m"));
self.io.write(compound.as_ref());
match self.io.write(compound.as_ref()) {
Ok(_) => (),
Err(e) => panic!("{}", e),
}
}

pub fn print(&mut self, line: &str) {
self.io.write(line);
match self.io.write(line) {
Ok(_) => (),
Err(e) => panic!("{}", e),
};
}

pub fn blank_line(&mut self, line: usize) {
Expand Down
30 changes: 21 additions & 9 deletions src/bin/bench_main.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
extern crate icepick;

use icepick::search::Search;
use std::fs::OpenOptions;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::{OpenOptions};
use std::path::Path;



#[allow(dead_code)]
fn main() {
let lines = read_lines("benches/30000.txt");

let mut search = Search::blank(&lines, None, 20);

search = search.append_to_search("t").append_to_search("o").append_to_search("a").append_to_search("w").append_to_search("c").backspace().backspace().backspace().append_to_search("w").backspace().append_to_search("a");

println!("\n{}", search.selection().unwrap_or("None".to_string()));
search = search
.append_to_search("t")
.append_to_search("o")
.append_to_search("a")
.append_to_search("w")
.append_to_search("c")
.backspace()
.backspace()
.backspace()
.append_to_search("w")
.backspace()
.append_to_search("a");

println!(
"\n{}",
search.selection().unwrap_or_else(|| "None".to_string())
);
}

fn read_lines(fname: &str) -> Vec<String> {
let path = Path::new(fname);
let mut file = BufReader::new(OpenOptions::new().read(true).open(&path).unwrap());
let mut file = BufReader::new(OpenOptions::new().read(true).open(path).unwrap());
let mut result = Vec::new();
loop {
let mut buf = String::new();
match file.read_line(&mut buf) {
Ok(_) if buf.len() > 0 => {
Ok(_) if !buf.is_empty() => {
result.push(buf);
},
}
_ => break,
}
}
Expand Down
45 changes: 26 additions & 19 deletions src/fake_tty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tty::IO;
use crate::tty::IO;
use std::io::Result;

pub struct FakeIO {
last: String,
Expand All @@ -12,7 +13,7 @@ impl FakeIO {
}

pub fn new_with_input(input: Vec<&str>) -> FakeIO {
let actual = input.iter().map( |s| s.to_string()).collect();
let actual = input.iter().map(|s| s.to_string()).collect();
FakeIO {
last: "fail".to_string(),
lines: Vec::new(),
Expand All @@ -21,28 +22,34 @@ impl FakeIO {
}
}

impl Default for FakeIO {
fn default() -> Self {
FakeIO::new_with_input(vec![])
}
}

impl IO for FakeIO {
fn write(&mut self, line: &str) {
self.last = line.to_string();
self.lines.push(line.to_string());
}
fn write(&mut self, line: &str) -> Result<()> {
self.last = line.to_string();
self.lines.push(line.to_string());
Ok(())
}

fn read(&mut self) -> Option<String> {
fn read(&mut self) -> Option<String> {
self.input.pop()
}
}

fn lines(&self) -> Vec<String> {
self.lines.clone()
}
fn lines(&self) -> Vec<String> {
self.lines.clone()
}

fn last(&self) -> &str {
self.last.as_ref()
}
fn last(&self) -> &str {
self.last.as_ref()
}

fn dimensions(&self) -> (usize, usize) {
(50, 50)
}
fn dimensions(&self) -> (usize, usize) {
(50, 50)
}

fn reset(&self) {
}
fn reset(&self) {}
}
Loading