Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to toggle the commits graph via env variable #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ variables have been set correctly, you can print them in the terminal -- for exa

All the settings the dashboard looks at are in the sample file `sample.env`. This file isn't used by the dashboard, it just
lists the environment variables that you can copy in your `rc` files:
- `TTC_BOTS` are the 3 twitter bots to check, comma separated. The first entry
- `TTC_BOTS` -- the 3 twitter bots to check, comma separated. The first entry
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this is that this changes makes it realy difficult to review your PR.
Pull request should ideally only taggle on feature or issue and should not make any changes to code that is not part of this change-set.

I like the new style. could you create a new PR that "fixes" the README please!?

in this list will be displayed in the big party parrot box.
- `TTC_SAY_BOX = parrot | bunny | llama | cat | yeoman | mario | ironman | minions | panda`, to party with a different parrot (or,
- `TTC_SAY_BOX = parrot | bunny | llama | cat | yeoman | mario | ironman | minions | panda` -- to party with a different parrot (or,
more specifically: to have a different animal say a message in the big box). You can create your own custom art(.ansi file) [here](https://gauravchl.github.io/ansi-art/webapp/) and download and supply it's absolute path to render it within box. (eg: `TTC_SAY_BOX='/Users/om/desktop/cat.ansi'`)
- `TTC_REPOS`, a comma separated list of repos to look at for `git` commits.
- `TTC_REPOS_DEPTH` is the max directory-depth to look for git repositories in
- `TTC_REPOS` -- a comma separated list of repos to look at for `git` commits.
- `TTC_REPOS_DEPTH` -- the max directory-depth to look for git repositories in
the directories defined with `TTC_REPOS` (by default 1). Note that the deeper
the directory depth, the slower the results will be fetched.
- `TTC_GITBOT` -- how to read your git commits. If you're having problems
seeing your commits in `tiny-terminal-care`, set this to `gitlog`
- `TTC_WEATHER`, the location to check the weather for. A zipcode doesn't
- `TTC_WEATHER` -- the location to check the weather for. A zipcode doesn't
always work, so if you can, use a location first (so prefer `Paris` over
`90210`)
- `TTC_CELSIUS` (by default true)
- `TTC_CELSIUS` -- celsius vs. fahrenheit (true by default)
- `TTC_APIKEYS` -- set this to false if you don't want to use Twitter API
keys and want to scrape the tweets instead.
- `TTC_UPDATE_INTERVAL`, set this to change the update frequency in minutes, default is 20 minutes.
- `TTC_TERMINAL_TITLE` -- set this to false if you don't want the terminal title
to be changed on startup.
- `TTC_GITBOT` -- how to read your git commits. If you're having problems
seeing your commits in `tiny-terminal-care`, set this to `gitlog`
- `TTC_TERMINAL_TITLE` -- set this to false if you don't want the terminal title to be changed on startup.
- `TTC_COMMITS_GRAPH` -- show/hide the commits graph (true by default). Will render number of commits in the labels of the today and week boxes when hidden.

#### Set up Twitter API keys

Expand Down
137 changes: 105 additions & 32 deletions care.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var bunnySay = require('sign-bunny');
var yosay = require('yosay');
var weather = require('weather-js');

var TODAY_BOX_LABEL = ' 📝 Today ';
var WEEK_BOX_LABEL = ' 📝 Week ';

var inPomodoroMode = false;

var screen = blessed.screen(
Expand Down Expand Up @@ -81,17 +84,13 @@ screen.key(['p', 'C-p'], function(ch, key) {
});

var grid = new contrib.grid({rows: 12, cols: 12, screen: screen});

// grid.set(row, col, rowSpan, colSpan, obj, opts)
var weatherBox = grid.set(0, 8, 2, 4, blessed.box, makeScrollBox(' 🌤 '));
var todayBox = grid.set(0, 0, 6, 6, blessed.box, makeScrollBox(' 📝 Today '));
var weekBox = grid.set(6, 0, 6, 6, blessed.box, makeScrollBox(' 📝 Week '));
var commits = grid.set(0, 6, 6, 2, contrib.bar, makeGraphBox('Commits'));
var parrotBox = grid.set(6, 6, 6, 6, blessed.box, makeScrollBox(''));

var tweetBoxes = {}
tweetBoxes[config.twitter[1]] = grid.set(2, 8, 2, 4, blessed.box, makeBox(' 💖 '));
tweetBoxes[config.twitter[2]] = grid.set(4, 8, 2, 4, blessed.box, makeBox(' 💬 '));
var boxes = buildBoxes(config.commitsGraph);
var weatherBox = boxes.weather;
var todayBox = boxes.today;
var weekBox = boxes.week;
var commits = boxes.commits;
var parrotBox = boxes.parrot;
var tweetBoxes = boxes.tweets;

tick();
setInterval(tick, 1000 * 60 * config.updateInterval);
Expand All @@ -102,6 +101,62 @@ function tick() {
doTheCodes();
}

function buildBoxes(showCommitsGraph) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the buildBoxes manages multibe boxes the funtion parameter should not be that specific.
I would recommend removing the parameter and just use the global config internally.

var firstQuadrant = buildFirstQuadrantBoxes(showCommitsGraph);

return {
today: buildTodayBox(),
week: buildWeekBox(),
tweets: firstQuadrant.tweets,
weather: firstQuadrant.weather,
commits: firstQuadrant.commits,
parrot: buildParrotBox()
};
}

function buildFirstQuadrantBoxes(showCommitsGraph) {
var col = 6, colSpan = 6;

if (showCommitsGraph) {
col += 2;
colSpan -= 2;
}

return {
tweets: buildTweetBoxes(col, colSpan),
weather: buildWeatherBox(col, colSpan),
commits: (showCommitsGraph) ? buildCommitsGraphBox() : null
};
}

// grid.set(row, col, rowSpan, colSpan, obj, opts)
function buildTweetBoxes(col, colSpan) {
var boxes = {};
boxes[config.twitter[1]] = grid.set(2, col, 2, colSpan, blessed.box, makeBox(' 💖 '));
boxes[config.twitter[2]] = grid.set(4, col, 2, colSpan, blessed.box, makeBox(' 💬 '));
return boxes;
}

function buildWeatherBox(col, colSpan) {
return grid.set(0, col, 2, colSpan, blessed.box, makeScrollBox(' 🌤 '));
}

function buildCommitsGraphBox() {
return grid.set(0, 6, 6, 2, contrib.bar, makeGraphBox('Commits'));
}

function buildTodayBox() {
return grid.set(0, 0, 6, 6, blessed.box, makeScrollBox(TODAY_BOX_LABEL));
}

function buildWeekBox() {
return grid.set(6, 0, 6, 6, blessed.box, makeScrollBox(WEEK_BOX_LABEL));
}

function buildParrotBox() {
return grid.set(6, 6, 6, 6, blessed.box, makeScrollBox(''));
}

function doTheWeather() {
weather.find({search: config.weather, degreeType: config.celsius ? 'C' : 'F'}, function(err, result) {
if (result && result[0] && result[0].current) {
Expand Down Expand Up @@ -157,29 +212,49 @@ function doTheCodes() {
var todayCommits = 0;
var weekCommits = 0;

function getCommits(data, box) {
var content = colorizeLog(data || '');
box.content += content;
function getNumCommits(commits) {
var commitRegex = /(.......) (- .*)/g;
return (box && box.content) ? (box.content.match(commitRegex) || []).length : '0';
return (commits) ? (commits.match(commitRegex) || []).length : '0';
}

function updateBoxContent(box, content, numCommits) {
var colorContent = colorizeLog(content || '');
box.content += colorContent;

if (!config.commitsGraph) {
var label = (box === todayBox) ? TODAY_BOX_LABEL : WEEK_BOX_LABEL;
box.setLabel(`${label} (${numCommits})`);
}

return box;
}

function updateWeekCommits(commits) {
weekCommits += getNumCommits(commits);

updateBoxContent(weekBox, commits, weekCommits);
updateCommitsGraph(todayCommits, weekCommits);

screen.render();
}

function updateTodayCommits(commits) {
todayCommits += getNumCommits(commits);

updateBoxContent(todayBox, commits, todayCommits);
updateCommitsGraph(todayCommits, weekCommits);

screen.render();
}

if (config.gitbot.toLowerCase() === 'gitstandup') {
var today = spawn('sh ' + __dirname + '/standup-helper.sh', ['-m ' + config.depth, config.repos], {shell:true});
todayBox.content = '';
today.stdout.on('data', data => {
todayCommits = getCommits(`${data}`, todayBox);
updateCommitsGraph(todayCommits, weekCommits);
screen.render();
});
today.stdout.on('data', data => { updateTodayCommits(`${data}`); });

var week = spawn('sh ' + __dirname + '/standup-helper.sh', ['-m ' + config.depth + ' -d 7', config.repos], {shell:true});
weekBox.content = '';
week.stdout.on('data', data => {
weekCommits = getCommits(`${data}`, weekBox);
updateCommitsGraph(todayCommits, weekCommits);
screen.render();
});
week.stdout.on('data', data => { updateWeekCommits(`${data}`); });
} else {
gitbot.findGitRepos(config.repos, config.depth-1, (err, allRepos) => {
if (err) {
Expand All @@ -192,19 +267,15 @@ function doTheCodes() {
screen.render();
}
todayBox.content = '';
todayCommits = getCommits(`${data}`, todayBox);
updateCommitsGraph(todayCommits, weekCommits);
screen.render();
updateTodayCommits(`${data}`);
});
gitbot.getCommitsFromRepos(allRepos, 7, (err, data) => {
if (err) {
return weekBox.content = err;
screen.render();
}
weekBox.content = '';
weekCommits = getCommits(`${data}`, weekBox);
updateCommitsGraph(todayCommits, weekCommits);
screen.render();
updateWeekCommits(`${data}`);
});
});
}
Expand Down Expand Up @@ -247,7 +318,9 @@ function makeGraphBox(label) {
}

function updateCommitsGraph(today, week) {
commits.setData({titles: ['today', 'week'], data: [today, week]})
if (commits) {
commits.setData({titles: ['today', 'week'], data: [today, week]})
}
}

function colorizeLog(text) {
Expand Down
3 changes: 3 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var config = {
// Set to false if you're an imperial savage. <3
celsius: (process.env.TTC_CELSIUS || 'true') === 'true',

// Show/hide the commits graph
commitsGraph: (process.env.TTC_COMMITS_GRAPH || 'true') === 'true',

terminal_title: (process.env.TTC_TERMINAL_TITLE === 'false' ? null : '✨💖 tiny care terminal 💖✨'),

updateInterval: parseFloat(process.env.TTC_UPDATE_INTERVAL) || 20,
Expand Down
3 changes: 3 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export TTC_APIKEYS=true
# Refresh the dashboard every 20 minutes.
export TTC_UPDATE_INTERVAL=20

# Show/hide the commits graph
export TTC_COMMITS_GRAPH=true

# Turn off terminal title
export TTC_TERMINAL_TITLE=false

Expand Down