aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2023-12-20 20:20:20 +0100
committerJoe <rbo@gmx.us>2023-12-20 20:20:20 +0100
commit7984a7e7073cae00a2d9dd5f37a32c3136ba14a4 (patch)
tree5770101ac639ecc801c2b7b20249a98c1d223cc3
parentfuck ye (diff)
downloadhardflip-7984a7e7073cae00a2d9dd5f37a32c3136ba14a4.tar.gz
hardflip-7984a7e7073cae00a2d9dd5f37a32c3136ba14a4.tar.bz2
hardflip-7984a7e7073cae00a2d9dd5f37a32c3136ba14a4.tar.xz
hardflip-7984a7e7073cae00a2d9dd5f37a32c3136ba14a4.tar.zst
hardflip-7984a7e7073cae00a2d9dd5f37a32c3136ba14a4.zip
refactor
-rw-r--r--c_hardflip.go23
-rw-r--r--c_init.go2
-rw-r--r--i_events.go62
-rw-r--r--i_ui.go337
4 files changed, 215 insertions, 209 deletions
diff --git a/c_hardflip.go b/c_hardflip.go
index ca231f7..c3e871a 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
- * Wed Dec 20 10:50:24 2023
+ * Wed Dec 20 16:34:51 2023
* Joe
*
* the main
@@ -47,29 +47,22 @@
package main
-import (
- // "os"
-
- "github.com/gdamore/tcell/v2"
-)
-
-type Data struct {
+// the main data structure, holds up everything important
+type HardData struct {
lhost *HostList
// dirs *DirList
- opts Opts
- s tcell.Screen
+ ui HardUI
+ opts HardOpts
data_dir string
- list_start int
}
func main() {
data_dir := c_get_data_dir()
- data := Data{
+ data := HardData{
c_load_data_dir(data_dir),
- Opts{true, true},
- nil,
+ HardUI{},
+ HardOpts{true, true},
data_dir,
- 0,
}
i_ui(&data)
}
diff --git a/c_init.go b/c_init.go
index 5f49455..51ce67a 100644
--- a/c_init.go
+++ b/c_init.go
@@ -52,7 +52,7 @@ import (
"path/filepath"
)
-type Opts struct {
+type HardOpts struct {
icon bool
loop bool
}
diff --git a/i_events.go b/i_events.go
index 74dbe06..df96cab 100644
--- a/i_events.go
+++ b/i_events.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/i_events.go
- * Wed Dec 20 16:17:19 2023
+ * Wed Dec 20 16:35:04 2023
* Joe
*
* the hosts linked list
@@ -52,81 +52,69 @@ import (
"github.com/gdamore/tcell/v2"
)
-func i_delete_selected(data *Data, sel *uint64) {
- host := data.lhost.sel(*sel)
- file_path := data.data_dir + "/" + host.Folder + host.Filename
- err := os.Remove(file_path)
- if err != nil {
- }
- // TODO: err, confirm
-}
-
-func i_reload_data(data *Data, sel, sel_max *uint64) {
+func i_reload_data(data *HardData) {
+ ui := data.ui
data.lhost = c_load_data_dir(data.data_dir)
l := data.lhost
- *sel_max = l.count()
- if *sel >= *sel_max {
- *sel = *sel_max - 1
+ data.ui.sel_max = l.count()
+ if ui.sel >= ui.sel_max {
+ ui.sel = ui.sel_max - 1
}
}
// screen events such as keypresses
-func i_events(data *Data,
- sel, sel_max *uint64,
- term_size *[2]int) {
+func i_events(data *HardData) {
var err error
- event := data.s.PollEvent()
+ ui := &data.ui
+ event := ui.s.PollEvent()
switch event := event.(type) {
case *tcell.EventResize:
- data.s.Sync()
+ ui.s.Sync()
case *tcell.EventKey:
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC ||
event.Rune() == 'q' {
- data.s.Fini()
+ ui.s.Fini()
os.Exit(0)
}
if event.Rune() == 'j' ||
event.Key() == tcell.KeyDown {
- if *sel < *sel_max - 1 {
- *sel += 1
+ if ui.sel < ui.sel_max - 1 {
+ ui.sel += 1
}
}
if event.Rune() == 'k' ||
event.Key() == tcell.KeyUp {
- if *sel > 0 {
- *sel -= 1
+ if ui.sel > 0 {
+ ui.sel -= 1
}
}
if event.Rune() == 'g' {
- *sel = 0
+ ui.sel = 0
}
if event.Rune() == 'G' {
- *sel = *sel_max - 1
+ ui.sel = ui.sel_max - 1
}
if event.Rune() == 'D' {
- i_delete_selected(data, sel)
- i_reload_data(data, sel, sel_max)
+ ui.delete_mode = true
+ ui.delete_id = ui.sel
}
if event.Key() == tcell.KeyEnter {
- data.s.Fini()
- c_exec(*sel, data.lhost)
+ ui.s.Fini()
+ c_exec(ui.sel, data.lhost)
if data.opts.loop == false {
os.Exit(0)
}
- if data.s, err = tcell.NewScreen(); err != nil {
+ if ui.s, err = tcell.NewScreen(); err != nil {
c_die("view", err)
}
- if err := data.s.Init(); err != nil {
+ if err := ui.s.Init(); err != nil {
c_die("view", err)
}
- def_style := tcell.StyleDefault.
- Background(tcell.ColorReset).
- Foreground(tcell.ColorReset)
- data.s.SetStyle(def_style)
+ ui.s.SetStyle(ui.def_style)
}
if event.Key() == tcell.KeyCtrlR {
- i_reload_data(data, sel, sel_max)
+ i_reload_data(data)
}
}
}
diff --git a/i_ui.go b/i_ui.go
index aa56c45..d6c3c63 100644
--- a/i_ui.go
+++ b/i_ui.go
@@ -54,6 +54,18 @@ import (
"golang.org/x/term"
)
+type HardUI struct {
+ s tcell.Screen
+ list_start int
+ delete_mode bool
+ delete_id uint64
+ sel uint64
+ sel_max uint64
+ def_style tcell.Style
+ bot_style tcell.Style
+ dim [2]int
+}
+
func i_draw_text(s tcell.Screen,
x1, y1, x2, y2 int,
style tcell.Style, text string) {
@@ -102,81 +114,75 @@ func i_draw_box(s tcell.Screen, x1, y1, x2, y2 int, title string) {
i_draw_text(s, x1 + 1, y1, x2 - 1, y2 - 1, style, title)
}
-func i_bottom_text(s tcell.Screen, t [2]int) {
- style := tcell.StyleDefault.
- Background(tcell.ColorReset).
- Foreground(tcell.ColorGrey)
+func i_bottom_text(ui HardUI) {
spaces := ""
- for i := 0; i < (t[W]) - len(KEYS_HINTS); i++ {
+ for i := 0; i < (ui.dim[W]) - len(KEYS_HINTS); i++ {
spaces += " "
}
- i_draw_text(s, 0, t[H] - 1, t[W], t[H] - 1, style, spaces + KEYS_HINTS)
+ i_draw_text(ui.s,
+ 0, ui.dim[H] - 1, ui.dim[W], ui.dim[H] - 1,
+ ui.def_style.Dim(true), spaces + KEYS_HINTS)
}
-func i_draw_zhosts_box(s tcell.Screen, t [2]int, def_style tcell.Style) {
+func i_draw_zhosts_box(ui HardUI) {
text := "Hosts list empty. Add hosts by pressing (a)"
left, right :=
- (t[W] / 2) - (len(text) / 2) - 5,
- (t[W] / 2) + (len(text) / 2) + 5
+ (ui.dim[W] / 2) - (len(text) / 2) - 5,
+ (ui.dim[W] / 2) + (len(text) / 2) + 5
top, bot :=
- (t[H] / 2) - 3,
- (t[H] / 2) + 3
- i_draw_box(s, left, top, right, bot, "")
- if left < t[W] / 3 {
+ (ui.dim[H] / 2) - 3,
+ (ui.dim[H] / 2) + 3
+ i_draw_box(ui.s, left, top, right, bot, "")
+ if left < ui.dim[W] / 3 {
for y := top + 1; y < bot; y++ {
- s.SetContent(t[W] / 3, y, ' ', nil, def_style)
+ ui.s.SetContent(ui.dim[W] / 3, y, ' ', nil, ui.def_style)
}
}
- i_draw_text(s,
- (t[W] / 2) - (len(text) / 2), t[H] / 2, right, t[H] / 2,
- def_style, text)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 2) - (len(text) / 2), ui.dim[H] / 2, right, ui.dim[H] / 2,
+ ui.def_style, text)
}
-func i_host_panel(data *Data, t [2]int,
- def_style tcell.Style,
- sel uint64, sel_max uint64) {
- i_draw_box(data.s, 0, 0,
- t[W] / 3, t[H] - 2,
+func i_host_panel(ui HardUI, lhost *HostList) {
+ i_draw_box(ui.s, 0, 0,
+ ui.dim[W] / 3, ui.dim[H] - 2,
" Hosts ")
- host := data.lhost.head
- for i := 0; i < data.list_start && host.next != nil; i++ {
+ host := lhost.head
+ for i := 0; i < ui.list_start && host.next != nil; i++ {
host = host.next
}
- for line := 1; line < t[H] - 2 && host != nil; line++ {
- style := def_style
- if sel == host.ID {
- style = tcell.StyleDefault.
- Background(tcell.ColorWhite).
- Foreground(tcell.ColorBlack)
+ for line := 1; line < ui.dim[H] - 2 && host != nil; line++ {
+ style := ui.def_style
+ if ui.sel == host.ID {
+ style = ui.def_style.Reverse(true)
}
spaces := ""
- for i := 0; i < (t[W] / 3) - len(host.Folder + host.Name) - 2; i++ {
+ for i := 0; i < (ui.dim[W] / 3) - len(host.Folder + host.Name) - 2; i++ {
spaces += " "
}
if host.Type == 0 {
- i_draw_text(data.s,
- 1, line, t[W] / 3, line,
+ i_draw_text(ui.s,
+ 1, line, ui.dim[W] / 3, line,
style, "  " + host.Folder + host.Name + spaces)
} else if host.Type == 1 {
- i_draw_text(data.s,
- 1, line, t[W] / 3, line,
+ i_draw_text(ui.s,
+ 1, line, ui.dim[W] / 3, line,
style, "  " + host.Folder + host.Name + spaces)
}
- i_draw_text(data.s,
- 4, line, t[W] / 3, line,
+ i_draw_text(ui.s,
+ 4, line, ui.dim[W] / 3, line,
style, host.Folder + host.Name + spaces)
host = host.next
}
- i_draw_text(data.s,
- 1, t[H] - 2, (t[W] / 3) - 1, t[H] - 2,
- def_style,
- " " + strconv.Itoa(int(sel + 1)) + "/" +
- strconv.Itoa(int(sel_max)) + " hosts ")
+ i_draw_text(ui.s,
+ 1, ui.dim[H] - 2, (ui.dim[W] / 3) - 1, ui.dim[H] - 2,
+ ui.def_style,
+ " " + strconv.Itoa(int(ui.sel + 1)) + "/" +
+ strconv.Itoa(int(ui.sel_max)) + " hosts ")
}
-func i_info_panel(s tcell.Screen, t [2]int,
- def_style tcell.Style, lhost *HostList, sel uint64) {
+func i_info_panel(ui HardUI, lhost *HostList) {
title_style := tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.ColorBlue).Dim(true).Bold(true)
@@ -184,15 +190,15 @@ func i_info_panel(s tcell.Screen, t [2]int,
curr_line := 2
var host_type string
- i_draw_box(s, (t[W] / 3), 0,
- t[W] - 1, t[H] - 2,
+ i_draw_box(ui.s, (ui.dim[W] / 3), 0,
+ ui.dim[W] - 1, ui.dim[H] - 2,
" Infos ")
- s.SetContent(t[W] / 3, 0, tcell.RuneTTee, nil, def_style)
- s.SetContent(t[W] / 3, t[H] - 2, tcell.RuneBTee, nil, def_style)
+ ui.s.SetContent(ui.dim[W] / 3, 0, tcell.RuneTTee, nil, ui.def_style)
+ ui.s.SetContent(ui.dim[W] / 3, ui.dim[H] - 2, tcell.RuneBTee, nil, ui.def_style)
if lhost.head == nil {
return
}
- host = lhost.sel(sel)
+ host = lhost.sel(ui.sel)
if host.Type == 0 {
host_type = "SSH"
} else if host.Type == 1 {
@@ -200,118 +206,118 @@ func i_info_panel(s tcell.Screen, t [2]int,
}
// name, type
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Name: ")
- i_draw_text(s,
- (t[W] / 3) + 10, curr_line, t[W] - 2, curr_line,
- def_style, host.Name)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 10, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.Name)
curr_line += 1
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Type: ")
- i_draw_text(s,
- (t[W] / 3) + 10, curr_line, t[W] - 2, curr_line,
- def_style, host_type)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 10, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host_type)
curr_line += 2
// host, port
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Host: ")
- i_draw_text(s,
- (t[W] / 3) + 10, curr_line, t[W] - 2, curr_line,
- def_style, host.Host)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 10, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.Host)
curr_line += 1
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Port: ")
- i_draw_text(s,
- (t[W] / 3) + 10, curr_line, t[W] - 2, curr_line,
- def_style, strconv.Itoa(int(host.Port)))
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 10, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, strconv.Itoa(int(host.Port)))
curr_line += 1
// RDP shit
if host.Type == 1 {
if len(host.Domain) > 0 {
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Domain: ")
- i_draw_text(s,
- (t[W] / 3) + 12, curr_line, t[W] - 2, curr_line,
- def_style, host.Domain)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 12, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.Domain)
curr_line += 1
}
}
curr_line += 1
// user infos
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "User: ")
- i_draw_text(s,
- (t[W] / 3) + 10, curr_line, t[W] - 2, curr_line,
- def_style, host.User)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 10, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.User)
curr_line += 1
if len(host.Pass) > 0 {
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Pass: ")
- i_draw_text(s,
- (t[W] / 3) + 10, curr_line, t[W] - 2, curr_line,
- def_style, "***")
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 10, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, "***")
curr_line += 1
}
if host.Type == 0 && len(host.Priv) > 0 {
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Privkey: ")
- i_draw_text(s,
- (t[W] / 3) + 13, curr_line, t[W] - 2, curr_line,
- def_style, host.Priv)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 13, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.Priv)
curr_line += 1
}
curr_line += 1
// jump
if host.Type == 0 && len(host.Jump) > 0 {
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Jump settings: ")
curr_line += 1
- i_draw_text(s,
- (t[W] / 3) + 5, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 5, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Host: ")
- i_draw_text(s,
- (t[W] / 3) + 11, curr_line, t[W] - 2, curr_line,
- def_style, host.Jump)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 11, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.Jump)
curr_line += 1
- i_draw_text(s,
- (t[W] / 3) + 5, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 5, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Port: ")
- i_draw_text(s,
- (t[W] / 3) + 11, curr_line, t[W] - 2, curr_line,
- def_style, strconv.Itoa(int(host.JumpPort)))
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 11, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, strconv.Itoa(int(host.JumpPort)))
curr_line += 1
- i_draw_text(s,
- (t[W] / 3) + 5, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 5, curr_line, ui.dim[W] - 2, curr_line,
title_style, "User: ")
- i_draw_text(s,
- (t[W] / 3) + 11, curr_line, t[W] - 2, curr_line,
- def_style, host.JumpUser)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 11, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.JumpUser)
curr_line += 1
if len(host.JumpPass) > 0 {
- i_draw_text(s,
- (t[W] / 3) + 5, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 5, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Pass: ")
- i_draw_text(s,
- (t[W] / 3) + 11, curr_line, t[W] - 2, curr_line,
- def_style, "***")
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 11, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, "***")
curr_line += 1
}
if host.Type == 0 && len(host.JumpPriv) > 0 {
- i_draw_text(s,
- (t[W] / 3) + 5, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 5, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Privkey: ")
- i_draw_text(s,
- (t[W] / 3) + 14, curr_line, t[W] - 2, curr_line,
- def_style, host.JumpPriv)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 14, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.JumpPriv)
curr_line += 1
}
curr_line += 1
@@ -319,75 +325,94 @@ func i_info_panel(s tcell.Screen, t [2]int,
// RDP shit
if host.Type == 1 {
qual := [3]string{"Low", "Medium", "High"}
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Screen size: ")
- i_draw_text(s,
- (t[W] / 3) + 17, curr_line, t[W] - 2, curr_line,
- def_style,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 17, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style,
strconv.Itoa(int(host.Width)) + "x" +
strconv.Itoa(int(host.Height)))
curr_line += 1
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Dynamic window: ")
- i_draw_text(s,
- (t[W] / 3) + 20, curr_line, t[W] - 2, curr_line,
- def_style, strconv.FormatBool(host.Dynamic))
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 20, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, strconv.FormatBool(host.Dynamic))
curr_line += 1
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Quality: ")
- i_draw_text(s,
- (t[W] / 3) + 13, curr_line, t[W] - 2, curr_line,
- def_style, qual[host.Quality])
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 13, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, qual[host.Quality])
curr_line += 1
curr_line += 1
}
// note
if len(host.Note) > 0 {
- i_draw_text(s,
- (t[W] / 3) + 4, curr_line, t[W] - 2, curr_line,
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line,
title_style, "Note: ")
- i_draw_text(s,
- (t[W] / 3) + 10, curr_line, t[W] - 2, curr_line,
- def_style, host.Note)
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 10, curr_line, ui.dim[W] - 2, curr_line,
+ ui.def_style, host.Note)
curr_line += 1
}
}
-func i_ui(data *Data) {
+func i_ui(data *HardData) {
var err error
- data.s, err = tcell.NewScreen()
- var term_size [2]int
- var sel uint64 = 0
- sel_max := data.lhost.count()
+ ui := &data.ui
+ ui.s, err = tcell.NewScreen()
+ ui.sel_max = data.lhost.count()
if err != nil {
c_die("view", err)
}
- if err := data.s.Init(); err != nil {
+ if err := ui.s.Init(); err != nil {
c_die("view", err)
}
- def_style := tcell.StyleDefault.
+ ui.def_style = tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.ColorReset)
- data.s.SetStyle(def_style)
+ ui.bot_style = tcell.StyleDefault.
+ Background(tcell.ColorReset).
+ Foreground(tcell.ColorGrey)
+ ui.s.SetStyle(ui.def_style)
for {
- term_size[W], term_size[H], _ = term.GetSize(0)
- data.s.Clear()
- i_bottom_text(data.s, term_size)
- i_host_panel(data, term_size, def_style, sel, sel_max)
- i_info_panel(data.s, term_size, def_style, data.lhost, sel)
+ ui.dim[W], ui.dim[H], _ = term.GetSize(0)
+ ui.s.Clear()
+ i_bottom_text(*ui)
+ i_host_panel(data.ui, data.lhost)
+ i_info_panel(data.ui, data.lhost)
if data.lhost.head == nil {
- i_draw_zhosts_box(data.s, term_size, def_style)
+ i_draw_zhosts_box(*ui)
+ }
+ if ui.delete_mode == true {
+ host := data.lhost.sel(ui.sel)
+ // file_path := data.data_dir + "/" + host.Folder + host.Filename
+ text := "Do you really want to delete host " +
+ host.Folder + host.Filename + "?"
+ left, right :=
+ (ui.dim[W] / 2) - (len(text) / 2) - 5,
+ (ui.dim[W] / 2) + (len(text) / 2) + 5
+ top, bot :=
+ (ui.dim[H] / 2) - 3,
+ (ui.dim[H] / 2) + 3
+ i_draw_box(ui.s, left, top, right, bot, text)
+ // if err := os.Remove(file_path); err != nil {
+ // c_die("can't remove " + file_path, err)
+ // }
+ // i_reload_data(data, sel, sel_max)
}
- data.s.Show()
- i_events(data, &sel, &sel_max, &term_size)
- if int(sel) > data.list_start + term_size[H] - 4 {
- data.list_start = int(sel + 1) - term_size[H] + 3
- } else if int(sel) < data.list_start {
- data.list_start = int(sel)
+ ui.s.Show()
+ i_events(data)
+ if int(ui.sel) > ui.list_start + ui.dim[H] - 4 {
+ ui.list_start = int(ui.sel + 1) - ui.dim[H] + 3
+ } else if int(ui.sel) < ui.list_start {
+ ui.list_start = int(ui.sel)
}
}
}