Skip to content
Open
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ image = { version = "0.25.8", default-features = false, features = [
"png",
] }
laurier = "0.1.1"
libc = "0.2.177"
once_cell = "1.21.3"
ratatui = { version = "0.29.0", features = ["serde"] }
rayon = "1.11.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ The terminals on which each has been confirmed to work are listed below.
### Unsupported environments

- Sixel graphics is not supported.
- Terminal multiplexers (screen, tmux, Zellij, etc.) are not supported.
- Tmux is supported when using the Terminal graphics protocol (kitty, Ghosty), Other terminal multiplexers (screen, Zellij, etc.) are not supported.

## Contributing

Expand Down
20 changes: 19 additions & 1 deletion src/check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ratatui::crossterm::terminal;
use ratatui::crossterm::terminal::{self, WindowSize};

use crate::{
graph::{CellWidthType, Graph},
Expand Down Expand Up @@ -53,3 +53,21 @@ fn decide_cell_width_type_from(
}
}
}

pub fn detect_cell_size() -> Option<(u16, u16)> {
let ws = terminal::window_size().ok()?;
match ws {
WindowSize {
rows,
columns,
width,
height,
} if width == 0 || height == 0 || rows == 0 || columns == 0 => None,
WindowSize {
rows,
columns,
width,
height,
} => Some((width / columns, height / rows)),
}
}
56 changes: 51 additions & 5 deletions src/graph/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,47 @@ pub enum CellWidthType {
Single,
}

pub struct CellSize {
pub width: u16,
pub height: u16,
}

impl Default for CellSize {
fn default() -> Self {
Self {
width: 25,
height: 50,
}
}
}

impl CellSize {
fn new() -> Self {
match crate::check::detect_cell_size() {
Some((width, height)) => Self { width, height },
None => Self::default(),
}
}
}

impl ImageParams {
pub fn new(graph_color_set: &GraphColorSet, cell_width_type: CellWidthType) -> Self {
let (width, height, line_width, circle_inner_radius, circle_outer_radius) =
match cell_width_type {
CellWidthType::Double => (50, 50, 5, 10, 13),
CellWidthType::Single => (25, 50, 3, 7, 10),
pub fn new_with_cell_size(
graph_color_set: &GraphColorSet,
cell_width_type: CellWidthType,
cell_size: CellSize,
) -> Self {
let (width, height, line_width, circle_inner_radius, circle_outer_radius) = {
let calc_image_params = |width: u16, height: u16| -> (u16, u16, u16, u16, u16) {
let inner_radius = ((width as f32) * 0.12 + 4.0).round() as u16;
let line_width = width.div_ceil(10);
(width, height, line_width, inner_radius, inner_radius + 3)
};
match cell_width_type {
CellWidthType::Double => calc_image_params(cell_size.width * 2, cell_size.height),
CellWidthType::Single => calc_image_params(cell_size.width, cell_size.height),
}
};

let edge_colors = graph_color_set
.colors
.iter()
Expand All @@ -159,6 +193,18 @@ impl ImageParams {
}
}

pub fn new(graph_color_set: &GraphColorSet, cell_width_type: CellWidthType) -> Self {
let mut cell_size = CellSize::new();

// Increase the cell width minimum of 25 while maintaining the aspect ratio. So we dont't
// end up with a too small image to draw into.
let aspect_ratio = cell_size.height as f32 / cell_size.width as f32;
cell_size.width = cell_size.width.max(25);
cell_size.height = (cell_size.width as f32 * aspect_ratio).round() as u16;

Self::new_with_cell_size(graph_color_set, cell_width_type, cell_size)
}

fn edge_color(&self, index: usize) -> image::Rgba<u8> {
self.edge_colors[index % self.edge_colors.len()]
}
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use clap::{Parser, ValueEnum};
use graph::GraphImageManager;
use serde::Deserialize;

use crate::protocol::PassthruProtocol;

/// Serie - A rich git commit graph in your terminal, like magic 📚
#[derive(Parser)]
#[command(version)]
Expand Down Expand Up @@ -53,7 +55,9 @@ impl From<Option<ImageProtocolType>> for protocol::ImageProtocol {
match protocol {
Some(ImageProtocolType::Auto) => protocol::auto_detect(),
Some(ImageProtocolType::Iterm) => protocol::ImageProtocol::Iterm2,
Some(ImageProtocolType::Kitty) => protocol::ImageProtocol::Kitty,
Some(ImageProtocolType::Kitty) => protocol::ImageProtocol::Kitty {
passthru: PassthruProtocol::detect(),
},
None => protocol::auto_detect(),
}
}
Expand Down
Loading
Loading