Skip to content
Merged
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
1,574 changes: 1,181 additions & 393 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ keywords = ["git", "graph"]
license = "MIT"
readme = "README.md"
edition = "2021"
rust-version = "1.83.0"

[profile.release]
opt-level = 3
Expand All @@ -22,18 +23,22 @@ default = ["crossterm"]

[dependencies]
git2 = { version = "0.15", default-features = false, optional = false }
crossterm = { version = "0.25", optional = true }
tui = { version = "0.19", default-features = false, optional = false, features=["crossterm"] }
unicode-width = "0.1"
crossterm = { version = "0.29", optional = true }
tui = { version = "0.19", default-features = false, optional = false, features = [
"crossterm",
] }
unicode-width = "0.2"
muncher = "0.7"
itertools = "0.10"
clap = {version = "4.0", optional = false}
itertools = "0.14"
clap = { version = "4.5", optional = false }
platform-dirs = "0.3"
yansi = "0.5"
toml = "0.5"
yansi = "1.0"
toml = "0.9"
lazy_static = "1.4"
syntect = "5.0"
textwrap = {version = "0.16", default-features = false, optional = false, features = ["unicode-width"]}
git-graph = "0.5.3"
textwrap = { version = "0.16", default-features = false, optional = false, features = [
"unicode-width",
] }
git-graph = "0.6"
log4rs = "1.2.0"
log = "0.4.18"
12 changes: 6 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ impl FromStr for DiffType {
}
}

impl ToString for DiffType {
fn to_string(&self) -> String {
match self {
impl std::fmt::Display for DiffType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
DiffType::Added => "+",
DiffType::Deleted => "-",
DiffType::Modified => "m",
DiffType::Renamed => "r",
}
.to_string()
};
write!(f, "{}", s)
}
}

