-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
71 lines (60 loc) · 1.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const config = require('./config');
const git = new (require('./Git'))();
const GUI = new (require('./UI'))();
GUI.setInputEvent((element) => {
var message = element.getValue();
git.sendMessage(message);
element.setValue("");
element.focus();
GUI.redraw();
});
GUI.setListItemSelectedEvent((newBranch) => {
git.getCurrentBranch()
.then(currentBranch => {
if(currentBranch !== newBranch) {
GUI.clearMessages();
GUI.addMessage("Please wait...");
git.switchBranch(newBranch)
.then(() => {
GUI.clearMessages();
GUI.addMessage("Switched to branch " + newBranch);
});
}
})
});
GUI.addMessage("Welcome to GIC - the first git based chat");
GUI.addMessage("Every message in this chat is a commit");
GUI.addMessage("And every channel is a branch");
GUI.addMessage("");
GUI.addMessage("Cloning repo... Please wait...");
git.cloneRepo(config.gitRepo)
.then(() => {
GUI.addMessage("Finished cloning repo, you may begin!");
getBranches();
getMessages();
});
function getBranches() {
git.getBranches()
.then(branches => {
branches.forEach(branch => {
GUI.addChannelBuffer(branch);
});
GUI.addChannelFlush();
setTimeout(getBranches, config.branchesCheckInterval);
}).catch(err => {
console.error(err);
})
}
function getMessages() {
git.getCommits()
.then(commits => {
commits.forEach(commit => {
GUI.addMessageBuffer('{bold}' + commit.sender + '{/bold}: ' + commit.message);
});
GUI.addMessageFlush();
setTimeout(getMessages, config.messageCheckInterval);
}).catch((err) => {
console.error(err);
})
}