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

Improve code quality a little bit #352

Merged
merged 11 commits into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
linting
  • Loading branch information
denisidoro committed Apr 25, 2020
commit 10a2b364e4a0fc1b07017762b3ed4d9109671142
32 changes: 16 additions & 16 deletions src/display/alfred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ impl Writer for AlfredWriter {

impl AlfredWriter {
pub fn write_suggestion(&mut self, snippet: &str, varname: &str, line: &str) {
if line.len() < 3 {
return
}
if line.len() < 3 {
return;
}

let prefix = if self.is_first {
self.is_first = false;
""
} else {
","
};
let prefix = if self.is_first {
self.is_first = false;
""
} else {
","
};

println!(
r#"{prefix}{{"title":"{value}","subtitle":"{snippet}","variables":{{"{varname}":"{value}"}},"icon":{{"path":"navi.png"}}}}"#,
prefix = prefix,
snippet = snippet,
varname = varname,
value = line
);
println!(
r#"{prefix}{{"title":"{value}","subtitle":"{snippet}","variables":{{"{varname}":"{value}"}},"icon":{{"path":"navi.png"}}}}"#,
prefix = prefix,
snippet = snippet,
varname = varname,
value = line
);
}
}
7 changes: 3 additions & 4 deletions src/flows/alfred.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::display;
use crate::parser;
use crate::structures::cheat::Suggestion;
use crate::structures::{error::command::BashSpawnError, option::Config};
use anyhow::Context;
use anyhow::Error;
use crate::display;
use std::env;
use std::process::{Command, Stdio};

Expand Down Expand Up @@ -72,11 +72,10 @@ pub fn suggestions(config: Config) -> Result<(), Error> {
Ok(prompt_with_suggestions(&varname, &config, suggestion).unwrap())
})?;

let mut writer = display::alfred::new_writer();
let mut writer = display::alfred::new_writer();

for line in lines.split('\n') {

writer.write_suggestion(&snippet, &varname, &line);
writer.write_suggestion(&snippet, &varname, &line);
}
} else {
display::alfred::print_items_start(None);
Expand Down