summaryrefslogtreecommitdiffstats
path: root/src/repl
diff options
context:
space:
mode:
Diffstat (limited to 'src/repl')
-rw-r--r--src/repl/handler.rs28
-rw-r--r--src/repl/mod.rs29
2 files changed, 41 insertions, 16 deletions
diff --git a/src/repl/handler.rs b/src/repl/handler.rs
index d70abbe..afe016a 100644
--- a/src/repl/handler.rs
+++ b/src/repl/handler.rs
@@ -1,7 +1,7 @@
use crate::client::init_client;
use crate::config::SharedConfig;
use crate::print_now;
-use crate::render::render_stream;
+use crate::render::{render_stream, MarkdownRender};
use std::fs;
use std::io::Read;
@@ -15,7 +15,9 @@ use std::cell::RefCell;
pub enum ReplCmd {
Submit(String),
- ViewInfo,
+ Info,
+ RoleInfo,
+ SessionInfo,
SetModel(String),
SetRole(String),
ExitRole,
@@ -66,7 +68,7 @@ impl ReplCmdHandler {
let _ = self.copy(&buffer);
}
}
- ReplCmd::ViewInfo => {
+ ReplCmd::Info => {
let output = self.config.read().info()?;
print_now!("{}\n\n", output.trim_end());
}
@@ -75,8 +77,15 @@ impl ReplCmdHandler {
print_now!("\n");
}
ReplCmd::SetRole(name) => {
- let output = self.config.write().set_role(&name)?;
- print_now!("{}\n\n", output.trim_end());
+ self.config.write().set_role(&name)?;
+ print_now!("\n");
+ }
+ ReplCmd::RoleInfo => {
+ if let Some(role) = &self.config.read().role {
+ print_now!("{}\n\n", role.info()?);
+ } else {
+ bail!("No role")
+ }
}
ReplCmd::ExitRole => {
self.config.write().clear_role()?;
@@ -86,6 +95,15 @@ impl ReplCmdHandler {
self.config.write().start_session(&name)?;
print_now!("\n");
}
+ ReplCmd::SessionInfo => {
+ if let Some(session) = &self.config.read().session {
+ let render_options = self.config.read().get_render_options();
+ let mut markdown_render = MarkdownRender::init(render_options)?;
+ print_now!("{}\n\n", session.render(&mut markdown_render)?);
+ } else {
+ bail!("No session")
+ }
+ }
ReplCmd::ExitSession => {
self.config.write().end_session()?;
print_now!("\n");
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index e5691dc..4cf59f7 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -18,14 +18,16 @@ use lazy_static::lazy_static;
use reedline::Signal;
use std::rc::Rc;
-pub const REPL_COMMANDS: [(&str, &str); 12] = [
+pub const REPL_COMMANDS: [(&str, &str); 14] = [
(".help", "Print this help message"),
- (".info", "Print system-wide information"),
+ (".info", "Print system info"),
(".edit", "Multi-line editing (CTRL+S to finish)"),
(".model", "Switch LLM model"),
(".role", "Use role"),
+ (".info role", "Show role info"),
(".exit role", "Leave current role"),
(".session", "Start a context-aware chat session"),
+ (".info session", "Show session info"),
(".exit session", "End the current session"),
(".set", "Modify the configuration parameters"),
(".copy", "Copy the last reply to the clipboard"),
@@ -66,7 +68,7 @@ impl Repl {
}
Err(err) => {
let err = format!("{err:?}");
- print_now!("{}\n\n", err.trim());
+ print_now!("Error: {}\n\n", err.trim());
}
}
}
@@ -95,9 +97,14 @@ impl Repl {
".help" => {
dump_repl_help();
}
- ".info" => {
- handler.handle(ReplCmd::ViewInfo)?;
- }
+ ".info" => match args {
+ Some("role") => handler.handle(ReplCmd::RoleInfo)?,
+ Some("session") => handler.handle(ReplCmd::SessionInfo)?,
+ Some(_) => unknown_command(),
+ None => {
+ handler.handle(ReplCmd::Info)?;
+ }
+ },
".edit" => {
if let Some(text) = args {
handler.handle(ReplCmd::Submit(text.to_string()))?;
@@ -128,7 +135,7 @@ impl Repl {
".exit" => match args {
Some("role") => handler.handle(ReplCmd::ExitRole)?,
Some("session") => handler.handle(ReplCmd::ExitSession)?,
- Some(_) => dump_unknown_command(),
+ Some(_) => unknown_command(),
None => {
return Ok(true);
}
@@ -141,9 +148,9 @@ impl Repl {
Some("session") => {
print_now!("Deprecated. Use '.exit session' instead.\n\n");
}
- _ => dump_unknown_command(),
+ _ => unknown_command(),
},
- _ => dump_unknown_command(),
+ _ => unknown_command(),
},
None => {
handler.handle(ReplCmd::Submit(line.to_string()))?;
@@ -154,8 +161,8 @@ impl Repl {
}
}
-fn dump_unknown_command() {
- print_now!("Unknown command. Type \".help\" for more information.\n\n");
+fn unknown_command() {
+ print_now!("Unknown command. Try `.help`.\n\n");
}
fn dump_repl_help() {