aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c_defs.go2
-rw-r--r--c_exec.go3
-rw-r--r--c_hardflip.go19
-rw-r--r--c_init.go32
-rw-r--r--c_utils.go29
-rw-r--r--i_events.go110
-rw-r--r--i_ui.go78
7 files changed, 176 insertions, 97 deletions
diff --git a/c_defs.go b/c_defs.go
index ebe14a2..1ad421a 100644
--- a/c_defs.go
+++ b/c_defs.go
@@ -54,7 +54,7 @@ const (
(q)uit -
[x](a)dd/(i)nsert host -
[x](e)dit -
-[x](d)elete -
+[x](D)elete -
[x](s)earch -
(c-r) reload -
[x](?) help`
diff --git a/c_exec.go b/c_exec.go
index be22e1c..02b5342 100644
--- a/c_exec.go
+++ b/c_exec.go
@@ -48,7 +48,6 @@
package main
import (
- "fmt"
"os"
"os/exec"
"strconv"
@@ -57,7 +56,6 @@ import (
func c_exec_cmd(cmd_fmt []string) {
cmd := exec.Command(cmd_fmt[0], cmd_fmt[1:]...)
- fmt.Println(cmd_fmt)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
@@ -150,7 +148,6 @@ func c_format_cmd(id uint64, lhost *HostList) {
func c_exec(id uint64, lhost *HostList) {
if lhost.head == nil {
- fmt.Println("no hosts")
return
}
c_format_cmd(id, lhost)
diff --git a/c_hardflip.go b/c_hardflip.go
index 0b34828..27e8ef3 100644
--- a/c_hardflip.go
+++ b/c_hardflip.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_hardflip.go
- * Mon, 18 Dec 2023 16:56:07 +0100
+ * Wed Dec 20 10:50:24 2023
* Joe
*
* the main
@@ -47,7 +47,20 @@
package main
+import "github.com/gdamore/tcell/v2"
+
+type Data struct {
+ lhost *HostList
+ // dirs *DirList
+ opts Opts
+ s tcell.Screen
+}
+
func main() {
- lhost := c_load_data_dir(c_get_data_dir())
- i_ui(lhost)
+ data := Data{
+ c_load_data_dir(c_get_data_dir()),
+ Opts{true, true},
+ nil,
+ }
+ i_ui(&data)
}
diff --git a/c_init.go b/c_init.go
index 5454928..5f49455 100644
--- a/c_init.go
+++ b/c_init.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_init.go
- * Fri, 15 Dec 2023 17:27:13 +0100
+ * Wed Dec 20 10:47:33 2023
* Joe
*
* init functions
@@ -48,37 +48,13 @@
package main
import (
- "fmt"
"os"
"path/filepath"
)
-// this function will go get the data folder and try to create it if it does
-// not exist
-// the first path being checked is $XDG_DATA_HOME then $HOME/.local/share
-// it returns the full data directory path
-func c_get_data_dir() string {
- var ptr *string
- var home string
- if home = os.Getenv("HOME"); len(home) == 0 {
- c_die("env variable HOME not defined", nil)
- }
- xdg_home := os.Getenv("XDG_DATA_HOME")
-
- if len(xdg_home) > 0 {
- ptr = &xdg_home
- } else {
- ptr = &home
- *ptr += "/.local/share"
- }
- *ptr += "/hardflip"
- if _, err := os.Stat(*ptr); os.IsNotExist(err) {
- if err := os.MkdirAll(*ptr, os.ModePerm); err != nil {
- c_die("could not create path " + *ptr, err)
- }
- fmt.Println("created folder path " + *ptr)
- }
- return *ptr
+type Opts struct {
+ icon bool
+ loop bool
}
// this function recurses into the specified root directory in order to load
diff --git a/c_utils.go b/c_utils.go
index 0ef70c1..a2b420c 100644
--- a/c_utils.go
+++ b/c_utils.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_utils.go
- * Thu, 14 Dec 2023 12:59:16 +0100
+ * Wed Dec 20 10:50:12 2023
* Joe
*
* core funcs
@@ -52,6 +52,33 @@ import (
"os"
)
+// this function will go get the data folder and try to create it if it does
+// not exist
+// the first path being checked is $XDG_DATA_HOME then $HOME/.local/share
+// it returns the full data directory path
+func c_get_data_dir() string {
+ var ptr *string
+ var home string
+ if home = os.Getenv("HOME"); len(home) == 0 {
+ c_die("env variable HOME not defined", nil)
+ }
+ xdg_home := os.Getenv("XDG_DATA_HOME")
+
+ if len(xdg_home) > 0 {
+ ptr = &xdg_home
+ } else {
+ ptr = &home
+ *ptr += "/.local/share"
+ }
+ *ptr += "/hardflip"
+ if _, err := os.Stat(*ptr); os.IsNotExist(err) {
+ if err := os.MkdirAll(*ptr, os.ModePerm); err != nil {
+ c_die("could not create path " + *ptr, err)
+ }
+ }
+ return *ptr
+}
+
// c_die displays an error string to the stderr fd and exits the program
// with the return code 1
// it takes an optional err argument of the error type as a complement of
diff --git a/i_events.go b/i_events.go
new file mode 100644
index 0000000..28a40b5
--- /dev/null
+++ b/i_events.go
@@ -0,0 +1,110 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2023 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.
+ *
+ * hardflip: src/i_events.go
+ * Wed Dec 20 11:05:16 2023
+ * Joe
+ *
+ * the hosts linked list
+ */
+
+package main
+
+import(
+ "os"
+ "github.com/gdamore/tcell/v2"
+)
+
+// screen events such as keypresses
+func i_events(data *Data,
+ sel *uint64, sel_max *uint64,
+ term_size *[2]int,
+ quit func()) {
+ var err error
+ event := data.s.PollEvent()
+ switch event := event.(type) {
+ case *tcell.EventResize:
+ data.s.Sync()
+ case *tcell.EventKey:
+ if event.Key() == tcell.KeyEscape ||
+ event.Key() == tcell.KeyCtrlC ||
+ event.Rune() == 'q' {
+ quit()
+ os.Exit(0)
+ }
+ if event.Rune() == 'j' ||
+ event.Key() == tcell.KeyDown {
+ if *sel < *sel_max - 1 {
+ *sel += 1
+ }
+ }
+ if event.Rune() == 'k' ||
+ event.Key() == tcell.KeyUp {
+ if *sel > 0 {
+ *sel -= 1
+ }
+ }
+ if event.Key() == tcell.KeyEnter {
+ quit()
+ c_exec(*sel, data.lhost)
+ if data.opts.loop == false {
+ os.Exit(0)
+ }
+ if data.s, err = tcell.NewScreen(); err != nil {
+ c_die("view", err)
+ }
+ if err := data.s.Init(); err != nil {
+ c_die("view", err)
+ }
+ def_style := tcell.StyleDefault.
+ Background(tcell.ColorReset).
+ Foreground(tcell.ColorReset)
+ data.s.SetStyle(def_style)
+ }
+ if event.Key() == tcell.KeyCtrlR {
+ data.lhost = c_load_data_dir(c_get_data_dir())
+ l := data.lhost
+ *sel_max = l.count()
+ if *sel >= *sel_max {
+ *sel = *sel_max - 1
+ }
+ }
+ }
+}
diff --git a/i_ui.go b/i_ui.go
index 8eadb55..6c022dc 100644
--- a/i_ui.go
+++ b/i_ui.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.
*
- * hardflip: src/c_hardflip.go
- * Tue Dec 19 18:51:35 2023
+ * hardflip: src/i_ui.go
+ * Wed Dec 20 11:05:07 2023
* Joe
*
* interfacing with the user
@@ -48,7 +48,6 @@
package main
import (
- "os"
"strconv"
"github.com/gdamore/tcell/v2"
"golang.org/x/term"
@@ -355,79 +354,36 @@ func i_info_panel(s tcell.Screen, t [2]int,
}
}
-func i_events(s tcell.Screen,
- sel *uint64, sel_max *uint64,
- term_size *[2]int,
- lhost **HostList,
- quit func()) {
- event := s.PollEvent()
- switch event := event.(type) {
- case *tcell.EventResize:
- s.Sync()
- case *tcell.EventKey:
- if event.Key() == tcell.KeyEscape ||
- event.Key() == tcell.KeyCtrlC ||
- event.Rune() == 'q' {
- quit()
- os.Exit(0)
- }
- if event.Rune() == 'j' ||
- event.Key() == tcell.KeyDown {
- if *sel < *sel_max - 1 {
- *sel += 1
- }
- }
- if event.Rune() == 'k' ||
- event.Key() == tcell.KeyUp {
- if *sel > 0 {
- *sel -= 1
- }
- }
- if event.Key() == tcell.KeyEnter {
- quit()
- c_exec(*sel, *lhost)
- os.Exit(0)
- }
- if event.Key() == tcell.KeyCtrlR {
- *lhost = c_load_data_dir(c_get_data_dir())
- l := *lhost
- *sel_max = l.count()
- if *sel >= *sel_max {
- *sel = *sel_max - 1
- }
- }
- }
-}
-
-func i_ui(lhost *HostList) {
- screen, err := tcell.NewScreen()
+func i_ui(data *Data) {
+ var err error
+ data.s, err = tcell.NewScreen()
var term_size [2]int
var sel uint64 = 0
- sel_max := lhost.count()
+ sel_max := data.lhost.count()
if err != nil {
c_die("view", err)
}
- if err := screen.Init(); err != nil {
+ if err := data.s.Init(); err != nil {
c_die("view", err)
}
def_style := tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.ColorReset)
- screen.SetStyle(def_style)
+ data.s.SetStyle(def_style)
quit := func() {
- screen.Fini()
+ data.s.Fini()
}
for {
term_size[W], term_size[H], _ = term.GetSize(0)
- screen.Clear()
- i_bottom_text(screen, term_size)
- i_host_panel(screen, term_size, def_style, lhost, sel, sel_max)
- i_info_panel(screen, term_size, def_style, lhost, sel)
- if lhost.head == nil {
- i_draw_zhosts_box(screen, term_size, def_style)
+ data.s.Clear()
+ i_bottom_text(data.s, term_size)
+ i_host_panel(data.s, term_size, def_style, data.lhost, sel, sel_max)
+ i_info_panel(data.s, term_size, def_style, data.lhost, sel)
+ if data.lhost.head == nil {
+ i_draw_zhosts_box(data.s, term_size, def_style)
}
- screen.Show()
- i_events(screen, &sel, &sel_max, &term_size, &lhost, quit)
+ data.s.Show()
+ i_events(data, &sel, &sel_max, &term_size, quit)
}
}