From d11e10032a73fb25421fd3e45155ec88086e65ea Mon Sep 17 00:00:00 2001 From: Chris Overcash Date: Wed, 20 Nov 2024 21:40:57 -0600 Subject: [PATCH] chore: address clippy lints --- .github/workflows/rust.yml | 2 ++ README.md | 4 ++++ justfile | 7 +++++++ ollama-cli/src/tui/chat/mod.rs | 2 +- ollama-cli/src/tui/{event.rs => event/mod.rs} | 9 +++++++++ ollama-cli/src/tui/messages/state.rs | 4 ---- ollama-cli/src/tui/mod.rs | 5 +++-- ollama-cli/src/tui/model_context.rs | 1 - ollama-cli/src/tui/models/mod.rs | 5 ----- ollama-cli/src/tui/models/model_list.rs | 2 +- ollama-cli/src/tui/models/modelfile.rs | 16 ++++++++++------ 11 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 justfile rename ollama-cli/src/tui/{event.rs => event/mod.rs} (83%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bafb54b..29e381c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,6 +19,8 @@ jobs: - name: typos-action uses: crate-ci/typos@v1.27.3 - uses: actions/checkout@v4 + - name: lint + run: cargo clippy - name: Build run: cargo build --verbose - name: Run tests diff --git a/README.md b/README.md index 7af4c63..3040ac1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ a Rust playground for running language models and some other machine learning models. +## `ollama-cli` + +a CLI/TUI for interacting with an [Ollama] server. + ## `djinn-cli` the main entrypoint for running either diff --git a/justfile b/justfile new file mode 100644 index 0000000..48e0a91 --- /dev/null +++ b/justfile @@ -0,0 +1,7 @@ +tui: + cargo run --bin ollama-cli -- tui + +check: + typos + cargo clippy + cargo test --all diff --git a/ollama-cli/src/tui/chat/mod.rs b/ollama-cli/src/tui/chat/mod.rs index 7362a63..48591ad 100644 --- a/ollama-cli/src/tui/chat/mod.rs +++ b/ollama-cli/src/tui/chat/mod.rs @@ -167,7 +167,7 @@ pub impl<'a> Frame<'a> { "e".bold(), " to start editing.".bold(), ], - Style::default().add_modifier(Modifier::RAPID_BLINK), + style.add_modifier(Modifier::RAPID_BLINK), ), InputMode::Edit => ( vec![ diff --git a/ollama-cli/src/tui/event.rs b/ollama-cli/src/tui/event/mod.rs similarity index 83% rename from ollama-cli/src/tui/event.rs rename to ollama-cli/src/tui/event/mod.rs index d55971f..6bf599d 100644 --- a/ollama-cli/src/tui/event.rs +++ b/ollama-cli/src/tui/event/mod.rs @@ -1,5 +1,12 @@ use crossterm::event::{Event, KeyCode, KeyEvent}; +#[derive(Debug, Clone, PartialEq)] +pub struct ActionDefinition { + action: Action, + key: KeyEvent, + description: String, +} + #[derive(Debug, Clone, Copy, PartialEq, Default)] pub enum Action { Left, @@ -40,6 +47,8 @@ impl From for Action { KeyCode::Char('h') => Action::Left, KeyCode::Char('l') => Action::Right, KeyCode::Char('r') => Action::Refresh, + KeyCode::Char('w') => Action::RightWord, + KeyCode::Char('b') => Action::LeftWord, KeyCode::Enter => Action::Enter, _ => Action::Unhandled, } diff --git a/ollama-cli/src/tui/messages/state.rs b/ollama-cli/src/tui/messages/state.rs index bc853bf..5c119df 100644 --- a/ollama-cli/src/tui/messages/state.rs +++ b/ollama-cli/src/tui/messages/state.rs @@ -1,11 +1,7 @@ use ratatui::widgets::ListState; -use super::view::MessageContent; - #[derive(Debug, Clone, Default)] pub struct MessagesState { - cursor: usize, - message_view: Vec, pub list_state: ListState, } diff --git a/ollama-cli/src/tui/mod.rs b/ollama-cli/src/tui/mod.rs index 8244614..155c7b7 100644 --- a/ollama-cli/src/tui/mod.rs +++ b/ollama-cli/src/tui/mod.rs @@ -1,4 +1,4 @@ -use std::{io::stdout, process::Command, time::Duration}; +use std::{io::stdout, time::Duration}; use chat::ChatViewModel; use crossterm::ExecutableCommand as _; @@ -120,6 +120,7 @@ impl AppContext { Ok(app_event) } + // TODO: use this function with [`modelfile`] fn edit_model_file( &mut self, terminal: &mut DefaultTerminal, @@ -131,7 +132,7 @@ impl AppContext { let mut edit_options = edit::Builder::default(); let edit_options = edit_options.suffix(".tmpl"); - let edited_modelfile = edit::edit_with_builder(model_info.modelfile, edit_options)?; + let _edited_modelfile = edit::edit_with_builder(model_info.modelfile, edit_options)?; stdout().execute(crossterm::terminal::EnterAlternateScreen)?; crossterm::terminal::enable_raw_mode()?; diff --git a/ollama-cli/src/tui/model_context.rs b/ollama-cli/src/tui/model_context.rs index 0a35938..6896c59 100644 --- a/ollama-cli/src/tui/model_context.rs +++ b/ollama-cli/src/tui/model_context.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use futures::StreamExt; -use ollama_rs::models::{LocalModel, ModelInfo}; use tokio::{ sync::mpsc::{Receiver, Sender}, task::JoinHandle, diff --git a/ollama-cli/src/tui/models/mod.rs b/ollama-cli/src/tui/models/mod.rs index 2707058..874fe1b 100644 --- a/ollama-cli/src/tui/models/mod.rs +++ b/ollama-cli/src/tui/models/mod.rs @@ -51,10 +51,6 @@ impl ModelsViewModel { if let Some(model_event) = model_event { match model_event { - ModelEvent::Activate(pane) => { - self.active_pane = Some(pane); - Ok(None) - } ModelEvent::Deactivate => { self.active_pane = None; Ok(None) @@ -94,7 +90,6 @@ impl ModelsViewModel { #[derive(Clone, Debug)] pub enum ModelEvent { - Activate(Pane), Deactivate, EditInfo(ModelInfo), GetInfo(ModelName), diff --git a/ollama-cli/src/tui/models/model_list.rs b/ollama-cli/src/tui/models/model_list.rs index 687bb72..0cbaa67 100644 --- a/ollama-cli/src/tui/models/model_list.rs +++ b/ollama-cli/src/tui/models/model_list.rs @@ -5,7 +5,7 @@ use ollama_rs::models::LocalModel; use ratatui::{ layout::{Constraint, Layout, Rect}, style::{Color, Style}, - text::{Line, Span}, + text::Span, widgets::{Block, Row, Table, TableState}, Frame, }; diff --git a/ollama-cli/src/tui/models/modelfile.rs b/ollama-cli/src/tui/models/modelfile.rs index 6b9e834..9c63d5a 100644 --- a/ollama-cli/src/tui/models/modelfile.rs +++ b/ollama-cli/src/tui/models/modelfile.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use modelfile::Modelfile; use ratatui::{ - layout::{Constraint, Layout, Offset, Rect}, + layout::{Constraint, Layout, Rect}, style::{Color, Style}, widgets::{Block, List, ListState, Paragraph, Wrap}, Frame, @@ -21,10 +21,7 @@ pub struct ModelfileViewModel { instructions: Vec, details: Option, list_state: ListState, - /// x, y scroll offset - scroll_offset: Offset, - wrap: bool, - active_panel: Panel, + active_panel: Option, } impl ModelfileViewModel { @@ -61,7 +58,14 @@ impl ModelfileViewModel { self.update_details()?; Ok(None) } - Action::Enter => todo!(), + Action::Enter => { + if let Some(_selected) = self.selected { + self.active_panel = Some(Panel::Details); + Ok(None) + } else { + Ok(None) + } + } Action::Left => todo!(), Action::Right => todo!(), Action::LeftWord => todo!(),