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

chore: update flakes and formatting #20

Merged
merged 4 commits into from
Jul 11, 2024
Merged
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
14 changes: 14 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
edition = "2021"
unstable_features = true
# Unstable
comment_width = 80
condense_wildcard_suffixes = true
format_code_in_doc_comments = true
format_generated_files = false
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
imports_granularity = "Module"
reorder_impl_items = true
use_field_init_shorthand = true
wrap_comments = true
24 changes: 12 additions & 12 deletions flake.lock

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

36 changes: 17 additions & 19 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,32 @@
};
};

outputs = { nixpkgs, flake-utils, ... } @ inputs:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{ nixpkgs, flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = with inputs; [
inputs.fenix.overlays.default
];
overlays = [ inputs.fenix.overlays.default ];
};
inherit (pkgs) fenix ra-flake;
inherit (pkgs.lib) importTOML;
inherit (pkgs) fenix lib;

# Rust toolchain
rustChannel = (importTOML ./rust-toolchain).toolchain.channel;
rustToolchain = fenix.toolchainOf {
channel = rustChannel;
channel = (lib.importTOML ./rust-toolchain.toml).toolchain.channel;
sha256 = "sha256-gdYqng0y9iHYzYPAdkC/ka3DRny3La/S5G8ASj0Ayyc=";
};

# For development
rust-dev = fenix.combine (with rustToolchain; [
defaultToolchain
rust-src
rust-analyzer
]);
rust-dev = fenix.combine (
with rustToolchain;
[
defaultToolchain
rust-src
]
);

# For building packages
rust-minimal = rustToolchain.minimalToolchain;
rustPlatform = pkgs.makeRustPlatform {
Expand All @@ -46,11 +48,7 @@
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
};
devShells.default = with pkgs; mkShell {
nativeBuildInputs = [
rust-dev
];
};
devShells.default = with pkgs; mkShell { packages = [ rust-dev ]; };
}
);
}
File renamed without changes.
7 changes: 5 additions & 2 deletions src/autocomplete.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//! Autocompletion and fuzzy search for nerd fonts.

use crate::{icon::Icon, runtime::NGram};
use std::rc::Rc;

use indexmap::IndexMap;
use inquire::Autocomplete;
use itertools::Itertools;
use std::rc::Rc;

use crate::icon::Icon;
use crate::runtime::NGram;

const THRESHOLD: f32 = 0.6;
const MAX_SUGGESTIONS: usize = 100;
Expand Down
22 changes: 13 additions & 9 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
//! Command line arguments parser.

use crate::{error, icon::Substitution, shadow};
use clap::{Parser, Subcommand, ValueEnum};
use core::fmt;
use std::io;
use std::path::PathBuf;
use std::str::FromStr;

use clap::{Parser, Subcommand, ValueEnum};
use shadow_rs::formatcp;
use std::{io, path::PathBuf, str::FromStr};
use thisctx::IntoError;

use crate::icon::Substitution;
use crate::{error, shadow};

const V_PATH: &str = "PATH";
const V_SOURCE: &str = "SOURCE";
const V_SUBSTITUTION: &str = "SUBSTITUTION";
Expand All @@ -18,12 +23,11 @@ const SUB_LONG_HELP: &str = "\
Perform an exact/prefix substitution.

This option accepts several substitution types of `TYPE:FROM/TO` syntax:
* Exact substitution: replaces an icon with another when its name matches \
exactly. This is the default type when `TYPE` is omitted.
* Perfix substitution: replaces the prefix of an icon name with another, and \
then tries to replace the icon with the one has the new name, e.g. use \
`--sub prefix:mdi-/md-` to replace `mdi-tab` with `md-tab`.\
";
* Exact substitution: replaces an icon with another when its name matches exactly. This is the \
default type when `TYPE` is omitted.
* Prefix substitution: replaces the prefix of an icon name with another, and then tries to \
replace the icon with the one has the new name, e.g. use `--sub \
prefix:mdi-/md-` to replace `mdi-tab` with `md-tab`.";

