Skip to content

Commit cedb665

Browse files
committed
Show current brach name in the main view
1 parent 56134ca commit cedb665

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

controller/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ var main = {
9999
reload: function () {
100100
git.status();
101101

102+
view.branchbox.setText(git.getCurrentBranchName());
103+
102104
main.setItems();
103105

104106
main.moveToUnstaged(0);

model/git.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var gitExec = 'git';
66

77
function Git (path) {
88
this.path = path;
9+
10+
this.loadBranches();
911
}
1012

1113
Git.prototype.clear = function () {
@@ -207,4 +209,27 @@ Git.prototype.diff = function (type, index) {
207209
return stdout.toString();
208210
};
209211

212+
Git.prototype.loadBranches = function () {
213+
var self = this;
214+
215+
var gitCommand = gitExec + ' branch --list';
216+
217+
var stdout = execSync(gitCommand);
218+
219+
this.branches = stdout.toString().split('\n')
220+
.map(function (line, index) {
221+
if (line.charAt(0) === '*') {
222+
self.currentBranchIndex = index;
223+
}
224+
225+
return line.slice(2);
226+
});
227+
228+
return this.branches;
229+
};
230+
231+
Git.prototype.getCurrentBranchName = function () {
232+
return this.branches[this.currentBranchIndex];
233+
};
234+
210235
module.exports = Git;

view/main.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@ var screen = blessed.screen(styles.screen);
77

88
// bind screen to child elems
99
_.merge(styles, {
10-
title : {
10+
title : {
1111
staged : {parent: screen},
1212
unstaged: {parent: screen}
1313
},
14-
list : {
14+
list : {
1515
staged : {parent: screen},
1616
unstaged: {parent: screen}
1717
},
18-
menubar1: {
18+
branchbox: {
1919
parent: screen
2020
},
21-
menubar2: {
21+
menubar1 : {
2222
parent: screen
2323
},
24-
loading : {
24+
menubar2 : {
2525
parent: screen
2626
},
27-
popup : {
27+
loading : {
28+
parent: screen
29+
},
30+
popup : {
2831
parent: screen
2932
}
3033
});
@@ -42,6 +45,8 @@ var list = {
4245
list.staged.name = "staged";
4346
list.unstaged.name = "unstaged";
4447

48+
var branchbox = blessed.text(styles.branchbox);
49+
4550
blessed.listbar(styles.menubar1);
4651
blessed.listbar(styles.menubar2);
4752

@@ -50,9 +55,10 @@ var loading = blessed.loading(styles.loading);
5055
var popup = blessed.box(styles.popup);
5156

5257
module.exports = {
53-
screen : screen,
54-
title : title,
55-
list : list,
56-
loading: loading,
57-
popup : popup
58+
screen : screen,
59+
title : title,
60+
list : list,
61+
branchbox: branchbox,
62+
loading : loading,
63+
popup : popup
5864
};

view/style/main.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"align": "left",
4545
"tags": true,
4646
"width": "50%",
47-
"height": "100%-5",
47+
"height": "100%-6",
4848
"interactive": false,
4949
"keys": true,
5050
"style": {
@@ -64,7 +64,7 @@
6464
"align": "left",
6565
"tags": true,
6666
"width": "50%",
67-
"height": "100%-5",
67+
"height": "100%-6",
6868
"interactive": true,
6969
"keys": true,
7070
"style": {
@@ -77,6 +77,18 @@
7777
}
7878
}
7979
},
80+
"branchbox": {
81+
"align": "center",
82+
"bottom": 3,
83+
"height": 1,
84+
"align": "right",
85+
"padding": {
86+
"right": 2
87+
},
88+
"style": {
89+
"fg": "yellow"
90+
}
91+
},
8092
"menubar1": {
8193
"align": "center",
8294
"bottom": 1,

0 commit comments

Comments
 (0)