mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2026-02-02 15:45:11 +01:00
chore: better output
This commit is contained in:
parent
551edc2828
commit
cf9e6882e6
5 changed files with 100 additions and 24 deletions
76
Cargo.lock
generated
76
Cargo.lock
generated
|
|
@ -654,6 +654,17 @@ dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "io-lifetimes"
|
||||||
|
version = "1.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.10.1"
|
version = "2.10.1"
|
||||||
|
|
@ -702,6 +713,12 @@ version = "0.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "64804cc6a5042d4f05379909ba25b503ec04e2c082151d62122d5dcaa274b961"
|
checksum = "64804cc6a5042d4f05379909ba25b503ec04e2c082151d62122d5dcaa274b961"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linux-raw-sys"
|
||||||
|
version = "0.3.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.4.14"
|
version = "0.4.14"
|
||||||
|
|
@ -850,6 +867,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sys-locale",
|
"sys-locale",
|
||||||
|
"textwrap",
|
||||||
"toml 0.8.19",
|
"toml 0.8.19",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -1062,6 +1080,20 @@ version = "0.1.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustix"
|
||||||
|
version = "0.37.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"errno",
|
||||||
|
"io-lifetimes",
|
||||||
|
"libc",
|
||||||
|
"linux-raw-sys 0.3.8",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "0.38.41"
|
version = "0.38.41"
|
||||||
|
|
@ -1071,7 +1103,7 @@ dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys",
|
"linux-raw-sys 0.4.14",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -1258,6 +1290,12 @@ version = "1.13.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smawk"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
version = "0.5.7"
|
version = "0.5.7"
|
||||||
|
|
@ -1367,10 +1405,32 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix",
|
"rustix 0.38.41",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "terminal_size"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237"
|
||||||
|
dependencies = [
|
||||||
|
"rustix 0.37.27",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "textwrap"
|
||||||
|
version = "0.16.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9"
|
||||||
|
dependencies = [
|
||||||
|
"smawk",
|
||||||
|
"terminal_size",
|
||||||
|
"unicode-linebreak",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinystr"
|
name = "tinystr"
|
||||||
version = "0.7.6"
|
version = "0.7.6"
|
||||||
|
|
@ -1537,6 +1597,18 @@ version = "1.0.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
|
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-linebreak"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ toml = { version = "0.8", optional = true }
|
||||||
serde_json = { version = "1.0", optional = true }
|
serde_json = { version = "1.0", optional = true }
|
||||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
reqwest = { version = "0.12", features = ["blocking", "json"], optional = true }
|
reqwest = { version = "0.12", features = ["blocking", "json"], optional = true }
|
||||||
|
textwrap = { version = "0.16", features = ["terminal_size"], optional = true}
|
||||||
|
|
||||||
pay-respects-parser = "0.2.5"
|
pay-respects-parser = "0.2.5"
|
||||||
# pay-respects-parser = { path = "../pay-respects-parser" }
|
# pay-respects-parser = { path = "../pay-respects-parser" }
|
||||||
|
|
@ -32,7 +33,7 @@ pay-respects-parser = "0.2.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
runtime-rules = ["dep:serde", "dep:toml"]
|
runtime-rules = ["dep:serde", "dep:toml"]
|
||||||
request-ai = ["dep:serde", "dep:serde_json", "dep:reqwest"]
|
request-ai = ["dep:serde", "dep:serde_json", "dep:reqwest", "dep:textwrap"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
|
|
|
||||||
10
src/main.rs
10
src/main.rs
|
|
@ -64,7 +64,10 @@ fn main() {
|
||||||
let mut last_command = shell::last_command(&shell);
|
let mut last_command = shell::last_command(&shell);
|
||||||
last_command = shell::expand_alias(&shell, &last_command);
|
last_command = shell::expand_alias(&shell, &last_command);
|
||||||
let mut error_msg = command_output(&shell, &last_command);
|
let mut error_msg = command_output(&shell, &last_command);
|
||||||
error_msg = error_msg.split_whitespace().collect::<Vec<&str>>().join(" ");
|
error_msg = error_msg
|
||||||
|
.split_whitespace()
|
||||||
|
.collect::<Vec<&str>>()
|
||||||
|
.join(" ");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let suggestion = {
|
let suggestion = {
|
||||||
|
|
@ -93,7 +96,10 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
last_command = suggestion;
|
last_command = suggestion;
|
||||||
error_msg = execution.err().unwrap();
|
error_msg = execution.err().unwrap();
|
||||||
error_msg = error_msg.split_whitespace().collect::<Vec<&str>>().join(" ");
|
error_msg = error_msg
|
||||||
|
.split_whitespace()
|
||||||
|
.collect::<Vec<&str>>()
|
||||||
|
.join(" ");
|
||||||
|
|
||||||
let retry_message = format!("{}...", t!("retry"));
|
let retry_message = format!("{}...", t!("retry"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,12 @@ pub struct AISuggest {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ai_suggestion(last_command: &str, error_msg: &str) -> Option<AISuggest> {
|
pub fn ai_suggestion(last_command: &str, error_msg: &str) -> Option<AISuggest> {
|
||||||
|
let error_msg = if error_msg.len() > 300 {
|
||||||
|
&error_msg[..300]
|
||||||
|
} else {
|
||||||
|
error_msg
|
||||||
|
};
|
||||||
|
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("last_command", last_command);
|
map.insert("last_command", last_command);
|
||||||
map.insert("error_msg", error_msg);
|
map.insert("error_msg", error_msg);
|
||||||
|
|
@ -57,9 +63,12 @@ pub fn ai_suggestion(last_command: &str, error_msg: &str) -> Option<AISuggest> {
|
||||||
Err(_) => "llama3-8b-8192".to_string(),
|
Err(_) => "llama3-8b-8192".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_locale = std::env::var("_PR_LOCALE").unwrap_or("en_US".to_string());
|
let user_locale = std::env::var("_PR_LOCALE").unwrap_or("en-US".to_string());
|
||||||
let set_locale = if user_locale != "en_US" {
|
let set_locale = if user_locale != "en-US" {
|
||||||
format!("Plese provide the note in the language for the locale {}", user_locale)
|
format!(
|
||||||
|
"Plese provide the note in the language for the locale {}\n",
|
||||||
|
user_locale
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
|
|
@ -70,8 +79,7 @@ You run the command `{last_command}` and get the following error message: `{erro
|
||||||
```
|
```
|
||||||
{{"command":"your suggestion","note":"why you think this command will fix the error"}}
|
{{"command":"your suggestion","note":"why you think this command will fix the error"}}
|
||||||
```
|
```
|
||||||
{set_locale}
|
{set_locale}If you don't know the answer or can't provide a good suggestion, please reply the command field with `None` and a explanation in note
|
||||||
If you don't know the answer or can't provide a good suggestion, please reply the command field with `None` and a explanation in note
|
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,23 +59,12 @@ pub fn suggest_command(shell: &str, last_command: &str, error_msg: &str) -> Opti
|
||||||
#[cfg(feature = "request-ai")]
|
#[cfg(feature = "request-ai")]
|
||||||
{
|
{
|
||||||
use crate::requests::ai_suggestion;
|
use crate::requests::ai_suggestion;
|
||||||
|
use textwrap::{fill, termwidth};
|
||||||
let suggest = ai_suggestion(last_command, error_msg);
|
let suggest = ai_suggestion(last_command, error_msg);
|
||||||
if let Some(suggest) = suggest {
|
if let Some(suggest) = suggest {
|
||||||
let suggest_note = suggest.note.split_whitespace().collect::<Vec<&str>>();
|
|
||||||
let mut note = String::new();
|
|
||||||
let mut line = String::new();
|
|
||||||
for word in suggest_note {
|
|
||||||
if line.len() + word.len() > 80 {
|
|
||||||
note.push_str(&line);
|
|
||||||
note.push('\n');
|
|
||||||
line.clear();
|
|
||||||
}
|
|
||||||
line.push_str(word);
|
|
||||||
line.push(' ');
|
|
||||||
}
|
|
||||||
note.push_str(&line);
|
|
||||||
|
|
||||||
let warn = format!("{}:", t!("ai-suggestion")).bold().blue();
|
let warn = format!("{}:", t!("ai-suggestion")).bold().blue();
|
||||||
|
let note = fill(&suggest.note, termwidth());
|
||||||
|
|
||||||
eprintln!("{}\n{}\n", warn, note);
|
eprintln!("{}\n{}\n", warn, note);
|
||||||
let command = suggest.command;
|
let command = suggest.command;
|
||||||
if command != "None" {
|
if command != "None" {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue