← back to hughdbrown__ollama-tui

Function bodies 141 total

All specs Real LLM only Function bodies
test_question_mark_closes_help function · rust · L604-L610 (7 LOC)
src/app.rs
    fn test_question_mark_closes_help() {
        let mut app = make_app_with_models(0, 0);
        app.show_help = true;

        app.handle_event(Event::Key(make_key_event(KeyCode::Char('?'))));
        assert!(!app.show_help);
    }
test_esc_closes_help function · rust · L613-L619 (7 LOC)
src/app.rs
    fn test_esc_closes_help() {
        let mut app = make_app_with_models(0, 0);
        app.show_help = true;

        app.handle_event(Event::Key(make_key_event(KeyCode::Esc)));
        assert!(!app.show_help);
    }
test_help_swallows_other_keys function · rust · L622-L630 (9 LOC)
src/app.rs
    fn test_help_swallows_other_keys() {
        let mut app = make_app_with_models(3, 0);
        app.show_help = true;

        // 'r' should not trigger refresh when help is open
        let action = app.handle_event(Event::Key(make_key_event(KeyCode::Char('r'))));
        assert!(matches!(action, Action::None));
        assert!(app.show_help);
    }
test_help_allows_quit function · rust · L633-L639 (7 LOC)
src/app.rs
    fn test_help_allows_quit() {
        let mut app = make_app_with_models(0, 0);
        app.show_help = true;

        app.handle_event(Event::Key(make_key_event(KeyCode::Char('q'))));
        assert!(!app.running);
    }
test_help_allows_ctrl_c_quit function · rust · L642-L649 (8 LOC)
src/app.rs
    fn test_help_allows_ctrl_c_quit() {
        let mut app = make_app_with_models(0, 0);
        app.show_help = true;

        let key = make_key_event_with_modifiers(KeyCode::Char('c'), KeyModifiers::CONTROL);
        app.handle_event(Event::Key(key));
        assert!(!app.running);
    }
