summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config/mod.rs8
-rw-r--r--src/main.rs10
-rw-r--r--src/repl/mod.rs6
3 files changed, 15 insertions, 9 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 6b99483..cbf1020 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -11,7 +11,7 @@ use crate::client::{
Model, OpenAIClient, SendData,
};
use crate::render::{MarkdownRender, RenderOptions};
-use crate::utils::{get_env_name, light_theme_from_colorfgbg, now, render_prompt};
+use crate::utils::{get_env_name, light_theme_from_colorfgbg, now, render_prompt, set_text};
use anyhow::{anyhow, bail, Context, Result};
use inquire::{Confirm, Select, Text};
@@ -247,6 +247,12 @@ impl Config {
.with_context(|| "Failed to save message")
}
+ pub fn maybe_copy(&self, text: &str) {
+ if self.auto_copy {
+ let _ = set_text(text);
+ }
+ }
+
pub fn config_file() -> Result<PathBuf> {
Self::local_path(CONFIG_FILE_NAME)
}
diff --git a/src/main.rs b/src/main.rs
index f9be816..30e7f8f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -122,7 +122,7 @@ fn start_directive(
config.read().maybe_print_send_tokens(&input);
let output = if !stdout().is_terminal() || no_stream {
let output = client.send_message(input.clone())?;
- let to_print = if code_mode && output.trim_start().starts_with("```") {
+ let output = if code_mode && output.trim_start().starts_with("```") {
extract_block(&output)
} else {
output.clone()
@@ -130,16 +130,17 @@ fn start_directive(
if no_stream {
let render_options = config.read().get_render_options()?;
let mut markdown_render = MarkdownRender::init(render_options)?;
- println!("{}", markdown_render.render(&to_print).trim());
+ println!("{}", markdown_render.render(&output).trim());
} else {
- println!("{}", to_print);
+ println!("{}", output);
}
output
} else {
let abort = create_abort_signal();
render_stream(&input, client.as_ref(), config, abort)?
};
- config.write().save_message(input, &output)
+ config.write().save_message(input, &output)?;
+ Ok(())
}
fn start_interactive(config: &GlobalConfig) -> Result<()> {
@@ -157,6 +158,7 @@ fn execute(config: &GlobalConfig, text: &str) -> Result<()> {
eval_str = extract_block(&eval_str);
}
config.write().save_message(input, &eval_str)?;
+ config.read().maybe_copy(&eval_str);
let render_options = config.read().get_render_options()?;
let mut markdown_render = MarkdownRender::init(render_options)?;
if config.read().dry_run {
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index 3edf5f6..118ff0c 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -273,9 +273,7 @@ impl Repl {
ensure_model_capabilities(client.as_mut(), input.required_capabilities())?;
let output = render_stream(&input, client.as_ref(), &self.config, self.abort.clone())?;
self.config.write().save_message(input, &output)?;
- if self.config.read().auto_copy {
- let _ = self.copy(&output);
- }
+ self.config.read().maybe_copy(&output);
Ok(())
}
@@ -352,7 +350,7 @@ Type ".help" for more information.
fn copy(&self, text: &str) -> Result<()> {
if text.is_empty() {
- bail!("No text")
+ bail!("Empty text")
}
set_text(text)?;
Ok(())