#[derive(Debug, Parser)]
#[command(author, version, long_version = CLAP_LONG_VERSION)]
Expand Down
12 changes: 8 additions & 4 deletions src/icon.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//! Nerd font icons infomation.
//! Nerd font icons information.

use crate::error;
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;

use serde::de::Visitor;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use thisctx::IntoError;

use crate::error;

pub(crate) fn parse_codepoint(s: &str) -> error::Result<char> {
let v = u32::from_str_radix(s, 16).map_err(|_| error::InvalidCodepoint.build())?;
char::from_u32(v).ok_or_else(|| error::InvalidCodepoint.build())
Expand Down Expand Up @@ -91,9 +94,10 @@ mod codepoint {
}

mod substitution {
use super::*;
use std::str::FromStr;

use super::*;

impl FromStr for SubstitutionType {
type Err = &'static str;

Expand Down
9 changes: 4 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! Parses font infomation from nerd font official cheat sheet.
//! Parses font information from nerd font official cheat sheet.

use crate::{
error,
icon::{Database, Icon},
};
use once_cell::sync::Lazy;
use regex::Regex;
use thisctx::WithContext;

use crate::error;
use crate::icon::{Database, Icon};

pub fn parse(s: &str) -> error::Result<Database> {
let s = s.trim_start();
Ok(if s.starts_with('{') {
Expand Down
7 changes: 5 additions & 2 deletions src/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::error;
use std::fmt;
use std::str::FromStr;

use inquire::InquireError;
use std::{fmt, str::FromStr};
use thisctx::IntoError;

use crate::error;

pub fn prompt_yes_or_no(msg: &str, help: Option<&str>) -> error::Result<YesOrNo> {
match inquire::CustomType::<YesOrNo>::new(msg)
.with_help_message(help.unwrap_or("(Y)es/(N)o/(A)ll yes, (Ctrl_C) to abort"))
Expand Down
28 changes: 14 additions & 14 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use crate::{
autocomplete::Autocompleter,
cli::{IoPath, OutputFormat, UserInput},
error,
icon::{Database, Icon, Substitution, SubstitutionType, Substitutions},
util::NGramSearcherExt,
};
use codespan_reporting::{
diagnostic::{Diagnostic, Label},
files::SimpleFiles,
term,
term::termcolor::{ColorChoice, StandardStream},
};
use std::collections::HashMap;
use std::io::Write;
use std::rc::Rc;

use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use indexmap::IndexMap;
use inquire::InquireError;
use itertools::Itertools;
use once_cell::unsync::{Lazy, OnceCell};
use serde::Serialize;
use std::{collections::HashMap, io::Write, rc::Rc};
use thisctx::IntoError;
use tracing::info;

use crate::autocomplete::Autocompleter;
use crate::cli::{IoPath, OutputFormat, UserInput};
use crate::error;
use crate::icon::{Database, Icon, Substitution, SubstitutionType, Substitutions};
use crate::util::NGramSearcherExt;

const ARITY: usize = 3;
const PAD_LEN: usize = 2;
const WARP: f32 = 3.0;
Expand Down
7 changes: 5 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::error;
use noodler::NGramSearcher;
use std::fmt;

use noodler::NGramSearcher;

use crate::error;

pub(crate) struct LogStatus;

const _: () = {
use std::sync::atomic::{AtomicBool, Ordering};

use tracing::{Event, Level, Subscriber};
use tracing_subscriber::layer::{Context, Layer};

Expand Down
12 changes: 6 additions & 6 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// NOTE: ignored on Windows as CRLF causes differences in spans
#![cfg(unix)]

use assert_cmd::{assert::Assert, prelude::*};
use core::fmt;
use std::env;
use std::path::Path;
use std::process::{Command, Output};

use assert_cmd::assert::Assert;
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::{
env,
path::Path,
process::{Command, Output},
};

fn normalize_output(bytes: Vec<u8>) -> Vec<u8> {
strip_ansi_escapes::strip(bytes)
Expand Down
Loading