diff options
author | Joe <rbo@gmx.us> | 2023-12-20 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2023-12-20 20:20:20 +0100 |
commit | 2e54711df0a7d064fd45fe1e10a5b8675b2ed459 (patch) | |
tree | fccb2fd1fd9857515a8ff35da6d3bf2d60d7962a | |
parent | fix (diff) | |
download | hardflip-2e54711df0a7d064fd45fe1e10a5b8675b2ed459.tar.gz hardflip-2e54711df0a7d064fd45fe1e10a5b8675b2ed459.tar.bz2 hardflip-2e54711df0a7d064fd45fe1e10a5b8675b2ed459.tar.xz hardflip-2e54711df0a7d064fd45fe1e10a5b8675b2ed459.tar.zst hardflip-2e54711df0a7d064fd45fe1e10a5b8675b2ed459.zip |
delete
-rw-r--r-- | c_hardflip.go | 5 | ||||
-rw-r--r-- | c_lhosts.go | 39 | ||||
-rw-r--r-- | i_events.go | 50 | ||||
-rw-r--r-- | i_ui.go | 5 |
4 files changed, 57 insertions, 42 deletions
diff --git a/c_hardflip.go b/c_hardflip.go index 27e8ef3..5ad9e8e 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -54,13 +54,16 @@ type Data struct { // dirs *DirList opts Opts s tcell.Screen + data_dir string } func main() { + data_dir := c_get_data_dir() data := Data{ - c_load_data_dir(c_get_data_dir()), + c_load_data_dir(data_dir), Opts{true, true}, nil, + data_dir, } i_ui(&data) } diff --git a/c_lhosts.go b/c_lhosts.go index 8cfeb37..ac5cfcd 100644 --- a/c_lhosts.go +++ b/c_lhosts.go @@ -94,23 +94,23 @@ func (lhost *HostList) add_back(node *HostNode) { curr.next = new_node } -// removes a host node from the list -func (lhost *HostList) del(id uint64) { - if lhost.head == nil { - return - } - if lhost.head.ID == id { - lhost.head = lhost.head.next - return - } - curr := lhost.head - for curr.next != nil && curr.next.ID != id { - curr = curr.next - } - if curr.next != nil { - curr.next = curr.next.next - } -} +// not used - removes a host node from the list +// func (lhost *HostList) del(id uint64) { +// if lhost.head == nil { +// return +// } +// if lhost.head.ID == id { +// lhost.head = lhost.head.next +// return +// } +// curr := lhost.head +// for curr.next != nil && curr.next.ID != id { +// curr = curr.next +// } +// if curr.next != nil { +// curr.next = curr.next.next +// } +// } // return the list node with the according id func (lhost *HostList) sel(id uint64) *HostNode { @@ -127,11 +127,10 @@ func (lhost *HostList) sel(id uint64) *HostNode { func (lhost *HostList) count() uint64 { curr := lhost.head - var count uint64 = 0 + var count uint64 - for curr != nil { + for count = 0; curr != nil; count++ { curr = curr.next - count++ } return count } diff --git a/i_events.go b/i_events.go index 28a40b5..524b612 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 11:05:16 2023 + * Wed Dec 20 12:19:56 2023 * Joe * * the hosts linked list @@ -47,16 +47,33 @@ package main -import( +import ( "os" "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) { + data.lhost = c_load_data_dir(data.data_dir) + l := data.lhost + *sel_max = l.count() + if *sel >= *sel_max { + *sel = *sel_max - 1 + } +} + // screen events such as keypresses func i_events(data *Data, - sel *uint64, sel_max *uint64, - term_size *[2]int, - quit func()) { + sel, sel_max *uint64, + term_size *[2]int) { var err error event := data.s.PollEvent() switch event := event.(type) { @@ -64,25 +81,29 @@ func i_events(data *Data, data.s.Sync() case *tcell.EventKey: if event.Key() == tcell.KeyEscape || - event.Key() == tcell.KeyCtrlC || - event.Rune() == 'q' { - quit() + event.Key() == tcell.KeyCtrlC || + event.Rune() == 'q' { + data.s.Fini() os.Exit(0) } if event.Rune() == 'j' || - event.Key() == tcell.KeyDown { + event.Key() == tcell.KeyDown { if *sel < *sel_max - 1 { *sel += 1 } } if event.Rune() == 'k' || - event.Key() == tcell.KeyUp { + event.Key() == tcell.KeyUp { if *sel > 0 { *sel -= 1 } } + if event.Rune() == 'D' { + i_delete_selected(data, sel) + i_reload_data(data, sel, sel_max) + } if event.Key() == tcell.KeyEnter { - quit() + data.s.Fini() c_exec(*sel, data.lhost) if data.opts.loop == false { os.Exit(0) @@ -99,12 +120,7 @@ func i_events(data *Data, 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 - } + i_reload_data(data, sel, sel_max) } } } @@ -370,9 +370,6 @@ func i_ui(data *Data) { Background(tcell.ColorReset). Foreground(tcell.ColorReset) data.s.SetStyle(def_style) - quit := func() { - data.s.Fini() - } for { term_size[W], term_size[H], _ = term.GetSize(0) data.s.Clear() @@ -383,6 +380,6 @@ func i_ui(data *Data) { i_draw_zhosts_box(data.s, term_size, def_style) } data.s.Show() - i_events(data, &sel, &sel_max, &term_size, quit) + i_events(data, &sel, &sel_max, &term_size) } } |