Expand Down Expand Up @@ -727,7 +727,7 @@ impl App {
.map_err(|err| err.message().to_string())?;

let head_idx = graph.indices.get(&graph.head.oid);
let head = if head_idx.map_or(false, |h| h == &idx) {
let head = if head_idx == Some(&idx) {
Some(&graph.head)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions src/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<'a> FileDialog<'a> {
let is_repo = Repository::open(path.path()).is_ok();
path.path()
.components()
.last()
.next_back()
.and_then(|c| c.as_os_str().to_str().map(|s| (s.to_string(), is_repo)))
} else {
None
Expand All @@ -135,7 +135,7 @@ impl<'a> FileDialog<'a> {
} else if let Some(prev) = prev_location {
if let Some(prev_index) = prev
.components()
.last()
.next_back()
.and_then(|comp| comp.as_os_str().to_str())
.and_then(|dir| self.dirs.iter().position(|d| d.0 == dir))
{
Expand Down
39 changes: 30 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ fn main() {
});
}

fn setup_logger(log_level: &String) {
let level = match log_level.as_str() {
fn setup_logger(log_level: &str) {
let level = match log_level {
"error" => log::LevelFilter::Error,
"warn" => log::LevelFilter::Warn,
"info" => log::LevelFilter::Info,
Expand Down Expand Up @@ -172,6 +172,14 @@ fn from_args() -> Result<(), String> {
.required(false)
.num_args(0),
)
.arg(
Arg::new("reverse")
.long("reverse")
.short('r')
.help("Show commits in reverse order")
.required(false)
.num_args(0),
)
.arg(
Arg::new("sparse")
.long("sparse")
Expand Down Expand Up @@ -346,11 +354,11 @@ fn from_args() -> Result<(), String> {
};

let include_remote = !matches.get_flag("local");
let reverse_commit_order = matches.get_flag("reverse");

let compact = !matches.get_flag("sparse");
match matches.get_one::<String>("log-level") {
Some(log_level) => setup_logger(log_level),
None => {}
if let Some(log_level) = matches.get_one::<String>("log-level") {
setup_logger(log_level)
}

let style = matches
Expand All @@ -369,10 +377,15 @@ fn from_args() -> Result<(), String> {
false
} else if let Some(mode) = matches.get_one::<String>("color") {
match mode.as_str() {
"auto" => !cfg!(windows) || yansi::Paint::enable_windows_ascii(),
"auto" => {
!cfg!(windows) || {
yansi::enable();
yansi::is_enabled()
}
}
"always" => {
if cfg!(windows) {
yansi::Paint::enable_windows_ascii();
yansi::enable();
}
true
}
Expand All @@ -385,12 +398,16 @@ fn from_args() -> Result<(), String> {
}
}
} else {
!cfg!(windows) || yansi::Paint::enable_windows_ascii()
!cfg!(windows) || {
yansi::enable();
yansi::is_enabled()
}
};

let app_settings = AppSettings::default().tab_width(tab_width.unwrap_or(4));

let settings = Settings {
reverse_commit_order,
debug: false,
colored,
compact,
Expand Down Expand Up @@ -961,7 +978,11 @@ fn create_app(
let name = &repository
.path()
.parent()
.and_then(|p| p.components().last().and_then(|c| c.as_os_str().to_str()))
.and_then(|p| {
p.components()
.next_back()
.and_then(|c| c.as_os_str().to_str())
})
.unwrap_or("unknown")
.to_string();

Expand Down
4 changes: 2 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ fn draw_files<B: Backend>(f: &mut Frame<B>, target: Rect, app: &mut App) {
let style = Style::default().fg(item.diff_type.to_color());
FileListItem::new(
Span::styled(&item.file, style),
Span::styled(format!("{} ", item.diff_type.to_string()), style),
Span::styled(format!("{} ", item.diff_type), style),
)
} else {
FileListItem::new(
Span::raw(&item.file),
Span::raw(format!("{} ", item.diff_type.to_string())),
Span::raw(format!("{} ", item.diff_type)),
)
}
})
Expand Down
5 changes: 3 additions & 2 deletions src/util/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ pub fn format(commit: &Commit, branches: String, hash_color: Option<u8>) -> Vec<
let mut out_vec = vec![];
let mut out = String::new();

let id = commit.id();
if let Some(color) = hash_color {
write!(out, "{}", Paint::fixed(color, &commit.id()))
write!(out, "{}", id.to_string().fixed(color))
} else {
write!(out, "{}", &commit.id())
write!(out, "{}", id)
}
.unwrap();

Expand Down
5 changes: 1 addition & 4 deletions src/util/syntax_highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ fn brighter(color: SynColor, factor: f32) -> SynColor {
}

pub fn highlight(lines: &str, extension: &str) -> Option<Vec<Vec<(Style, String)>>> {
let syntax = match SYNTAX.syntax.find_syntax_by_extension(extension) {
None => return None,
Some(syntax) => syntax,
};
let syntax = SYNTAX.syntax.find_syntax_by_extension(extension)?;

let mut h = HighlightLines::new(syntax, &THEME);

Expand Down
6 changes: 3 additions & 3 deletions src/widgets/branches_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ListItem for BranchItem {
}
}

impl<'a> ListItem for BranchListItem<'a> {
impl ListItem for BranchListItem<'_> {
fn is_selectable(&self) -> bool {
self.item_type != &BranchItemType::Heading
}
Expand Down Expand Up @@ -131,7 +131,7 @@ impl<'a> BranchList<'a> {
}
}

impl<'a> StatefulWidget for BranchList<'a> {
impl StatefulWidget for BranchList<'_> {
type State = ListState;

fn render(mut self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
Expand Down Expand Up @@ -271,7 +271,7 @@ impl<'a> StatefulWidget for BranchList<'a> {
}
}

impl<'a> Widget for BranchList<'a> {
impl Widget for BranchList<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let mut state = ListState::default();
StatefulWidget::render(self, area, buf, &mut state);
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/commit_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a> CommitView<'a> {
}
}

impl<'a> StatefulWidget for CommitView<'a> {
impl StatefulWidget for CommitView<'_> {
type State = CommitViewState;

fn render(mut self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<'a> StatefulWidget for CommitView<'a> {
}
}

impl<'a> Widget for CommitView<'a> {
impl Widget for CommitView<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let mut state = CommitViewState::default();
StatefulWidget::render(self, area, buf, &mut state);
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/files_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a> FileList<'a> {
}
}

impl<'a> StatefulWidget for FileList<'a> {
impl StatefulWidget for FileList<'_> {
type State = ListState;

fn render(mut self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<'a> StatefulWidget for FileList<'a> {
}
}

impl<'a> Widget for FileList<'a> {
impl Widget for FileList<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let mut state = ListState::default();
StatefulWidget::render(self, area, buf, &mut state);
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/graph_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a> GraphView<'a> {
}
}

impl<'a> StatefulWidget for GraphView<'a> {
impl StatefulWidget for GraphView<'_> {
type State = GraphViewState;

fn render(mut self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'a> StatefulWidget for GraphView<'a> {
}
}

impl<'a> Widget for GraphView<'a> {
impl Widget for GraphView<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let mut state = GraphViewState::default();
StatefulWidget::render(self, area, buf, &mut state);
Expand Down
Loading