diff options
| author | sigoden <sigoden@gmail.com> | 2023-10-30 17:28:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-30 17:28:10 +0800 |
| commit | 4909a20f2e31361f49557c2e597f6f816e3674f3 (patch) | |
| tree | d09d31975d9fdf4747da68c87b3d6e9b1cb356ec | |
| parent | 22031639382b4afebae2560f12c6e66ec44a2898 (diff) | |
| download | aichat-4909a20f2e31361f49557c2e597f6f816e3674f3.tar.gz | |
feat: force nowrap if no tty/terminal (#182)
| -rw-r--r-- | README.md | 17 | ||||
| -rw-r--r-- | src/config/mod.rs | 15 |
2 files changed, 16 insertions, 16 deletions
@@ -286,8 +286,6 @@ Options: -V, --version Print version ``` -Examples: - ```sh aichat -s # Start REPL with a new temp session aichat -s temp # Use temp session @@ -295,6 +293,13 @@ aichat -r shell -s # Create a session with a role aichat -m openai:gpt-4-32k -s # Create a session with a model aichat -s sh unzip a file # Run session in command mode +aichat -r shell unzip a file # Use role in command mode +aichat -s shell unzip a file # Use session in command mode + +cat config.json | aichat convert to yaml # Read stdin +cat config.json | aichat -r convert:yaml # Read stdin with a role +cat config.json | aichat -s i18n # Read stdin with a session + aichat --list-models # List all available models aichat --list-roles # List all available roles aichat --list-sessions # List all available models @@ -303,13 +308,7 @@ aichat --info # system-wide information aichat -s temp --info # Show session details aichat -r shell --info # Show role info - -aichat -r shell unzip a file # Use role in command mode -aichat -s shell unzip a file # Use session in command mode - -cat config.json | aichat convert to yaml # Read stdin -cat config.json | aichat -r convert:yaml # Read stdin with a role -cat config.json | aichat -s i18n # Read stdin with a session +$(echo "$data" | aichat -S -H to json) # Use aichat in a script ``` ## License diff --git a/src/config/mod.rs b/src/config/mod.rs index fbdd5b5..e6d9238 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -14,12 +14,13 @@ use crate::utils::{get_env_name, light_theme_from_colorfgbg, now}; use anyhow::{anyhow, bail, Context, Result}; use inquire::{Confirm, Select, Text}; +use is_terminal::IsTerminal; use parking_lot::RwLock; use serde::Deserialize; use std::{ env, fs::{create_dir_all, read_dir, read_to_string, remove_file, File, OpenOptions}, - io::Write, + io::{stdout, Write}, path::{Path, PathBuf}, process::exit, sync::Arc, @@ -524,12 +525,12 @@ impl Config { } pub fn get_render_options(&self) -> RenderOptions { - RenderOptions::new( - self.highlight, - self.light_theme, - self.wrap.clone(), - self.wrap_code, - ) + let wrap = if stdout().is_terminal() { + self.wrap.clone() + } else { + None + }; + RenderOptions::new(self.highlight, self.light_theme, wrap, self.wrap_code) } pub fn maybe_print_send_tokens(&self, input: &str) { |
