diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2022-03-29 22:18:15 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2022-03-29 22:18:15 +0200 |
commit | 4be5f62f0adc412c7eccccee59d03c00e5c4b5cf (patch) | |
tree | d3118e6fc8c60500b328e115ed5427900c21c2db | |
parent | New file (diff) | |
download | go2work-4be5f62f0adc412c7eccccee59d03c00e5c4b5cf.tar.gz go2work-4be5f62f0adc412c7eccccee59d03c00e5c4b5cf.tar.bz2 go2work-4be5f62f0adc412c7eccccee59d03c00e5c4b5cf.tar.xz go2work-4be5f62f0adc412c7eccccee59d03c00e5c4b5cf.tar.zst go2work-4be5f62f0adc412c7eccccee59d03c00e5c4b5cf.zip |
Update
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | src/c_go2work.go | 29 | ||||
-rw-r--r-- | src/u_prints.go (renamed from src/c_prints.go) | 31 | ||||
-rw-r--r-- | src/u_utils.go | 52 |
5 files changed, 102 insertions, 19 deletions
@@ -1 +1,2 @@ +#* go2work @@ -11,7 +11,7 @@ # ======================== # # go2work: Makefile -# Tue Mar 29 21:08:26 CEST 2022 +# Tue Mar 29 22:14:45 CEST 2022 # Joe # # GNU Makefile @@ -27,7 +27,8 @@ TRGT_DIR = ./ SRCS_NAME = c_go2work SRCS_NAME += c_player -SRCS_NAME += c_prints +SRCS_NAME += u_prints +SRCS_NAME += u_utils SRCS = $(addprefix ${SRCS_DIR}, $(addsuffix .go, ${SRCS_NAME})) @@ -51,4 +52,5 @@ run: # File prefixes info # ------------------ -# c_ -> core program related +# c_ -> core program +# u_ -> utils related diff --git a/src/c_go2work.go b/src/c_go2work.go index 89fb91d..3daa17b 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 20:55:49 CEST 2022 + * Tue Mar 29 22:14:51 CEST 2022 * Joe * * The main. @@ -51,6 +51,7 @@ import ( "log" "os" "time" + "strconv" "strings" ) @@ -63,6 +64,7 @@ const ( ) func main() { + var dest_t [2]int log.SetPrefix(PROGNAME + ": ") log.SetFlags(0) if len(os.Args[0:]) == 1 { @@ -81,17 +83,26 @@ func main() { return } curr_t := get_time() - dest_t := strings.Split(os.Args[1], ":") + str_dest_t := strings.Split(os.Args[1], ":") + dest_t[HOURS], _ = strconv.Atoi(str_dest_t[HOURS]) + dest_t[MINS], _ = strconv.Atoi(str_dest_t[MINS]) + // dest_t = [2]int{0, 0} ticker := time.NewTicker(1 * time.Second) quit := make(chan struct{}) - print_time(curr_t) for { select { case <- ticker.C: curr_t = get_time() - print_time(curr_t) + // print_time(curr_t) + print_time_left(curr_t, dest_t) if curr_t[HOURS] == dest_t[HOURS] && curr_t[MINS] == dest_t[MINS] { - exec_player(true, "mpv", "--no-video", "/usr/home/jozan/mu/progressive/progressive_black_metal/deathspell_omega/2010_paracletus/02_wings_of_predation.flac") + exec_player( + true, + "mpv", + "--no-video", + "/usr/home/jozan/mu/progressive/progressive_black_metal/deathspell_omega/2010_paracletus/02_wings_of_predation.flac", + ) + return } case <- quit: ticker.Stop() @@ -100,8 +111,12 @@ func main() { } } -func get_time() []string { +func get_time() [3]int { + var curr_t [3]int now := time.Now() t := strings.Split(now.Format("15:04:05"), ":") - return t + curr_t[HOURS], _ = strconv.Atoi(t[HOURS]) + curr_t[MINS], _ = strconv.Atoi(t[MINS]) + curr_t[SECS], _ = strconv.Atoi(t[SECS]) + return curr_t } diff --git a/src/c_prints.go b/src/u_prints.go index 283fae4..45c48eb 100644 --- a/src/c_prints.go +++ b/src/u_prints.go @@ -38,8 +38,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * go2work: src/c_prints.go - * Tue Mar 29 21:03:26 CEST 2022 + * go2work: src/u_prints.go + * Tue Mar 29 22:15:02 CEST 2022 * Joe * * Stuff to print @@ -49,8 +49,28 @@ package main import ( "fmt" + "strconv" ) +func print_time(t []string) { + fmt.Print("\rTime is: ", t[HOURS], ":", t[MINS], ":", t[SECS]) +} + +func print_time_left(curr_t []int, dest_t []int) { + var left_t [2]int + left_t = int{0, 0} + h, _ := strconv.Atoi(curr) + m + s, _ := strconv.Atoi(curr_t[SECS]) + s = 60 - s + fmt.Print( + "\rTime left to sleep: ", + left_t[HOURS], "h ", + left_t[MINS], "m ", + s, "s", + ) +} + func print_help() { fmt.Println("help") } @@ -62,10 +82,3 @@ func print_real_help() { func print_version() { fmt.Println(PROGNAME, VERSION) } - -func print_time(t []string) { - fmt.Print("\rTime is: ", t[HOURS], ":", t[MINS], ":", t[SECS]) -} - -func print_left_to_sleep(curr_t []string, dest_t []string) { -} diff --git a/src/u_utils.go b/src/u_utils.go new file mode 100644 index 0000000..88b8768 --- /dev/null +++ b/src/u_utils.go @@ -0,0 +1,52 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2022 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * go2work: src/u_utils.go + * Tue Mar 29 22:15:50 CEST 2022 + * Joe + */ + +package main + +func time_to_seconds(time [3]int) int { +} + +func seconds_to_time(seconds int) [3]int { +} |