diff --git a/README.md b/README.md index 758afd8..498f1c5 100644 --- a/README.md +++ b/README.md @@ -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 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 diff --git a/care.js b/care.js index d01afcb..c954764 100755 --- a/care.js +++ b/care.js @@ -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( @@ -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); @@ -102,6 +101,62 @@ function tick() { doTheCodes(); } +function buildBoxes(showCommitsGraph) { + 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) { @@ -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) { @@ -192,9 +267,7 @@ 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) { @@ -202,9 +275,7 @@ function doTheCodes() { screen.render(); } weekBox.content = ''; - weekCommits = getCommits(`${data}`, weekBox); - updateCommitsGraph(todayCommits, weekCommits); - screen.render(); + updateWeekCommits(`${data}`); }); }); } @@ -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) { diff --git a/config.js b/config.js index 56f444e..ef948b0 100644 --- a/config.js +++ b/config.js @@ -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, diff --git a/sample.env b/sample.env index ba30c53..af3ee11 100644 --- a/sample.env +++ b/sample.env @@ -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