summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authorshane s <stephenson.shane.a@gmail.com>2023-05-04 09:22:12 -0400
committerGitHub <noreply@github.com>2023-05-04 21:22:12 +0800
commitcf03952c7bd44a3ad94a675b846cdfafb2af1c75 (patch)
tree8c7cffe33e8650580635553b24efeceaafba6eaa /src/config
parent2489e34993986251a56dbc6dfe2233d85b02ac0e (diff)
downloadaichat-cf03952c7bd44a3ad94a675b846cdfafb2af1c75.tar.gz
feat: add `config.auto_copy` (#102)
* added config option to copy all ChatGPT output to clipboard * formatted with * updates --------- Co-authored-by: sigoden <sigoden@gmail.com>
Diffstat (limited to 'src/config')
-rw-r--r--src/config/mod.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 376f923..021d2c1 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -10,6 +10,7 @@ use crate::config::message::num_tokens_from_messages;
use crate::utils::{mask_text, now};
use anyhow::{anyhow, bail, Context, Result};
+use copypasta::{ClipboardContext, ClipboardProvider};
use inquire::{Confirm, Text};
use parking_lot::RwLock;
use serde::Deserialize;
@@ -70,6 +71,8 @@ pub struct Config {
pub light_theme: bool,
/// Set a timeout in seconds for connect to gpt
pub connect_timeout: usize,
+ /// Automatically copy the last message output to the clipboard
+ pub auto_copy: bool,
/// Predefined roles
#[serde(skip)]
pub roles: Vec<Role>,
@@ -97,6 +100,7 @@ impl Default for Config {
conversation_first: false,
light_theme: false,
connect_timeout: 10,
+ auto_copy: false,
roles: vec![],
role: None,
conversation: None,
@@ -169,6 +173,20 @@ impl Config {
Ok(path)
}
+ pub fn copy_message(&self, output: &str) -> Result<()> {
+ if self.auto_copy {
+ match ClipboardContext::new() {
+ Ok(mut ctx) => {
+ ctx.set_contents(output.to_string()).map_err(|err| {
+ anyhow!("Error: Unable to the last message output to clipboard, {err}")
+ })?;
+ }
+ Err(_) => bail!("Error: Unable to access clipboard context."),
+ }
+ }
+ Ok(())
+ }
+
pub fn save_message(&self, input: &str, output: &str) -> Result<()> {
if !self.save {
return Ok(());