aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2022-03-30 00:27:20 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2022-03-30 00:27:20 +0200
commit9aa205ce5c606812ce5042a4a981fd73d44d45f0 (patch)
tree998311cd7adb6d437ed9b00ed18e485eb5b4fc03 /src
parentIn progress (diff)
downloadgo2work-9aa205ce5c606812ce5042a4a981fd73d44d45f0.tar.gz
go2work-9aa205ce5c606812ce5042a4a981fd73d44d45f0.tar.bz2
go2work-9aa205ce5c606812ce5042a4a981fd73d44d45f0.tar.xz
go2work-9aa205ce5c606812ce5042a4a981fd73d44d45f0.tar.zst
go2work-9aa205ce5c606812ce5042a4a981fd73d44d45f0.zip
A lot more to do but it works for tonight
Diffstat (limited to 'src')
-rw-r--r--src/c_go2work.go33
-rw-r--r--src/u_prints.go64
-rw-r--r--src/u_utils.go17
3 files changed, 73 insertions, 41 deletions
diff --git a/src/c_go2work.go b/src/c_go2work.go
index 6cf5ab4..d7f7e41 100644
--- a/src/c_go2work.go
+++ b/src/c_go2work.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* go2work: src/c_go2work.go
- * Tue Mar 29 22:32:07 CEST 2022
+ * Wed Mar 30 00:16:51 CEST 2022
* Joe
*
* The main.
@@ -64,6 +64,7 @@ const (
)
func main() {
+ var curr_t [3]byte
var dest_t [3]byte
var tmp int
log.SetPrefix(PROGNAME + ": ")
@@ -82,24 +83,28 @@ func main() {
case "-v":
print_version()
return
+ case "-t":
+ dest_t = get_test_time()
+ default:
+ str_dest_t := strings.Split(os.Args[1], ":")
+ tmp, _ = strconv.Atoi(str_dest_t[HOURS])
+ dest_t[HOURS] = byte(tmp)
+ tmp, _ = strconv.Atoi(str_dest_t[MINS])
+ dest_t[MINS] = byte(tmp)
+ dest_t[SECS] = 0
}
- curr_t := get_time()
- str_dest_t := strings.Split(os.Args[1], ":")
- tmp, _ = strconv.Atoi(str_dest_t[HOURS])
- dest_t[HOURS] = byte(tmp)
- tmp, _ = strconv.Atoi(str_dest_t[MINS])
- dest_t[MINS] = byte(tmp)
- dest_t[SECS] = 0
- // dest_t = [2]int{0, 0}
- ticker := time.NewTicker(1 * time.Second)
+ curr_t = get_time()
+ print_time_left(curr_t, dest_t)
+ ticker := time.NewTicker(500 * time.Millisecond)
quit := make(chan struct{})
for {
select {
case <- ticker.C:
curr_t = get_time()
- // print_time(curr_t)
print_time_left(curr_t, dest_t)
- if curr_t[HOURS] == dest_t[HOURS] && curr_t[MINS] == dest_t[MINS] {
+ if curr_t[HOURS] == dest_t[HOURS] &&
+ curr_t[MINS] == dest_t[MINS] &&
+ curr_t[SECS] == dest_t[SECS] {
exec_player(
true,
"mpv",
@@ -128,3 +133,7 @@ func get_time() [3]byte {
curr_t[SECS] = byte(tmp)
return curr_t
}
+
+func get_test_time() [3]byte {
+ return seconds_to_time(time_to_seconds(get_time()) + 3)
+}
diff --git a/src/u_prints.go b/src/u_prints.go
index 6233763..64851dd 100644
--- a/src/u_prints.go
+++ b/src/u_prints.go
@@ -56,37 +56,49 @@ func print_time(t [3]byte) {
}
func print_time_left(curr_t [3]byte, dest_t [3]byte) {
+ var left_secs uint
curr_secs := time_to_seconds(curr_t)
dest_secs := time_to_seconds(dest_t)
- left_secs := curr_secs - dest_secs
- fmt.Println("left_secs: [", left_secs, "]")
- // left_t := seconds_to_time(left_secs)
- // if left_secs < 60 {
- // fmt.Print(
- // "\r",
- // left_t[SECS], "s",
- // " left to sleep",
- // )
- // } else if left_secs < 3600 {
- // fmt.Print(
- // "\r",
- // left_t[MINS], "m ",
- // left_t[SECS], "s",
- // " left to sleep",
- // )
- // } else {
- // fmt.Print(
- // "\r",
- // left_t[HOURS], "h ",
- // left_t[MINS], "m ",
- // left_t[SECS], "s",
- // " left to sleep",
- // )
- // }
+ if curr_secs <= dest_secs {
+ left_secs = dest_secs - curr_secs
+ } else {
+ left_secs = (dest_secs + (24 * 3600)) - curr_secs
+ }
+ left_t := seconds_to_time(left_secs)
+ if left_secs < 60 {
+ fmt.Print("\r ")
+ fmt.Print(
+ "\r",
+ left_t[SECS], "s",
+ " left to sleep",
+ )
+ } else if left_secs < 3600 {
+ fmt.Print(
+ "\r",
+ left_t[MINS], "m ",
+ left_t[SECS], "s",
+ " left to sleep",
+ )
+ } else {
+ fmt.Print(
+ "\r",
+ left_t[HOURS], "h ",
+ left_t[MINS], "m ",
+ left_t[SECS], "s",
+ " left to sleep",
+ )
+ }
}
func print_help() {
- fmt.Println("help")
+ fmt.Println("Usage:
+ go2work [option / time]
+
+Options:
+ -h show this help menu
+ -H show the real help menu
+ -v show version of go2work
+ ")
}
func print_real_help() {
diff --git a/src/u_utils.go b/src/u_utils.go
index a0c5008..598efed 100644
--- a/src/u_utils.go
+++ b/src/u_utils.go
@@ -39,14 +39,25 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* go2work: src/u_utils.go
- * Tue Mar 29 22:32:20 CEST 2022
+ * Wed Mar 30 00:02:25 CEST 2022
* Joe
*/
package main
-func time_to_seconds(time [3]byte) uint16 {
+func time_to_seconds(time [3]byte) uint {
+ return (3600 * uint(time[HOURS])) +
+ (60 * uint(time[MINS])) +
+ uint(time[SECS])
}
-func seconds_to_time(seconds uint16) [3]byte {
+func seconds_to_time(seconds uint) [3]byte {
+ var time [3]byte
+ var hours, mins uint
+ hours = seconds / 3600
+ time[HOURS] = byte(hours)
+ mins = (seconds - ((hours) * 3600)) / 60
+ time[MINS] = byte(mins)
+ time[SECS] = byte((seconds - (hours * 3600)) - mins * 60)
+ return time
}