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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ jobs:
run: |
cargo install cargo-wix
cargo wix init
cargo wix --no-build --nocapture
cargo wix --no-build --nocapture --output ./target/wix/gitui.msi
ls -l ./target/wix/gitui.msi

build-linux-musl:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- crash when changing git repo while gitui is open ([#271](https://github.com/extrawurst/gitui/issues/271))
- remove workaround for color serialization [[@1wilkens](https://github.com/1wilkens)] ([#149](https://github.com/extrawurst/gitui/issues/149))
- crash on small terminal size ([#307](https://github.com/extrawurst/gitui/issues/307))
- fix vim keybindings uppercase handling [[@yanganto](https://github.com/yanganto)] ([#286](https://github.com/extrawurst/gitui/issues/286))

Expand Down
7 changes: 4 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ scopetime = { path = "./scopetime", version = "0.1" }
asyncgit = { path = "./asyncgit", version = "0.10" }
crossterm = { version = "0.18", features = [ "serde" ] }
clap = { version = "2.33", default-features = false }
tui = { version = "0.12", default-features = false, features = ['crossterm'] }
tui = { version = "0.12", default-features = false, features = ['crossterm', 'serde'] }
bytesize = { version = "1.0.1", default-features = false}
itertools = "0.9"
rayon-core = "1.9"
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ release-win: build-release
cargo install cargo-wix
cargo wix init
cargo wix --no-build --nocapture --output ./release/gitui.msi
ls -l ./release/gitui.msi

release-linux-musl: build-linux-musl-release
strip target/x86_64-unknown-linux-musl/release/gitui
Expand Down
5 changes: 2 additions & 3 deletions THEMES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Themes
# Themes

default on light terminal:
![](assets/light-theme.png)
Expand All @@ -10,5 +10,4 @@ to change the colors of the program you have to modify `theme.ron` file
* `$XDG_CONFIG_HOME/gitui/theme.ron` (linux using XDG)
* `$HOME/.config/gitui/theme.ron` (linux)

Valid colors can be found in [ColorDef](./src/ui/style.rs#ColorDef) struct. note that rgb colors might not be supported
in every terminal.
Valid colors can be found in tui-rs' [Color](https://docs.rs/tui/0.12.0/tui/style/enum.Color.html) struct. note that rgb colors might not be supported in every terminal.
3 changes: 1 addition & 2 deletions src/components/commit_details/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ impl DrawableComponent for DetailsComponent {
f,
chunks[1],
&self.theme,
self.get_number_of_lines(width as usize)
.saturating_sub(height as usize),
self.get_number_of_lines(width as usize),
self.scroll_top.get(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl DrawableComponent for DiffComponent {
r,
&self.theme,
self.lines_count(),
self.selection.get_end(),
self.scroll_top.get(),
);
}

Expand Down
188 changes: 106 additions & 82 deletions src/components/select_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use super::{
DrawableComponent,
};
use crate::{
components::ScrollType,
keys::SharedKeyConfig,
queue::{Action, InternalEvent, NeedsUpdate, Queue},
strings, ui,
strings,
ui::{self, calc_scroll_top},
};
use asyncgit::{
sync::{
Expand All @@ -14,7 +16,7 @@ use asyncgit::{
CWD,
};
use crossterm::event::Event;
use std::{cmp, convert::TryFrom};
use std::{cell::Cell, convert::TryInto};
use tui::{
backend::Backend,
layout::{Alignment, Rect},
Expand All @@ -23,6 +25,7 @@ use tui::{
Frame,
};

use crate::ui::Size;
use anyhow::Result;
use ui::style::SharedTheme;

Expand All @@ -31,6 +34,7 @@ pub struct SelectBranchComponent {
branch_names: Vec<BranchForDisplay>,
visible: bool,
selection: u16,
scroll_top: Cell<usize>,
queue: Queue,
theme: SharedTheme,
key_config: SharedKeyConfig,
Expand All @@ -43,33 +47,40 @@ impl DrawableComponent for SelectBranchComponent {
rect: Rect,
) -> Result<()> {
if self.visible {
const PERCENT_SIZE: (u16, u16) = (60, 25);
const MIN_SIZE: (u16, u16) = (50, 20);
const PERCENT_SIZE: Size = Size::new(60, 25);
const MIN_SIZE: Size = Size::new(50, 20);

let area = ui::centered_rect(
PERCENT_SIZE.0,
PERCENT_SIZE.1,
PERCENT_SIZE.width,
PERCENT_SIZE.height,
f.size(),
);
let area = ui::rect_min(MIN_SIZE.0, MIN_SIZE.1, area);
let area =
ui::rect_inside(MIN_SIZE, f.size().into(), area);
let area = area.intersection(rect);

let scroll_threshold = area.height / 3;
let scroll =
self.selection.saturating_sub(scroll_threshold);
let height_in_lines =
(area.height as usize).saturating_sub(2);

self.scroll_top.set(calc_scroll_top(
self.scroll_top.get(),
height_in_lines,
self.selection as usize,
));

f.render_widget(Clear, area);
f.render_widget(
Paragraph::new(
self.get_text(&self.theme, area.width)?,
)
Paragraph::new(self.get_text(
&self.theme,
area.width,
height_in_lines,
)?)
.block(
Block::default()
.title(strings::SELECT_BRANCH_POPUP_MSG)
.borders(Borders::ALL)
.border_type(BorderType::Thick),
)
.scroll((scroll, 0))
.alignment(Alignment::Left),
area,
);
Expand Down Expand Up @@ -133,9 +144,9 @@ impl Component for SelectBranchComponent {
if e == self.key_config.exit_popup {
self.hide()
} else if e == self.key_config.move_down {
self.move_selection(true)
return self.move_selection(ScrollType::Up);
} else if e == self.key_config.move_up {
self.move_selection(false)
return self.move_selection(ScrollType::Down);
} else if e == self.key_config.enter {
if let Err(e) = self.switch_to_selected_branch() {
log::error!("switch branch error: {}", e);
Expand Down Expand Up @@ -209,6 +220,7 @@ impl SelectBranchComponent {
branch_names: Vec::new(),
visible: false,
selection: 0,
scroll_top: Cell::new(0),
queue,
theme,
key_config,
Expand Down Expand Up @@ -246,28 +258,31 @@ impl SelectBranchComponent {
}

///
fn move_selection(&mut self, inc: bool) {
let mut new_selection = self.selection;

new_selection = if inc {
new_selection.saturating_add(1)
} else {
new_selection.saturating_sub(1)
fn move_selection(&mut self, scroll: ScrollType) -> Result<bool> {
let num_branches: u16 = self.branch_names.len().try_into()?;
let num_branches = num_branches.saturating_sub(1);

let mut new_selection = match scroll {
ScrollType::Up => self.selection.saturating_add(1),
ScrollType::Down => self.selection.saturating_sub(1),
_ => self.selection,
};
new_selection = cmp::max(new_selection, 0);

if let Ok(max) =
u16::try_from(self.branch_names.len().saturating_sub(1))
{
self.selection = cmp::min(new_selection, max);
if new_selection > num_branches {
new_selection = num_branches;
}

self.selection = new_selection;

Ok(true)
}

/// Get branches to display
fn get_text(
&self,
theme: &SharedTheme,
width_available: u16,
height: usize,
) -> Result<Text> {
const COMMIT_HASH_LENGTH: usize = 8;
const IS_HEAD_STAR_LENGTH: usize = 3; // "* "
Expand All @@ -284,7 +299,12 @@ impl SelectBranchComponent {
.saturating_sub(THREE_DOTS_LENGTH);
let mut txt = Vec::new();

for (i, displaybranch) in self.branch_names.iter().enumerate()
for (i, displaybranch) in self
.branch_names
.iter()
.skip(self.scroll_top.get())
.take(height)
.enumerate()
{
let mut commit_message =
displaybranch.top_commit_message.clone();
Expand All @@ -308,63 +328,67 @@ impl SelectBranchComponent {
let is_head_str =
if displaybranch.is_head { "*" } else { " " };

txt.push(Spans::from(if self.selection as usize == i {
vec![
Span::styled(
format!("{} ", is_head_str),
theme.commit_author(true),
),
Span::styled(
format!(
">{:w$} ",
branch_name,
w = branch_name_length
txt.push(Spans::from(
if self.selection as usize - self.scroll_top.get()
== i
{
vec![
Span::styled(
format!("{} ", is_head_str),
theme.commit_author(true),
),
Span::styled(
format!(
">{:w$} ",
branch_name,
w = branch_name_length
),
theme.commit_author(true),
),
Span::styled(
format!(
"{} ",
displaybranch
.top_commit
.get_short_string()
),
theme.commit_hash(true),
),
theme.commit_author(true),
),
Span::styled(
format!(
"{} ",
displaybranch
.top_commit
.get_short_string()
Span::styled(
commit_message.to_string(),
theme.text(true, true),
),
theme.commit_hash(true),
),
Span::styled(
commit_message.to_string(),
theme.text(true, true),
),
]
} else {
vec![
Span::styled(
format!("{} ", is_head_str),
theme.commit_author(false),
),
Span::styled(
format!(
" {:w$} ",
branch_name,
w = branch_name_length
]
} else {
vec![
Span::styled(
format!("{} ", is_head_str),
theme.commit_author(false),
),
theme.commit_author(false),
),
Span::styled(
format!(
"{} ",
displaybranch
.top_commit
.get_short_string()
Span::styled(
format!(
" {:w$} ",
branch_name,
w = branch_name_length
),
theme.commit_author(false),
),
Span::styled(
format!(
"{} ",
displaybranch
.top_commit
.get_short_string()
),
theme.commit_hash(false),
),
theme.commit_hash(false),
),
Span::styled(
commit_message.to_string(),
theme.text(true, false),
),
]
}));
Span::styled(
commit_message.to_string(),
theme.text(true, false),
),
]
},
));
}

Ok(Text::from(txt))
Expand Down
Loading