base_url function · rust · L21-L38 (18 LOC)
src/cli.rs
    pub fn base_url(&self) -> String {
        format!("http://{}:{}", self.host, self.port)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_default_base_url() {
        let args = Args {
            host: "localhost".to_string(),
            port: 11434,
            refresh: 2,
        };
        assert_eq!(args.base_url(), "http://localhost:11434");
    }
test_default_base_url function · rust · L31-L48 (18 LOC)
src/cli.rs
    fn test_default_base_url() {
        let args = Args {
            host: "localhost".to_string(),
            port: 11434,
            refresh: 2,
        };
        assert_eq!(args.base_url(), "http://localhost:11434");
    }

    #[test]
    fn test_custom_base_url() {
        let args = Args {
            host: "192.168.1.100".to_string(),
            port: 8080,
            refresh: 5,
        };
        assert_eq!(args.base_url(), "http://192.168.1.100:8080");
    }
If a scraper extracted this row, it came from Repobility (https://repobility.com)
test_parse_defaults function · rust · L51-L56 (6 LOC)
src/cli.rs
    fn test_parse_defaults() {
        let args = Args::parse_from(["ollama-tui"]);
        assert_eq!(args.host, "localhost");
        assert_eq!(args.port, 11434);
        assert_eq!(args.refresh, 2);
    }
test_parse_custom_args function · rust · L59-L72 (14 LOC)
src/cli.rs
    fn test_parse_custom_args() {
        let args = Args::parse_from([
            "ollama-tui",
            "--host",
            "myserver",
            "--port",
            "9999",
            "--refresh",
            "10",
        ]);
        assert_eq!(args.host, "myserver");
        assert_eq!(args.port, 9999);
        assert_eq!(args.refresh, 10);
    }
new function · rust · L26-L67 (42 LOC)
src/event.rs
    pub fn new(tick_rate: Duration) -> Self {
        let (tx, rx) = mpsc::unbounded_channel();
        let sender = tx.clone();

        tokio::spawn(async move {
            let mut reader = EventStream::new();
            let mut tick = tokio::time::interval(tick_rate);

            loop {
                let tick_delay = tick.tick();
                let crossterm_event = reader.next();

                tokio::select! {
                    _ = sender.closed() => break,
                    _ = tick_delay => {
                        if sender.send(Event::Tick).is_err() {
                            break;
                        }
                    }
                    Some(Ok(evt)) = crossterm_event => {
                        match evt {
                            crossterm::event::Event::Key(key)
                                if key.kind == KeyEventKind::Press =>
                            {
                                if sender.send(Event::Key(key)).is_err() {
       
sender function · rust · L68-L71 (4 LOC)
src/event.rs
    pub fn sender(&self) -> mpsc::UnboundedSender<Event> {
        self.tx.clone()
    }
next function · rust · L72-L78 (7 LOC)
src/event.rs
    pub async fn next(&mut self) -> color_eyre::Result<Event> {
        self.rx
            .recv()
            .await
            .ok_or_else(|| eyre!("event channel closed"))
    }
from_channel function · rust · L81-L83 (3 LOC)
src/event.rs
    fn from_channel(tx: mpsc::UnboundedSender<Event>, rx: mpsc::UnboundedReceiver<Event>) -> Self {
        Self { rx, tx }
    }
spawn_poller function · rust · L85-L108 (24 LOC)
src/event.rs
pub fn spawn_poller(
    client: OllamaClient,
    tx: mpsc::UnboundedSender<Event>,
    interval: Duration,
    cancel: CancellationToken,
) {
    tokio::spawn(async move {
        let mut ticker = tokio::time::interval(interval);
        ticker.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);

        loop {
            tokio::select! {
                _ = cancel.cancelled() => break,
                _ = ticker.tick() => {
                    let state = client.poll_all().await;
                    if tx.send(Event::DataUpdate(state)).is_err() {
                        break;
                    }
                }
            }
        }
    });
}
test_next_receives_tick function · rust · L117-L124 (8 LOC)
src/event.rs
    async fn test_next_receives_tick() {
        let (tx, rx) = mpsc::unbounded_channel();
        let mut handler = EventHandler::from_channel(tx.clone(), rx);

        tx.send(Event::Tick).unwrap();
        let event = handler.next().await.unwrap();
        assert!(matches!(event, Event::Tick));
    }
Generated by Repobility's multi-pass static-analysis pipeline (https://repobility.com)
test_next_receives_key_event function · rust · L127-L146 (20 LOC)
src/event.rs
    async fn test_next_receives_key_event() {
        use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};

        let (tx, rx) = mpsc::unbounded_channel();
        let mut handler = EventHandler::from_channel(tx.clone(), rx);

        let key = KeyEvent {
            code: KeyCode::Char('q'),
            modifiers: KeyModifiers::NONE,
            kind: KeyEventKind::Press,
            state: KeyEventState::NONE,
        };
        tx.send(Event::Key(key)).unwrap();

        let event = handler.next().await.unwrap();
        match event {
            Event::Key(k) => assert_eq!(k.code, KeyCode::Char('q')),
            other => panic!("expected Key event, got {other:?}"),
        }
    }
test_next_receives_resize function · rust · L149-L162 (14 LOC)
src/event.rs
    async fn test_next_receives_resize() {
        let (tx, rx) = mpsc::unbounded_channel();
        let mut handler = EventHandler::from_channel(tx.clone(), rx);

        tx.send(Event::Resize(80, 24)).unwrap();
        let event = handler.next().await.unwrap();
        match event {
            Event::Resize(w, h) => {
                assert_eq!(w, 80);
                assert_eq!(h, 24);
            }
            other => panic!("expected Resize event, got {other:?}"),
        }
    }
test_next_errors_on_closed_channel function · rust · L165-L175 (11 LOC)
src/event.rs
    async fn test_next_errors_on_closed_channel() {
        let (tx, rx) = mpsc::unbounded_channel::<Event>();
        drop(tx);

        let mut handler = EventHandler {
            rx,
            tx: mpsc::unbounded_channel().0,
        };
        let result = handler.next().await;
        assert!(result.is_err());
    }
test_multiple_events_in_order function · rust · L178-L192 (15 LOC)
src/event.rs
    async fn test_multiple_events_in_order() {
        let (tx, rx) = mpsc::unbounded_channel();
        let mut handler = EventHandler::from_channel(tx.clone(), rx);

        tx.send(Event::Tick).unwrap();
        tx.send(Event::Resize(100, 50)).unwrap();
        tx.send(Event::Tick).unwrap();

        assert!(matches!(handler.next().await.unwrap(), Event::Tick));
        assert!(matches!(
            handler.next().await.unwrap(),
            Event::Resize(100, 50)
        ));
        assert!(matches!(handler.next().await.unwrap(), Event::Tick));
    }
test_data_update_event function · rust · L195-L209 (15 LOC)
src/event.rs
    async fn test_data_update_event() {
        let (tx, rx) = mpsc::unbounded_channel();
        let mut handler = EventHandler::from_channel(tx.clone(), rx);

        let state = OllamaState::default();
        tx.send(Event::DataUpdate(state)).unwrap();

        let event = handler.next().await.unwrap();
        match event {
            Event::DataUpdate(s) => {
                assert!(matches!(s.connection, ConnectionStatus::Connecting));
            }
            other => panic!("expected DataUpdate event, got {other:?}"),
        }
    }
test_sender_returns_clone function · rust · L212-L218 (7 LOC)
src/event.rs
    async fn test_sender_returns_clone() {
        let (tx, rx) = mpsc::unbounded_channel();
        let handler = EventHandler::from_channel(tx, rx);

        let sender = handler.sender();
        sender.send(Event::Tick).unwrap();
    }
test_spawn_poller_sends_data_updates function · rust · L221-L277 (57 LOC)
src/event.rs
    async fn test_spawn_poller_sends_data_updates() {
        let (tx, mut rx) = mpsc::unbounded_channel();
        let cancel = CancellationToken::new();

        // Use unreachable address so poll returns quickly with Disconnected
        let client = OllamaClient::new("http://127.0.0.1:1".to_string()).unwrap();

        spawn_poller(client, tx, Duration::from_millis(10), cancel.clone());

        // Wait for at least one DataUpdate event
        let event = tokio::time::timeout(Duration::from_secs(5), rx.recv())
            .await
            .expect("timed out waiting for poll")
            .expect("channel closed");

        match event {
            Event::DataUpdate(state) => {
                assert!(matches!(
                    state.connection,
                    ConnectionStatus::Disconnected(_)
                ));
            }
            other => panic!("expected DataUpdate, got {other:?}"),
        }

        cancel.cancel();
    }

    #[tokio::test]
    async fn test
format_bytes function · rust · L2-L19 (18 LOC)
src/format.rs
pub fn format_bytes(bytes: i64) -> String {
    const KB: f64 = 1024.0;
    const MB: f64 = 1024.0 * 1024.0;
    const GB: f64 = 1024.0 * 1024.0 * 1024.0;

    let b = bytes as f64;
    let abs_b = b.abs();
    if abs_b < KB {
        format!("{bytes} B")
    } else if abs_b < MB {
        format!("{:.1} KB", b / KB)
    } else if abs_b < GB {
        format!("{:.1} MB", b / MB)
    } else {
        format!("{:.1} GB", b / GB)
    }
}
Repobility · code-quality intelligence · https://repobility.com
format_countdown function · rust · L20-L43 (24 LOC)
src/format.rs
pub fn format_countdown(expires_at: &str) -> String {
    let parsed = match expires_at.parse::<DateTime<FixedOffset>>() {
        Ok(dt) => dt,
        Err(_) => return "-".to_string(),
    };

    let now = Local::now();
    let duration = parsed.signed_duration_since(now);
    let total_secs = duration.num_seconds();

    if total_secs <= 0 {
        return "Expired".to_string();
    }

    let minutes = total_secs / 60;
    let secs = total_secs % 60;

    if minutes > 0 {
        format!("{minutes}m {secs}s")
    } else {
        format!("{secs}s")
    }
}
format_modified function · rust · L44-L68 (25 LOC)
src/format.rs
pub fn format_modified(modified_at: &str) -> String {
    let parsed = match modified_at.parse::<DateTime<FixedOffset>>() {
        Ok(dt) => dt,
        Err(_) => return "-".to_string(),
    };

    let now = Local::now();
    let duration = now.signed_duration_since(parsed);
    let days = duration.num_days();

    if days < 0 {
        "in the future".to_string()
    } else if days == 0 {
        "today".to_string()
    } else if days == 1 {
        "yesterday".to_string()
    } else if days < 30 {
        format!("{days}d ago")
    } else if days < 365 {
        format!("{}mo ago", days / 30)
    } else {
        format!("{}y ago", days / 365)
    }
}
test_format_bytes_zero function · rust · L75-L77 (3 LOC)
src/format.rs
    fn test_format_bytes_zero() {
        assert_eq!(format_bytes(0), "0 B");
    }
test_format_bytes_small function · rust · L80-L82 (3 LOC)
src/format.rs
    fn test_format_bytes_small() {
        assert_eq!(format_bytes(512), "512 B");
    }
test_format_bytes_one_kb function · rust · L85-L87 (3 LOC)
src/format.rs
    fn test_format_bytes_one_kb() {
        assert_eq!(format_bytes(1024), "1.0 KB");
    }
test_format_bytes_kilobytes function · rust · L90-L92 (3 LOC)
src/format.rs
    fn test_format_bytes_kilobytes() {
        assert_eq!(format_bytes(1500), "1.5 KB");
    }
test_format_bytes_megabytes function · rust · L95-L97 (3 LOC)
src/format.rs
    fn test_format_bytes_megabytes() {
        assert_eq!(format_bytes(1_500_000), "1.4 MB");
    }
test_format_bytes_one_gb function · rust · L100-L102 (3 LOC)
src/format.rs
    fn test_format_bytes_one_gb() {
        assert_eq!(format_bytes(1_073_741_824), "1.0 GB");
    }
Source: Repobility analyzer · https://repobility.com
test_format_bytes_gigabytes function · rust · L105-L107 (3 LOC)
src/format.rs
    fn test_format_bytes_gigabytes() {
        assert_eq!(format_bytes(5_000_000_000), "4.7 GB");
    }
test_format_bytes_large function · rust · L110-L112 (3 LOC)
src/format.rs
    fn test_format_bytes_large() {
        assert_eq!(format_bytes(5_137_025_024), "4.8 GB");
    }
test_format_bytes_negative_small function · rust · L115-L117 (3 LOC)
src/format.rs
    fn test_format_bytes_negative_small() {
        assert_eq!(format_bytes(-1), "-1 B");
    }
test_format_bytes_negative_kb function · rust · L120-L122 (3 LOC)
src/format.rs
    fn test_format_bytes_negative_kb() {
        assert_eq!(format_bytes(-2000), "-2.0 KB");
    }
test_format_bytes_negative_gb function · rust · L125-L127 (3 LOC)
src/format.rs
    fn test_format_bytes_negative_gb() {
        assert_eq!(format_bytes(-5_000_000_000), "-4.7 GB");
    }
test_format_countdown_invalid function · rust · L130-L132 (3 LOC)
src/format.rs
    fn test_format_countdown_invalid() {
        assert_eq!(format_countdown("not-a-date"), "-");
    }
test_format_countdown_empty function · rust · L135-L137 (3 LOC)
src/format.rs
    fn test_format_countdown_empty() {
        assert_eq!(format_countdown(""), "-");
    }
test_format_countdown_past function · rust · L140-L142 (3 LOC)
src/format.rs
    fn test_format_countdown_past() {
        assert_eq!(format_countdown("2020-01-01T00:00:00+00:00"), "Expired");
    }
If a scraper extracted this row, it came from Repobility (https://repobility.com)
test_format_countdown_future function · rust · L145-L153 (9 LOC)
src/format.rs
    fn test_format_countdown_future() {
        use chrono::{Duration, Utc};
        let future = Utc::now() + Duration::minutes(5) + Duration::seconds(30);
        let s = future.to_rfc3339();
        let result = format_countdown(&s);
        // Should be approximately "5m 30s" or "5m 29s"
        assert!(result.contains("m "), "expected minutes in '{result}'");
        assert!(result.contains("s"), "expected seconds in '{result}'");
    }
test_format_countdown_seconds_only function · rust · L156-L163 (8 LOC)
src/format.rs
    fn test_format_countdown_seconds_only() {
        use chrono::{Duration, Utc};
        let future = Utc::now() + Duration::seconds(45);
        let s = future.to_rfc3339();
        let result = format_countdown(&s);
        assert!(!result.contains("m"), "expected no minutes in '{result}'");
        assert!(result.ends_with("s"), "expected seconds suffix in '{result}'");
    }
test_format_modified_invalid function · rust · L166-L168 (3 LOC)
src/format.rs
    fn test_format_modified_invalid() {
        assert_eq!(format_modified("garbage"), "-");
    }
test_format_modified_empty function · rust · L171-L173 (3 LOC)
src/format.rs
    fn test_format_modified_empty() {
        assert_eq!(format_modified(""), "-");
    }
test_format_modified_future function · rust · L176-L181 (6 LOC)
src/format.rs
    fn test_format_modified_future() {
        use chrono::Duration;
        let future = Local::now() + Duration::days(5);
        let s = future.to_rfc3339();
        assert_eq!(format_modified(&s), "in the future");
    }
test_format_modified_today function · rust · L184-L188 (5 LOC)
src/format.rs
    fn test_format_modified_today() {
        let now = Local::now();
        let s = now.to_rfc3339();
        assert_eq!(format_modified(&s), "today");
    }
test_format_modified_yesterday function · rust · L191-L201 (11 LOC)
src/format.rs
    fn test_format_modified_yesterday() {
        use chrono::Duration;
        let yesterday = Local::now() - Duration::days(1);
        let s = yesterday.to_rfc3339();
        let result = format_modified(&s);
        // Could be "yesterday" or "today" depending on exact timing
        assert!(
            result == "yesterday" || result == "today",
            "expected yesterday or today, got '{result}'"
        );
    }
test_format_modified_days_ago function · rust · L204-L210 (7 LOC)
src/format.rs
    fn test_format_modified_days_ago() {
        use chrono::Duration;
        let past = Local::now() - Duration::days(15);
        let s = past.to_rfc3339();
        let result = format_modified(&s);
        assert!(result.contains("d ago"), "expected days ago in '{result}'");
    }
Generated by Repobility's multi-pass static-analysis pipeline (https://repobility.com)
test_format_modified_months_ago function · rust · L213-L222 (10 LOC)
src/format.rs
    fn test_format_modified_months_ago() {
        use chrono::Duration;
        let past = Local::now() - Duration::days(90);
        let s = past.to_rfc3339();
        let result = format_modified(&s);
        assert!(
            result.contains("mo ago"),
            "expected months ago in '{result}'"
        );
    }
test_format_modified_years_ago function · rust · L225-L234 (10 LOC)
src/format.rs
    fn test_format_modified_years_ago() {
        use chrono::Duration;
        let past = Local::now() - Duration::days(400);
        let s = past.to_rfc3339();
        let result = format_modified(&s);
        assert!(
            result.contains("y ago"),
            "expected years ago in '{result}'"
        );
    }
main function · rust · L20-L27 (8 LOC)
src/main.rs
async fn main() -> color_eyre::Result<()> {
    color_eyre::install()?;
    let args = Args::parse();
    let terminal = ratatui::init();
    let result = run(terminal, &args).await;
    ratatui::restore();
    result
}
‹ prevpage 2 / 3next ›