Skip to content

Commit

Permalink
display formatter prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Jan 19, 2024
1 parent b27252c commit d100f96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std;
use std::collections::HashMap;
use std::sync::atomic::AtomicBool;

use crate::config::Config;
use crate::notification::Notification;
use crate::spinner::Spinner;
use crate::{config::Config, formatter::Formatter};
use crossterm::event::KeyCode;
use tui::text::{Line, Text};

Expand Down Expand Up @@ -46,16 +46,18 @@ pub struct Chat<'a> {
}

#[derive(Debug)]
pub struct Prompt {
pub struct Prompt<'a> {
pub message: String,
pub formatted_prompt: Text<'a>,
pub scroll: u16,
pub length: u16,
}

impl Default for Prompt {
impl Default for Prompt<'_> {
fn default() -> Self {
Self {
message: String::from(">_ "),
formatted_prompt: Text::raw(">_ "),
scroll: 0,
length: 0,
}
Expand All @@ -70,7 +72,7 @@ pub struct Answer<'a> {

pub struct App<'a> {
pub running: bool,
pub prompt: Prompt,
pub prompt: Prompt<'a>,
pub mode: Mode,
pub chat: Chat<'a>,
pub previous_key: KeyCode,
Expand All @@ -82,10 +84,11 @@ pub struct App<'a> {
pub notifications: Vec<Notification>,
pub spinner: Spinner,
pub terminate_response_signal: Arc<AtomicBool>,
pub formatter: &'a Formatter<'a>,
}

impl<'a> App<'a> {
pub fn new(config: Arc<Config>) -> Self {
pub fn new(config: Arc<Config>, formatter: &'a Formatter<'a>) -> Self {
Self {
running: true,
prompt: Prompt::default(),
Expand All @@ -100,6 +103,7 @@ impl<'a> App<'a> {
notifications: Vec::new(),
spinner: Spinner::default(),
terminate_response_signal: Arc::new(AtomicBool::new(false)),
formatter,
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ pub fn handle_key_events(

app.chat.messages.push(format!(" : {}\n", user_input));

app.chat
.formatted_chat
.lines
.push(Line::raw(format!(" : {}\n", user_input)));
app.chat.formatted_chat.extend(
app.formatter
.format(format!(" : {}\n", user_input).as_str()),
);

let conv = HashMap::from([
("role".into(), "user".into()),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() -> AppResult<()> {

let formatter = Formatter::new(&formatter_config, &formatter_assets);

let mut app = App::new(config.clone());
let mut app = App::new(config.clone(), &formatter);

let llm = Arc::new(LLMModel::init(LLMBackend::ChatGPT, config));

Expand Down

0 comments on commit d100f96

Please sign in to comment.