From d74f27ca83b56f66b84373b2492fed8c19c96721 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Mon, 25 Aug 2025 15:29:01 +0100 Subject: [PATCH] fix: feature gate required items and fix build without `blog` --- Cargo.toml | 11 ++++++++--- build.rs | 1 + src/app.rs | 9 ++++----- src/components/content.rs | 1 + src/ssh.rs | 12 +++++++++--- src/tui/terminal.rs | 14 ++++++++++++-- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca0f74a..7bf0c6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ build = "build.rs" # TODO: CLI feature default = ["blog"] blog = [ + # Main deps "dep:atrium-api", "dep:atrium-xrpc", "dep:atrium-xrpc-client", @@ -19,7 +20,11 @@ blog = [ "dep:tui-markdown", "dep:chrono", "dep:ratatui-image", - "dep:image" + "dep:image", + + # Build deps + "dep:atrium-codegen", + "dep:patch-crate" ] [package.metadata.patch] @@ -83,7 +88,7 @@ tui-markdown = { version = "0.3.5", optional = true } [build-dependencies] anyhow = "1.0.90" -atrium-codegen = { git = "https://github.com/atrium-rs/atrium.git", rev = "ccc0213" } -patch-crate = "0.1.13" +atrium-codegen = { git = "https://github.com/atrium-rs/atrium.git", rev = "ccc0213", optional = true } +patch-crate = { version = "0.1.13", optional = true } ssh-key = { version = "0.6.7", features = ["getrandom", "crypto"] } vergen-gix = { version = "1.0.2", features = ["build", "cargo"] } diff --git a/build.rs b/build.rs index 77d0437..b98a615 100644 --- a/build.rs +++ b/build.rs @@ -21,6 +21,7 @@ fn main() -> Result<()> { println!("cargo:rerun-if-changed=Cargo.toml"); println!("cargo:rerun-if-changed=patches/"); + #[cfg(feature = "blog")] patch_crate::run().expect("Failed while patching"); // Generate openSSH host keys diff --git a/src/app.rs b/src/app.rs index 6dbc818..cec5fcc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -252,11 +252,10 @@ impl App { Action::Tick => { self.last_tick_key_events.drain(..); } - Action::Quit => { - if !self.blog_posts.try_lock()?.is_in_post() { - self.should_quit = true; - } - } + #[cfg(feature = "blog")] + Action::Quit => self.should_quit = !self.blog_posts.try_lock()?.is_in_post(), + #[cfg(not(feature = "blog"))] + Action::Quit => self.should_quit = true, Action::Suspend => self.should_suspend = true, Action::Resume => self.should_suspend = false, Action::ClearScreen => tui.terminal.try_lock()?.clear()?, diff --git a/src/components/content.rs b/src/components/content.rs index 3ae5e56..5f2847c 100644 --- a/src/components/content.rs +++ b/src/components/content.rs @@ -14,6 +14,7 @@ use crate::action::Action; use crate::components::Post; use crate::config::Config; +#[allow(dead_code)] pub(super) fn truncate(s: &str, max: usize) -> String { s.char_indices() .find(|(idx, ch)| idx + ch.len_utf8() > max) diff --git a/src/ssh.rs b/src/ssh.rs index 105c461..a1d7da3 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -13,7 +13,7 @@ use tracing::instrument; use crate::app::App; use crate::tui::backend::SshBackend; -use crate::tui::terminal::{TerminalInfo, TerminalKind, UnsupportedReason}; +use crate::tui::terminal::{TerminalInfo, TerminalKind}; use crate::tui::{Terminal, Tui}; use crate::OPTIONS; @@ -215,6 +215,7 @@ impl Handler for SshSession { tracing::info!("PTY requested by terminal: {term}"); tracing::debug!("dims: {col_width} * {row_height}, pixel: {pix_width} * {pix_height}"); + #[cfg(feature = "blog")] if pix_width != 0 && pix_height != 0 { self.terminal_info.write().await.set_font_size(( (pix_width / col_width).try_into().or(Err(eyre!("Terminal too wide")))?, @@ -224,7 +225,7 @@ impl Handler for SshSession { self.terminal_info .write() .await - .set_kind(TerminalKind::Unsupported(UnsupportedReason::Unsized)); + .set_kind(TerminalKind::Unsupported(crate::tui::terminal::UnsupportedReason::Unsized)); } if !term.contains("xterm") { @@ -260,15 +261,20 @@ impl Handler for SshSession { .map_err(|_| eyre!("Failed to send event keystroke data")) } + #[instrument(skip_all, fields(channel_id = %_channel_id))] async fn window_change_request( &mut self, - _: ChannelId, + _channel_id: ChannelId, col_width: u32, row_height: u32, pix_width: u32, pix_height: u32, _: &mut Session, ) -> Result<(), Self::Error> { + tracing::info!("Terminal window resized by client, notifying components"); + tracing::debug!("dims: {col_width} * {row_height}, pixel: {pix_width} * {pix_height}"); + + #[cfg(feature = "blog")] self.terminal_info.write().await.set_font_size(( (pix_width / col_width).try_into().or(Err(eyre!("Terminal too wide")))?, (pix_height / row_height).try_into().or(Err(eyre!("Terminal too tall")))?, diff --git a/src/tui/terminal.rs b/src/tui/terminal.rs index 080076d..aad1760 100644 --- a/src/tui/terminal.rs +++ b/src/tui/terminal.rs @@ -1,16 +1,22 @@ use std::default::Default; use default_variant::default; -use ratatui_image::picker::{Capability, ProtocolType}; -use ratatui_image::FontSize; use serde::{Deserialize, Serialize}; use strum::Display; +#[cfg(feature = "blog")] +use ratatui_image::{ + picker::{Capability, ProtocolType}, + FontSize, +}; + +#[cfg(feature = "blog")] pub const DEFAULT_FONT_SIZE: FontSize = (12, 12); #[derive(Debug, Default, Clone)] pub struct TerminalInfo { kind: TerminalKind, + #[cfg(feature = "blog")] font_size: Option, } @@ -21,6 +27,7 @@ impl TerminalInfo { } /// Get the font size. + #[cfg(feature = "blog")] pub fn font_size(&self) -> FontSize { self.font_size.unwrap_or(DEFAULT_FONT_SIZE) } @@ -33,6 +40,7 @@ impl TerminalInfo { } /// Sets the font size. + #[cfg(feature = "blog")] pub fn set_font_size(&mut self, font_size: FontSize) { self.font_size = Some(font_size); } @@ -111,6 +119,7 @@ impl TerminalKind { Self::ALL_SUPPORTED.map(|term| term.to_string()).join(", ") } + #[cfg(feature = "blog")] pub fn capabilities(&self) -> Vec { match *self { Self::Hyper | Self::Vscode => vec![Capability::RectangularOps], @@ -130,6 +139,7 @@ impl TerminalKind { } } + #[cfg(feature = "blog")] pub fn as_protocol(&self) -> ProtocolType { if matches!( self,