@@ -8,7 +8,7 @@ use chrono::prelude::*;
8
8
use crossbeam_channel:: Sender ;
9
9
use crossterm:: event:: Event ;
10
10
use std:: { borrow:: Cow , cmp, convert:: TryFrom , time:: Instant } ;
11
- use sync:: CommitInfo ;
11
+ use sync:: { CommitInfo , Tags } ;
12
12
use tui:: {
13
13
backend:: Backend ,
14
14
layout:: { Alignment , Rect } ,
@@ -24,29 +24,32 @@ struct LogEntry {
24
24
hash : String ,
25
25
}
26
26
27
- impl From < & CommitInfo > for LogEntry {
28
- fn from ( c : & CommitInfo ) -> Self {
27
+ impl From < CommitInfo > for LogEntry {
28
+ fn from ( c : CommitInfo ) -> Self {
29
29
let time =
30
30
DateTime :: < Local > :: from ( DateTime :: < Utc > :: from_utc (
31
31
NaiveDateTime :: from_timestamp ( c. time , 0 ) ,
32
32
Utc ,
33
33
) ) ;
34
34
Self {
35
- author : c. author . clone ( ) ,
36
- msg : c. message . clone ( ) ,
35
+ author : c. author ,
36
+ msg : c. message ,
37
37
time : time. format ( "%Y-%m-%d %H:%M:%S" ) . to_string ( ) ,
38
- hash : c. hash [ 0 .. 7 ] . to_string ( ) ,
38
+ hash : c. hash ,
39
39
}
40
40
}
41
41
}
42
42
43
43
const COLOR_SELECTION_BG : Color = Color :: Blue ;
44
44
45
+ const STYLE_TAG : Style = Style :: new ( ) . fg ( Color :: Yellow ) ;
45
46
const STYLE_HASH : Style = Style :: new ( ) . fg ( Color :: Magenta ) ;
46
47
const STYLE_TIME : Style = Style :: new ( ) . fg ( Color :: Blue ) ;
47
48
const STYLE_AUTHOR : Style = Style :: new ( ) . fg ( Color :: Green ) ;
48
49
const STYLE_MSG : Style = Style :: new ( ) . fg ( Color :: Reset ) ;
49
50
51
+ const STYLE_TAG_SELECTED : Style =
52
+ Style :: new ( ) . fg ( Color :: Yellow ) . bg ( COLOR_SELECTION_BG ) ;
50
53
const STYLE_HASH_SELECTED : Style =
51
54
Style :: new ( ) . fg ( Color :: Magenta ) . bg ( COLOR_SELECTION_BG ) ;
52
55
const STYLE_TIME_SELECTED : Style =
@@ -56,7 +59,7 @@ const STYLE_AUTHOR_SELECTED: Style =
56
59
const STYLE_MSG_SELECTED : Style =
57
60
Style :: new ( ) . fg ( Color :: Reset ) . bg ( COLOR_SELECTION_BG ) ;
58
61
59
- static ELEMENTS_PER_LINE : usize = 8 ;
62
+ static ELEMENTS_PER_LINE : usize = 10 ;
60
63
static SLICE_SIZE : usize = 1000 ;
61
64
static SLICE_OFFSET_RELOAD_THRESHOLD : usize = 100 ;
62
65
@@ -69,6 +72,7 @@ pub struct Revlog {
69
72
visible : bool ,
70
73
first_open_done : bool ,
71
74
scroll_state : ( Instant , f32 ) ,
75
+ tags : Tags ,
72
76
}
73
77
74
78
impl Revlog {
@@ -82,6 +86,7 @@ impl Revlog {
82
86
visible : false ,
83
87
first_open_done : false ,
84
88
scroll_state : ( Instant :: now ( ) , 0_f32 ) ,
89
+ tags : Tags :: new ( ) ,
85
90
}
86
91
}
87
92
@@ -94,7 +99,12 @@ impl Revlog {
94
99
95
100
let mut txt = Vec :: new ( ) ;
96
101
for ( idx, e) in self . items . iter ( ) . enumerate ( ) {
97
- Self :: add_entry ( e, idx == selection, & mut txt) ;
102
+ let tag = if let Some ( tag_name) = self . tags . get ( & e. hash ) {
103
+ tag_name. as_str ( )
104
+ } else {
105
+ ""
106
+ } ;
107
+ Self :: add_entry ( e, idx == selection, & mut txt, tag) ;
98
108
}
99
109
100
110
let title =
@@ -138,9 +148,14 @@ impl Revlog {
138
148
) ;
139
149
140
150
if let Ok ( commits) = commits {
141
- self . items . extend ( commits. iter ( ) . map ( LogEntry :: from) ) ;
151
+ self . items
152
+ . extend ( commits. into_iter ( ) . map ( LogEntry :: from) ) ;
142
153
}
143
154
}
155
+
156
+ if self . tags . is_empty ( ) {
157
+ self . tags = sync:: get_tags ( CWD ) . unwrap ( ) ;
158
+ }
144
159
}
145
160
146
161
fn move_selection ( & mut self , up : bool ) {
@@ -190,6 +205,7 @@ impl Revlog {
190
205
e : & ' a LogEntry ,
191
206
selected : bool ,
192
207
txt : & mut Vec < Text < ' a > > ,
208
+ tag : & ' a str ,
193
209
) {
194
210
let count_before = txt. len ( ) ;
195
211
@@ -204,7 +220,7 @@ impl Revlog {
204
220
} ;
205
221
206
222
txt. push ( Text :: Styled (
207
- Cow :: from ( e. hash . as_str ( ) ) ,
223
+ Cow :: from ( & e. hash [ 0 .. 7 ] ) ,
208
224
if selected {
209
225
STYLE_HASH_SELECTED
210
226
} else {
@@ -229,6 +245,19 @@ impl Revlog {
229
245
STYLE_AUTHOR
230
246
} ,
231
247
) ) ;
248
+ txt. push ( splitter. clone ( ) ) ;
249
+ txt. push ( Text :: Styled (
250
+ Cow :: from ( if tag. is_empty ( ) {
251
+ String :: from ( "" )
252
+ } else {
253
+ format ! ( " {}" , tag)
254
+ } ) ,
255
+ if selected {
256
+ STYLE_TAG_SELECTED
257
+ } else {
258
+ STYLE_TAG
259
+ } ,
260
+ ) ) ;
232
261
txt. push ( splitter) ;
233
262
txt. push ( Text :: Styled (
234
263
Cow :: from ( e. msg . as_str ( ) ) ,
0 commit comments