@hej / sigit / commits / 95b737c

Add #[cfg(unix)] to chat module types and functions

paydii committed Apr 26, 2026 at 12:36 UTC 95b737c6c2db88029a31f07dd44a80abf47a4e34
1 file changed +9
src/chat.rs
+9
@@ -70,6 +70,7 @@ pub(crate) fn strip_think_blocks(raw: &str) -> (String, String) {
70
71 // ── Message types ─────────────────────────────────────────────────────────────
72
73 +#[cfg(unix)]
74 #[derive(Clone, Copy, PartialEq, Eq)]
75 enum Role {
76 User,
@@ -79,6 +80,7 @@ enum Role {
80 Banner,
81 }
82
83 +#[cfg(unix)]
84 struct ChatMessage {
85 role: Role,
86 text: String,
@@ -86,6 +88,7 @@ struct ChatMessage {
88 think_block: Option<String>,
89 }
90
91 +#[cfg(unix)]
92 impl ChatMessage {
93 fn user(text: impl Into<String>) -> Self {
94 Self {
@@ -125,6 +128,7 @@ impl ChatMessage {
128 // ── Inference updates from background task ───────────────────────────────────
129
130 /// Messages sent from the spawned inference task back to the event loop.
131 +#[cfg(unix)]
132 enum InferenceUpdate {
133 /// The model is calling a tool — show its name in the chat.
134 ToolUse(String),
@@ -134,6 +138,7 @@ enum InferenceUpdate {
138 Error(String),
139 }
140
141 +#[cfg(unix)]
142 enum ModelLoadUpdate {
143 Loaded(String),
144 Error(String),
@@ -1418,6 +1423,7 @@ async fn run_inference_task(
1423 /// dedicated OS thread loads the model and sends `Ok(())` or `Err(msg)` when
1424 /// done. The event loop polls `try_recv()` on every tick — non-blocking,
1425 /// zero contention with the tokio runtime.
1426 +#[cfg(unix)]
1427 pub async fn run_with<B: ratatui::backend::Backend>(
1428 terminal: &mut ratatui::Terminal<B>,
1429 engine: Arc<ChatEngine>,
@@ -1427,6 +1433,7 @@ pub async fn run_with<B: ratatui::backend::Backend>(
1433 event_loop(terminal, engine, load_rx, load_model_name).await
1434 }
1435
1436 +#[cfg(unix)]
1437 async fn event_loop<B: ratatui::backend::Backend>(
1438 terminal: &mut ratatui::Terminal<B>,
1439 engine: Arc<ChatEngine>,
@@ -1692,6 +1699,7 @@ async fn event_loop<B: ratatui::backend::Backend>(
1699
1700 /// Recursively sum the on-disk size of all files under `path`, following
1701 /// symlinks so hf-hub's blob layout is counted correctly.
1702 +#[cfg(unix)]
1703 fn dir_size_recursive(path: &std::path::Path) -> u64 {
1704 let mut total: u64 = 0;
1705 let Ok(entries) = std::fs::read_dir(path) else {
@@ -1709,6 +1717,7 @@ fn dir_size_recursive(path: &std::path::Path) -> u64 {
1717 }
1718
1719 /// Format a byte count as a terse human-readable string.
1720 +#[cfg(unix)]
1721 fn format_size_human(bytes: u64) -> String {
1722 const GB: u64 = 1_073_741_824;
1723 const MB: u64 = 1_048_576;