Skip to content

Commit c99170a

Browse files
committed
finaally done
1 parent b031759 commit c99170a

File tree

20 files changed

+274
-101
lines changed

20 files changed

+274
-101
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ Parser (main) vs Regex approach benchmarks:
77
| --- | --- | --- | --- |
88
|regex| 313 second(s) | 22 second(s) | 8 second(s) |
99
|parser| 22 second(s) | 21 second(s)| 1 second(s) |
10+
11+
* These benchmarks were done in debug mode on a Ryzen 7 5700u with 16Gb of ram.
12+
13+
## Structure of this project
14+
15+
* [git-function-history-lib](https://github.com/mendelsshop/git_function_history/tree/main/git-function-history-lib) - the library itself
16+
* [function_history_backend_thread](https://github.com/mendelsshop/git_function_history/tree/main/function_history_backend_thread) - a threading middleware for the library (used by the GUI and TUI)
17+
* [cargo-function-history](https://github.com/mendelsshop/git_function_history/tree/main/cargo-function-history) - a cargo subcommand that uses the library (TUI)
18+
* [git-function-history-gui](https://github.com/mendelsshop/git_function_history/tree/main/git-function-history-gui) - the GUI frontend

TODO.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
- [x] add new documentation for the new filters and fix some old documentation that talks about filter commitfunctions and files etc
1313
- TUI
1414
- [x] use a proper input box for the edit bar, so that delete and scrolling the input works
15-
- [ ] finish documentation
15+
- [x] finish documentation
1616

1717
- General
1818
- [x] add the new filters to the GUI and TUI
1919
- [/] clean up the code
20-
- [/] add more logging in the code (and remove the `println!`s)
21-
- [ ] bump versions when all else is done and publish to crates.io
20+
- [x] add more logging in the code (and remove the `println!`s)
21+
- [x] bump versions when all else is done and publish to crates.io
22+
23+
- version 7.0
24+
- [ ] add more and better ways to filter dates
25+
- [ ] add filters for git specific stuff like author, committer, etc

cargo-function-history/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description = "cargo frontend for git-function-history"
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
git_function_history = { path = "../git-function-history-lib", version = "0.5.4" }
14+
git_function_history = { path = "../git-function-history-lib", version = "0.6.0" }
1515
lazy_static = "1.3.0"
1616
tui = { version = "0.19", features = ["crossterm"], default-features = false }
1717
crossterm = "0.25.0"
@@ -20,5 +20,5 @@ eyre = "0.6"
2020
dirs = "4.0.0"
2121
simple_file_logger = "0.2.0"
2222
log = "0.4"
23-
function_history_backend_thread = { path = "../function_history_backend_thread", version = "0.1.0"}
23+
function_history_backend_thread = { path = "../function_history_backend_thread", version = "0.2.0"}
2424
tui-input = "0.5.1"

cargo-function-history/README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# cargo function history
44

5+
* needs at least 15*15 terminal size
6+
57
A cargo frontend for the [git function history library](https://crates.io/crates/git-function-history).
68

79
## Installation
@@ -24,9 +26,9 @@ or cargo-function-history `<function-name<:filename>> <options>`
2426

2527
- `--filter-date-range=<date1>:<date2>`: filter to the given date range
2628

27-
- `file-absolute`: search the exact file with the filename specified after the function name
29+
- `--file-absolute`: search the exact file with the filename specified after the function name
2830

29-
- `file-relative`: search any file ending with the filename specified after the function name
31+
- `--file-relative`: search any file ending with the filename specified after the function name
3032

3133
### using the tui
3234

@@ -58,6 +60,8 @@ To exit editing mode press `esc`.
5860

5961
If your command is to long to fit on the screen, you can can use the left and right arrow keys to scroll the command pane.
6062

63+
You can also use the up and down arrow keys to scroll through your command history.
64+
6165
Each command starts with one of three command types:
6266

6367
- `search`: search for a function
@@ -134,8 +138,38 @@ Then press enter to execute the command, and after executing the command you wil
134138

135139
#### viewing pane
136140

141+
To navigate the viewing pane you need to be in viewing mode. To enter viewing mode from editing mode press `esc`.
142+
143+
<img src="https://raw.githubusercontent.com/mendelsshop/git_function_history/main/cargo-function-history/resources/screenshots/viewing-pane.png" width="400">
144+
145+
To scroll the file in the viewing pane you can use the the `up` or `k` and `down` or `j` keys.
146+
147+
To move to the next or previous commit you can use the `right` or `l` and `left` or `h` keys.
148+
149+
To move through files in a commit you can use the `shift` + `right` or `l` and `shift` + `left` or `h` keys.
150+
151+
At the top it will show the commit hash, date, and time of the commit.
152+
With the file name under that.
153+
154+
The file will be shown with the function you searched for with the line numbers.
155+
137156
#### status pane
138157

158+
The status pane is used to display the status of the program.
159+
160+
There are 4 different status types:
161+
162+
- `error`: This status type is used to display errors that occur during the program execution
163+
164+
<img src="https://raw.githubusercontent.com/mendelsshop/git_function_history/main/cargo-function-history/resources/screenshots/status-pane-err.png" width="400">
165+
166+
- `warning`: This status type is used to display warnings that occur during the program execution
167+
- `ok`: This status type is used to show when a command has been executed successfully
168+
169+
<img src="https://raw.githubusercontent.com/mendelsshop/git_function_history/main/cargo-function-history/resources/screenshots/status-pane-ok.png" width="400">
170+
171+
- `loading`: This status type is used to show when the program is loading
172+
139173
## Note
140174

141175
When specifying dates please use the RFC 2822 format, e.g. `Mon, 15 Feb 2021 15:04:05 +0000`, please put underscores instead of spaces like `Mon,_15_Feb_2021_15:04:05_+0000`.
1.42 KB
Loading
1.56 KB
Loading
37.3 KB
Loading

cargo-function-history/src/app/actions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ impl Action {
3838
match self {
3939
Action::Quit => &[Key::Ctrl('c'), Key::Char('q')],
4040
Action::TextEdit => &[Key::Char(':'), Key::Shift(':')],
41-
Action::ScrollUp => &[Key::Up],
42-
Action::ScrollDown => &[Key::Down],
43-
Action::BackCommit => &[Key::Left],
44-
Action::ForwardCommit => &[Key::Right],
45-
Action::BackFile => &[Key::Shiftleft],
46-
Action::ForwardFile => &[Key::Shiftright],
41+
Action::ScrollUp => &[Key::Up, Key::Char('k')],
42+
Action::ScrollDown => &[Key::Down, Key::Char('j')],
43+
Action::BackCommit => &[Key::Left, Key::Char('h')],
44+
Action::ForwardCommit => &[Key::Right, Key::Char('l')],
45+
Action::BackFile => &[Key::Shiftleft, Key::Char('H'), Key::Shift('h')],
46+
Action::ForwardFile => &[Key::Shiftright, Key::Char('L'), Key::Shift('l')],
4747
}
4848
}
4949
}

cargo-function-history/src/app/mod.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use function_history_backend_thread::types::{
77
};
88
use git_function_history::{BlockType, FileType, Filter};
99
use std::{sync::mpsc, time::Duration};
10+
use tui_input::InputRequest;
1011
pub mod actions;
1112
pub mod state;
1213
pub mod ui;
@@ -30,6 +31,8 @@ pub struct App {
3031
mpsc::Receiver<(CommandResult, Status)>,
3132
),
3233
status: Status,
34+
pub history: Vec<String>,
35+
pub history_index: usize,
3336
}
3437

3538
impl App {
@@ -39,6 +42,7 @@ impl App {
3942
mpsc::Sender<FullCommand>,
4043
mpsc::Receiver<(CommandResult, Status)>,
4144
),
45+
status: Status,
4246
) -> Self {
4347
let actions = vec![
4448
Action::Quit,
@@ -60,7 +64,9 @@ impl App {
6064
scroll_pos: (0, 0),
6165
body_height: 0,
6266
channels,
63-
status: Status::Ok(None),
67+
status,
68+
history: vec![],
69+
history_index: 0,
6470
}
6571
}
6672

@@ -94,7 +100,6 @@ impl App {
94100
self.scroll_pos.0 += 1;
95101
AppReturn::Continue
96102
}
97-
// TODO reset other things
98103
Action::BackCommit => {
99104
if let CommandResult::History(t) = &mut self.cmd_output {
100105
t.move_back();
@@ -466,7 +471,13 @@ impl App {
466471
match self.channels.1.recv_timeout(Duration::from_millis(100)) {
467472
Ok(timeout) => match timeout {
468473
(_, Status::Error(e)) => {
469-
log::info!("error recieved last command didn't work; {}", e);
474+
let e = e.split_once("why").unwrap_or((&e, ""));
475+
let e = format!(
476+
" error recieved last command didn't work; {}{}",
477+
e.0,
478+
e.1.split_once("why").unwrap_or(("", "")).0,
479+
);
480+
log::warn!("{}", e);
470481
self.status = Status::Error(e);
471482
}
472483
(t, Status::Ok(msg)) => {
@@ -484,4 +495,38 @@ impl App {
484495
},
485496
}
486497
}
498+
pub fn reset_and_save(&mut self) {
499+
let input = self.input_buffer.to_string();
500+
if !input.is_empty() {
501+
self.history.push(input);
502+
}
503+
self.input_buffer.reset();
504+
}
505+
506+
pub fn scroll_up(&mut self) {
507+
self.history_index = self.history_index.saturating_sub(1);
508+
let strs = match self.history.get(self.history_index) {
509+
Some(string) => string.as_str(),
510+
None => "",
511+
};
512+
for character in strs.chars() {
513+
let req = InputRequest::InsertChar(character);
514+
self.input_buffer.handle(req);
515+
}
516+
}
517+
518+
pub fn scroll_down(&mut self) {
519+
self.history_index = match self.history_index.saturating_add(1) {
520+
i if i >= self.history.len() - 1 => self.history.len() - 1,
521+
i => i,
522+
};
523+
let strs = match self.history.get(self.history_index) {
524+
Some(string) => string.as_str(),
525+
None => "",
526+
};
527+
for character in strs.chars() {
528+
let req = InputRequest::InsertChar(character);
529+
self.input_buffer.handle(req);
530+
}
531+
}
487532
}

cargo-function-history/src/app/ui.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ where
1919
B: Backend,
2020
{
2121
let size = rect.size();
22+
// check if we have enough space to draw
23+
if size.width < 10 || size.height < 10 {
24+
panic!("Not enough space to draw");
25+
}
2226
let main_window = draw_main();
2327
let mut whole_chunks = Layout::default()
2428
.direction(Direction::Vertical)
@@ -94,13 +98,17 @@ fn draw_body<B: Backend>(app: &mut App, mut pos: Rect, frame: &mut Frame<B>) {
9498
}
9599
_ => None,
96100
};
97-
let tick_text: Vec<Spans> = app
98-
.cmd_output
99-
.to_string()
100-
.split('\n')
101-
.map(|s| Spans::from(format!("{}\n", s)))
102-
.collect();
103-
101+
let tick_text: Vec<Spans> = match &app.cmd_output {
102+
CommandResult::None => match app.status {
103+
Status::Loading => vec![Spans::from("Loading...")],
104+
_ => vec![Spans::from("No output")],
105+
},
106+
a => a
107+
.to_string()
108+
.split('\n')
109+
.map(|s| Spans::from(format!("{}\n", s)))
110+
.collect(),
111+
};
104112
let body = Paragraph::new(tick_text)
105113
.style(Style::default().fg(Color::LightCyan))
106114
.scroll(app.scroll_pos)

0 commit comments

Comments
 (0)