fix: feature gate required items and fix build without blog

This commit is contained in:
Erica Marigold 2025-08-25 15:29:01 +01:00
parent f5fe0f52e6
commit d74f27ca83
Signed by: DevComp
SSH key fingerprint: SHA256:jD3oMT4WL3WHPJQbrjC3l5feNCnkv7ndW8nYaHX5wFw
6 changed files with 35 additions and 13 deletions

View file

@ -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"] }

View file

@ -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

View file

@ -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()?,

View file

@ -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)

View file

@ -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")))?,

View file

@ -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<FontSize>,
}
@ -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<Capability> {
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,