diff options
Diffstat (limited to '')
| -rw-r--r-- | c_hardflip.go | 10 | ||||
| -rw-r--r-- | c_init.go | 31 | ||||
| -rw-r--r-- | c_litems.go | 75 | ||||
| -rw-r--r-- | i_events.go | 2 | ||||
| -rw-r--r-- | i_ui.go | 9 | 
5 files changed, 108 insertions, 19 deletions
| diff --git a/c_hardflip.go b/c_hardflip.go index f0c663f..8155af0 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -47,8 +47,11 @@  package main +import "fmt" +  // the main data structure, holds up everything important  type HardData struct { +	litems *ItemsList  	ldirs *DirsList  	ui    HardUI  	opts  HardOpts @@ -58,8 +61,9 @@ type HardData struct {  func main() {  	data_dir := c_get_data_dir()  	opts := HardOpts{true, true, false} -	ldirs := c_load_data_dir(data_dir, opts) +	litems, ldirs := c_load_data_dir(data_dir, opts)  	data := HardData{ +		litems,  		ldirs,  		HardUI{},  		opts, @@ -79,5 +83,7 @@ func main() {  	//     }  	//     dir = dir.next  	// } -	i_ui(&data) +	return +	fmt.Println(data) +	// i_ui(&data)  } @@ -60,7 +60,8 @@ type HardOpts struct {  // this function recurses into the specified root directory in order to load  // every yaml file into memory -func c_recurse_data_dir(dir, root string, opts HardOpts, ldirs *DirsList, +func c_recurse_data_dir(dir, root string, opts HardOpts, +		litems *ItemsList, ldirs *DirsList,  		id *uint64, name string, parent *DirsNode, depth uint16) {  	files, err := os.ReadDir(root + dir)  	if err != nil { @@ -75,30 +76,38 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, ldirs *DirsList,  		opts.FoldAll,  		nil,  	} +	item_node := ItemsNode{} +	item_node.Dirs = &dir_node +	item_node.Host = nil  	*id++  	ldirs.add_back(&dir_node) +	litems.add_back(&item_node)  	for _, file := range files {  		filename := file.Name()  		if file.IsDir() == true { -			c_recurse_data_dir(dir + filename + "/", root, opts, ldirs, +			c_recurse_data_dir(dir + filename + "/", root, opts, litems, ldirs,  				id, file.Name(), &dir_node, depth + 1)  		} else if filepath.Ext(filename) == ".yml" { -			host := c_read_yaml_file(root + dir + filename) -			if host == nil { +			host_node := c_read_yaml_file(root + dir + filename) +			if host_node == nil {  				return  			} -			host.Filename = filename -			host.Dir = &dir_node -			dir_node.lhost.add_back(host) +			item_node := ItemsNode{} +			item_node.Dirs = nil +			item_node.Host = host_node +			host_node.Filename = filename +			host_node.Dir = &dir_node +			dir_node.lhost.add_back(host_node)  		}  	}  } -func c_load_data_dir(dir string, opts HardOpts) *DirsList { -	ldirs := DirsList{} +func c_load_data_dir(dir string, opts HardOpts) (*ItemsList, *DirsList) { +	litems := ItemsList{} +	ldirs  := DirsList{}  	var id uint64  	id = 0 -	c_recurse_data_dir("", dir + "/", opts, &ldirs, &id, "", nil, 1) -	return &ldirs +	c_recurse_data_dir("", dir + "/", opts, &litems, &ldirs, &id, "", nil, 1) +	return &litems, &ldirs  } diff --git a/c_litems.go b/c_litems.go new file mode 100644 index 0000000..e607d19 --- /dev/null +++ b/c_litems.go @@ -0,0 +1,75 @@ +/* + * ======================== + * =====    =============== + * ======  ================ + * ======  ================ + * ======  ====   ====   == + * ======  ===     ==  =  = + * ======  ===  =  ==     = + * =  ===  ===  =  ==  ==== + * =  ===  ===  =  ==  =  = + * ==     =====   ====   == + * ======================== + * + * 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/c_litems.go + * Wed Dec 27 18:55:37 2023 + * Joe + * + * the dir and hosts linked list + */ + +package main + +type ItemsNode struct { +	ID   int +	Dirs *DirsNode +	Host *HostNode +	next *ItemsNode +} + +type ItemsList struct { +	head *ItemsNode +} + +func (litems *ItemsList) add_back(node *ItemsNode) { +	new_node := node + +	if litems.head == nil { +		litems.head = new_node +		return +	} +	curr := litems.head +	for curr.next != nil { +		curr = curr.next +	} +	new_node.ID = curr.ID + 1 +	curr.next = new_node +} + diff --git a/i_events.go b/i_events.go index 7937f7e..2199667 100644 --- a/i_events.go +++ b/i_events.go @@ -53,7 +53,7 @@ import (  )  func i_reload_data(data *HardData) { -	data.ldirs = c_load_data_dir(data.data_dir, data.opts) +	data.litems, data.ldirs = c_load_data_dir(data.data_dir, data.opts)  	data.ui.sel_max,  	data.ui.count_dirs,  	data.ui.count_hosts = i_get_sel_max(data.ldirs) @@ -39,7 +39,7 @@   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   *   * hardflip: src/i_ui.go - * Wed Dec 27 16:41:52 2023 + * Wed Dec 27 18:19:37 2023   * Joe   *   * interfacing with the user @@ -65,18 +65,17 @@ type HardUI struct {  	dir_style   tcell.Style  	title_style tcell.Style  	dim         [2]int -	sel			HardSelect +	sel			HardSelector  } -type HardSelect struct { +type HardSelector struct {  	line     int  	dirs_ptr *DirsNode  	host_ptr *HostNode  }  func (ui *HardUI) inc_sel(n int) { -	sel := &ui.sel -	sel.line += n +	ui.sel.line += n  }  func i_draw_text(s tcell.Screen, | 
