forked from AntoinePlu/break-break-break
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
129 lines (100 loc) · 2.67 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Breather
*/
// import
var ProgressBar = require("progress")
, http = require("http")
, fs = require("fs")
, growl = require("growl")
, readline = require("readline")
, globalSettings = require(process.env.HOME + "/.breather")
, settings = globalSettings.settings
, pre = globalSettings.pre
, post = globalSettings.post
, weatherAPI = "http://api.openweathermap.org/data/2.5/weather?q="
, parseWeather = require("./lib/parse-weather.js")
, i18n = require("./i18n/" + ( settings.lang || "en" ) )
// functions
// weather
function checkWeather() {
http.get( weatherAPI + settings.location, function( response ) {
var json = ""
response.on("data", function( c ) {
json += c
})
response.on("end", function() {
setTimeout(function() {
var message = parseWeather( JSON.parse( json ) )
growl( message, {title : i18n.title} )
console.log("\n> " + message)
}, 6000)
})
})
}
// clock
function clock() {
bar.update()
if ( !bar.complete ) return setTimeout( clock, 1000 )
post()
growl( i18n.breakNotification, {title : i18n.title} )
// if( settings.location ) {
// checkWeather()
// }
console.log("\n> " + i18n.breakNotification)
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.question("\n" + i18n.anotherSessionQuestion + " (Y/time/n) ", function( answer ) {
var intAnswer = parseInt( answer, 10 )
if ( !isNaN( intAnswer ) ) {
settings.duration = intAnswer
fs.writeFile("./config/settings.json", JSON.stringify( settings, null, 2 ), function ( err ) {
if (err) throw err
})
}
if ( answer !== "n" && answer !== "N" ) {
programme()
}
else {
console.log( "\n" + i18n.byeBye)
}
rl.close()
})
}
// intro
function intro() {
console.log("\n" + new Date())
console.log(" ____ _ _ ")
console.log(" | __ ) _ __ ___ __ _| |_| |__ ___ _ __ ")
console.log(" | _ \\| '__/ _ \\/ _` | __| '_ \\ / _ \\ '__|")
console.log(" | |_) | | | __/ (_| | |_| | | | __/ | ")
console.log(" |____/|_| \\___|\\__,_|\\__|_| |_|\\___|_| ")
console.log("\n..." + i18n.workMessage)
}
// programme
function programme() {
duration = parseFloat( settings.duration )
// init bar
bar = new ProgressBar(i18n.progressBar, {
total: duration * 60
, width: 30
, complete: "●"
, incomplete: " "
})
// start progress bar
console.log()
bar.tick( 0 )
// start pre-tasks
pre()
// start process
setTimeout( clock, 1000 )
}
// variables
var duration
, bar
, rl
// start the generique!
intro()
// here we go.
programme()