Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
prepare for publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolpega committed Jul 20, 2023
1 parent 7390192 commit 2316cb1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
name = "sudo-askpass"
version = "2.2.0"
edition = "2021"
description = "A sudo askpasss so inputting your password isn't boring"
readme = "README.md"
homepage = "https://github.com/absolpega/sudo-askpass"
repository = "https://github.com/absolpega/sudo-askpass"
license = "MIT"
keywords = ["sudo", "askpass", "cli", "password"]
categories = [
"command-line-utilities",
"command-line-interface",
"authentication",
]

[dependencies]
ansi-escapes = "0.1.1"
Expand Down
2 changes: 2 additions & 0 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ impl<'a> AnsiCodeIterator<'a> {
}
}

/* unused, scared to delete forever
/// Returns the string slice up to the current match.
pub fn current_slice(&self) -> &str {
&self.s[..self.cur_idx]
Expand All @@ -251,6 +252,7 @@ impl<'a> AnsiCodeIterator<'a> {
pub fn rest_slice(&self) -> &str {
&self.s[self.cur_idx..]
}
*/
}

impl<'a> Iterator for AnsiCodeIterator<'a> {
Expand Down
49 changes: 21 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ use clap::Parser;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
_prompt: Option<String>,
prompt: Option<String>,

#[arg(trailing_var_arg = true, num_args(0..))]
_ingore_rest: Option<String>,

#[arg(long, default_value_t = false)]
setup: bool,
}

use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Default)]
pub struct Config {
secure: bool,
prompt: Prompt,
}

/*
impl Default for Config {
fn default() -> Self {
Self {
Expand All @@ -28,6 +32,7 @@ impl Default for Config {
}
}
}
*/

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
struct Prompt {
Expand Down Expand Up @@ -55,17 +60,12 @@ impl Default for Prompt {

use termios::*;

use ansi_escapes;

use colored::*;

use read_char::read_next_char;

use xdg;

use std::fs::File;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
use std::iter::Cycle;
use std::os::fd::AsRawFd;
Expand All @@ -79,10 +79,10 @@ impl TermiosWrapper {
fn new() -> Self {
let mut termios: Termios = Termios::from_fd(stdin().as_raw_fd()).unwrap();
tcgetattr(stdin().as_raw_fd(), &mut termios).unwrap();
return Self {
orig_termios: termios.clone(),
Self {
orig_termios: termios,
termios,
};
}
}
fn raw(&mut self) {
tcgetattr(stdin().as_raw_fd(), &mut self.termios).unwrap();
Expand All @@ -106,7 +106,7 @@ enum SpinType {
Secure,
}

fn spin<T>(way: SpinType, tty: &mut File, iter: &mut Cycle<T>, password: &String, prompt: &Prompt)
fn spin<T>(way: SpinType, tty: &mut File, iter: &mut Cycle<T>, password: &str, prompt: &Prompt)
where
T: Iterator<Item = char>,
T: Clone,
Expand Down Expand Up @@ -162,13 +162,9 @@ where
fn get_config() -> Option<Config> {
let some_config_path = xdg::BaseDirectories::new()
.unwrap()
.find_config_file("sudo-askpass.yml");
.find_config_file("sudo-askpass.yml")?;

if some_config_path.is_none() {
return None;
}

let some_config_string = std::fs::read_to_string(some_config_path.unwrap());
let some_config_string = std::fs::read_to_string(some_config_path);

if some_config_string.is_err() {
return None;
Expand Down Expand Up @@ -200,14 +196,6 @@ fn main() {

let mut password: String = String::new();

//let spinner = Prompt {
// characters: MOON_SPINNER_CHARACTERS.to_vec(),
// empty: '󱃓',
// secure: '󰦝',
// offset: 4,
// prompt_text: "Enter password < S > ".to_string().yellow().to_string(),
//};

let spinner = config.prompt;

let mut spinner_iter = spinner.characters.clone().into_iter().cycle();
Expand All @@ -222,6 +210,11 @@ fn main() {
}

let mut text = spinner.prompt_text.clone();

if args.prompt.is_some() && !args.prompt.clone().unwrap_or_default().contains("sudo") {
text = args.prompt.unwrap() + "< $ > ";
}

text.insert_str(0, format!("\x1B[{}m", spinner.prompt_ansi_color).as_str());
text.push_str("\x1B[0m");

Expand Down Expand Up @@ -290,12 +283,12 @@ fn main() {
}
}

write!(tty, "\n").unwrap();
writeln!(tty).unwrap();

write!(stdout(), "{}\n", password).unwrap();
println!("{}", password);
}

const CLOCK_SPINNER_CHARACTERS: [char; 8] = ['󰪞', '󰪟', '󰪠', '󰪡', '󰪢', '󰪣', '󰪤', '󰪥'];
//const CLOCK_SPINNER_CHARACTERS: [char; 8] = ['󰪞', '󰪟', '󰪠', '󰪡', '󰪢', '󰪣', '󰪤', '󰪥'];

const MOON_SPINNER_CHARACTERS: [char; 24] = [
'', // 6
Expand Down

0 comments on commit 2316cb1

Please sign in to comment.