aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c_defs.go4
-rw-r--r--c_ldirs.go2
-rw-r--r--c_lhosts.go22
-rw-r--r--c_litems.go26
-rw-r--r--i_events.go33
-rw-r--r--i_ui.go51
6 files changed, 88 insertions, 50 deletions
diff --git a/c_defs.go b/c_defs.go
index 9e317e4..0396adc 100644
--- a/c_defs.go
+++ b/c_defs.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_defs.go
- * Mon Jan 08 12:20:53 2024
+ * Mon Jan 08 17:08:48 2024
* Joe
*
* constants
@@ -65,7 +65,7 @@ const (
[x](?) help`
DELETE_KEYS_HINTS = `
(q)uit -
-(y)yes -
+(y)es -
(n)o`
)
diff --git a/c_ldirs.go b/c_ldirs.go
index ee8977b..64c9a4e 100644
--- a/c_ldirs.go
+++ b/c_ldirs.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_ldirs.go
- * Thu 04 Jan 2024 11:50:52 AM CET
+ * Mon Jan 08 17:44:15 2024
* Joe
*
* the directories linked list
diff --git a/c_lhosts.go b/c_lhosts.go
index fde5881..791e885 100644
--- a/c_lhosts.go
+++ b/c_lhosts.go
@@ -96,30 +96,28 @@ func (lhost *HostList) add_back(node *HostNode) {
lhost.last = last.next
}
-func (lhost *HostList) reset_id() {
- curr := lhost.head
- for i := 0; curr != nil; i++ {
- curr.ID = i
- curr = curr.next
- }
-}
-
// removes a host node from the list
-func (lhost *HostList) del(id int) {
+func (lhost *HostList) del(host *HostNode) {
if lhost.head == nil {
return
}
- if lhost.head.ID == id {
+ if lhost.head == host {
lhost.head = lhost.head.next
+ for curr:= lhost.head; curr != nil; curr = curr.next {
+ curr.ID -= 1
+ }
return
}
curr := lhost.head
- for curr.next != nil && curr.next.ID != id {
+ for curr.next != nil && curr.next != host {
curr = curr.next
}
- if curr.next.ID == id {
+ if curr.next == host {
curr.next = curr.next.next
}
+ for curr := curr.next; curr != nil; curr = curr.next {
+ curr.ID -= 1
+ }
}
// return the list node with the according id
diff --git a/c_litems.go b/c_litems.go
index 0a1acf0..df20520 100644
--- a/c_litems.go
+++ b/c_litems.go
@@ -80,6 +80,32 @@ func (litems *ItemsList) add_back(node *ItemsNode) {
litems.last = last.next
}
+// removes an item node from the list and resets the ids
+func (litems *ItemsList) del(item *ItemsNode) {
+ if litems.head == nil {
+ return
+ }
+ if litems.head == item {
+ litems.head = litems.head.next
+ litems.head.prev = nil
+ for curr := litems.head; curr != nil; curr = curr.next {
+ curr.ID -= 1
+ }
+ return
+ }
+ curr := litems.head
+ for curr.next != nil && curr.next != item {
+ curr = curr.next
+ }
+ if curr.next == item {
+ curr.next = curr.next.next
+ curr.next.prev = curr
+ }
+ for curr := curr.next; curr != nil; curr = curr.next {
+ curr.ID -= 1
+ }
+}
+
// sets litems.curr to be used
func (litems *ItemsList) sel(id int) {
curr := litems.head
diff --git a/i_events.go b/i_events.go
index 3406088..3c67a7f 100644
--- a/i_events.go
+++ b/i_events.go
@@ -79,19 +79,26 @@ func i_reload_data(data *HardData) {
}
func i_delete_host(data *HardData) {
-// ui := &data.ui
-// host := data.lhost.sel(data.ui.sel)
-// file_path := data.data_dir + "/" + host.Folder + host.Filename
-//
-// if err := os.Remove(file_path); err != nil {
-// c_die("can't remove " + file_path, err)
-// }
-// data.lhost.del(data.ui.sel)
-// data.lhost.reset_id()
-// ui.sel_max = data.lhost.count()
-// if ui.sel >= ui.sel_max {
-// ui.sel = ui.sel_max - 1
-// }
+ curr := data.litems.curr
+ if curr.is_dir() == true {
+ return
+ }
+ host := curr.Host
+ file_path := data.data_dir + host.Parent.path() + host.Filename
+
+ if err := os.Remove(file_path); err != nil {
+ c_die("can't remove " + file_path, err)
+ }
+ host.Parent.lhost.del(host)
+ prev := data.litems.curr.prev
+ data.litems.del(curr)
+ if prev == nil {
+ prev = data.litems.head
+ }
+ data.litems.curr = prev
+ if data.litems.last != nil {
+ data.ui.sel_max = data.litems.last.ID
+ }
}
// screen events such as keypresses
diff --git a/i_ui.go b/i_ui.go
index 31adcd0..7cdc515 100644
--- a/i_ui.go
+++ b/i_ui.go
@@ -165,7 +165,7 @@ func i_draw_delete_box(ui HardUI, item *ItemsNode) {
}
host := item.Host
text := "Really delete this host?"
- file := host.Dir + host.Filename
+ file := host.Parent.path() + host.Filename
max_len := len(text)
if max_len < len(file) {
@@ -206,17 +206,20 @@ func i_draw_delete_box(ui HardUI, item *ItemsNode) {
}
top = ui.dim[H] / 2 + 1
i_draw_text(ui.s,
+ left - 1, top, right, top,
+ ui.def_style, "[")
+ i_draw_text(ui.s,
left, top, right, top,
ui.def_style.Bold(true).Underline(true), "y")
i_draw_text(ui.s,
left + 1, top, right, top,
- ui.def_style, "es | ")
+ ui.def_style, "es] [")
i_draw_text(ui.s,
left + 6, top, right, top,
ui.def_style.Bold(true).Underline(true), "n")
i_draw_text(ui.s,
left + 7, top, right, top,
- ui.def_style, "o")
+ ui.def_style, "o]")
}
func i_host_panel_dirs(ui HardUI, icons bool,
@@ -250,27 +253,30 @@ func i_host_panel_dirs(ui HardUI, icons bool,
}
func i_host_panel_host(ui HardUI, icons bool,
- depth uint16, host *HostNode, curr *HostNode, line int) {
+ depth uint16, host *HostNode, curr *HostNode, ptr *ItemsNode, line int) {
style := ui.def_style
if host == curr {
- style = style.Reverse(true)
- }
- text := ""
- for i := 0; i < int(depth) - 2; i++ {
- text += " "
- }
- if icons == true {
- text += HOST_ICONS[int(host.Protocol)]
- }
- text += host.Name
- spaces := ""
- for i := 0; i < (ui.dim[W] / 3) - len(text) + 1; i++ {
- spaces += " "
- }
- text += spaces
- i_draw_text(ui.s,
- 1, line, ui.dim[W] / 3, line,
- style, text)
+ style = style.Reverse(true)
+ }
+ text := ""
+ for i := 0; i < int(depth) - 2; i++ {
+ text += " "
+ }
+ if icons == true {
+ text += HOST_ICONS[int(host.Protocol)]
+ }
+ text += host.Name
+ spaces := ""
+ for i := 0; i < (ui.dim[W] / 3) - len(text) + 1; i++ {
+ spaces += " "
+ }
+ text += spaces
+ i_draw_text(ui.s,
+ 1, line, ui.dim[W] / 3, line,
+ style, text)
+ i_draw_text(ui.s,
+ 1, line, ui.dim[W] / 3, line,
+ style, strconv.Itoa(ptr.ID))
}
func i_host_panel(ui HardUI, icons bool, litems *ItemsList) {
@@ -286,6 +292,7 @@ func i_host_panel(ui HardUI, icons bool, litems *ItemsList) {
ptr.Host.Parent.Depth,
ptr.Host,
litems.curr.Host,
+ ptr,
line)
} else {
i_host_panel_dirs(ui, icons,