Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tycode-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tycode-cli"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
authors = ["tigy"]
description = "CLI interface for TyCode"
Expand All @@ -26,7 +26,8 @@ terminal_size = "0.4"
# Utilities
anyhow = { workspace = true }
dirs = "5.0"
rustyline = "15"
rustyline = { version = "15", features = ["custom-bindings"] }
crossterm = "0.28"

# Logging and tracing
tracing = { workspace = true }
Expand Down
43 changes: 43 additions & 0 deletions tycode-cli/src/autocomplete/completer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use tycode_core::chat::commands::{get_available_commands, CommandInfo};

use super::CommandSuggestion;

pub struct CommandCompleter {
commands: Vec<CommandInfo>,
}

impl Default for CommandCompleter {
fn default() -> Self {
Self::new()
}
}

impl CommandCompleter {
pub fn new() -> Self {
// Filter out hidden commands
let commands: Vec<CommandInfo> = get_available_commands()
.into_iter()
.filter(|cmd| !cmd.hidden)
.collect();

Self { commands }
}

/// Filter commands based on partial input (characters after "/")
/// Returns all non-hidden commands when filter is empty
pub fn filter(&self, filter: &str) -> Vec<CommandSuggestion> {
let filter_lower = filter.to_lowercase();

self.commands
.iter()
.filter(|cmd| {
// Filter on command name only (not description)
filter.is_empty() || cmd.name.to_lowercase().starts_with(&filter_lower)
})
.map(|cmd| CommandSuggestion {
name: cmd.name.clone(),
description: cmd.description.clone(),
})
.collect()
}
}
Loading