Skip to content

Commit a736a36

Browse files
committed
Initial breakup of main to refine codebase
1 parent 341f7e7 commit a736a36

5 files changed

Lines changed: 108 additions & 116 deletions

File tree

cache.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ import (
55
"strings"
66
)
77

8-
// Entry ... Interface for any object part of a file system."
9-
type Entry interface {
10-
addChild(newItem *Entry)
11-
hasChildren()
12-
sortChildrenByAlphaDescending()
13-
listChildren()
14-
populate(list string)
15-
navigate(child Item)
16-
childFromInode(itemType string, inode string)
17-
}
18-
198
// Item ... Basic struct for all items in file system.
209
type Item struct {
2110
Type string

cmdcontroller.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
)
8+
9+
//defines the information to be passed to the main view
10+
//handles underlying program execution
11+
12+
// execute new command
13+
func commandexecuter() {
14+
cmdstruct := exec.Command(cmd, args...)
15+
tooloutput := executer(cmdstruct)
16+
directory.populate(tooloutput)
17+
displayexecuter()
18+
}
19+
20+
//Alternative to commandexecuter() that hsould be called when a command is not required to be run.
21+
func displayexecuter() {
22+
fullcurrent = directory.listChildren()
23+
maxlines = newlineCounter(fullcurrent)
24+
current = windowString(windowheight, fullcurrent, selectedline)
25+
26+
//current = directory.listChildren()
27+
//maxlines = newlineCounter(current)
28+
}
29+
30+
func icatexecuter() {
31+
filename := nameMatcher(selectedstring)
32+
// execute new command
33+
cmdstruct := exec.Command(cmd, args...)
34+
// open the out file for writing
35+
writeCmdToFile(filename, cmdstruct)
36+
fmt.Print("\t\t Wrote " + filename)
37+
}
38+
39+
func istatexecuter() {
40+
filename := nameMatcher(selectedstring) + ".mft"
41+
// execute new command
42+
cmdstruct := exec.Command(cmd, args...)
43+
// open the out file for writing
44+
writeCmdToFile(filename, cmdstruct)
45+
fmt.Print("\t\t Wrote " + filename + "\n")
46+
}
47+
48+
// Executes a command on the host and prints the output as a string.
49+
func executer(cmdstruct *exec.Cmd) string {
50+
51+
// Define vars that will be used to store output and error of running the command.
52+
var (
53+
cmdOutput []byte
54+
cmdErr error
55+
)
56+
if cmdOutput, cmdErr = cmdstruct.Output(); cmdErr != nil {
57+
fmt.Fprintln(os.Stderr, cmdErr)
58+
os.Exit(1)
59+
}
60+
output := string(cmdOutput)
61+
if output == "" && cmd == "fls" {
62+
forceprint = "FLS did not output anything, try another method to investigate this directory. FLShell will quit in 3 seconds."
63+
enteredbaddir = true
64+
} else {
65+
forceprint = ""
66+
}
67+
return string(cmdOutput)
68+
}
69+
70+
// Updates the struct that is passed to exec.Output() to include the current directory inode.
71+
func argsupdater(arguments []string, inode string) []string {
72+
if len(arguments) < 4 {
73+
arguments = append(arguments, inode)
74+
// fmt.Println("args were less than 4. Appending inode value. ", args)
75+
}
76+
77+
arguments[3] = inode
78+
// fmt.Println("Updated args[3] with inode of:", inode)
79+
//Yuck, fix this.
80+
return arguments
81+
82+
}

flshell

0 Bytes
Binary file not shown.

main.go

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package main
22

33
import (
4-
"fmt"
54
"os"
6-
"os/exec"
7-
"strings"
85
"time"
96

107
"github.com/nsf/termbox-go"
@@ -94,41 +91,6 @@ func redrawAll() {
9491
termbox.Flush()
9592
}
9693

97-
// Executes a command on the host and prints the output as a string.
98-
func executer(cmdstruct *exec.Cmd) string {
99-
100-
// Define vars that will be used to store output and error of running the command.
101-
var (
102-
cmdOutput []byte
103-
cmdErr error
104-
)
105-
if cmdOutput, cmdErr = cmdstruct.Output(); cmdErr != nil {
106-
fmt.Fprintln(os.Stderr, cmdErr)
107-
os.Exit(1)
108-
}
109-
output := string(cmdOutput)
110-
if output == "" && cmd == "fls" {
111-
forceprint = "FLS did not output anything, try another method to investigate this directory. FLShell will quit in 3 seconds."
112-
enteredbaddir = true
113-
} else {
114-
forceprint = ""
115-
}
116-
return string(cmdOutput)
117-
}
118-
119-
// Updates the struct that is passed to exec.Output() to include the current directory inode.
120-
func argsupdater(arguments []string, inode string) []string {
121-
if len(arguments) < 4 {
122-
arguments = append(arguments, inode)
123-
// fmt.Println("args were less than 4. Appending inode value. ", args)
124-
}
125-
126-
arguments[3] = inode
127-
// fmt.Println("Updated args[3] with inode of:", inode)
128-
//Yuck, fix this.
129-
return arguments
130-
131-
}
13294
func goUp() {
13395
if dirlevel < 1 {
13496
dirlevel = 0
@@ -141,65 +103,6 @@ func goUp() {
141103

142104
}
143105

144-
// execute new command
145-
func commandexecuter() {
146-
cmdstruct := exec.Command(cmd, args...)
147-
tooloutput := executer(cmdstruct)
148-
directory.populate(tooloutput)
149-
displayexecuter()
150-
}
151-
152-
//Alternative to commandexecuter() that hsould be called when a command is not required to be run.
153-
func displayexecuter() {
154-
fullcurrent = directory.listChildren()
155-
maxlines = newlineCounter(fullcurrent)
156-
current = windowString(windowheight, fullcurrent, selectedline)
157-
158-
//current = directory.listChildren()
159-
//maxlines = newlineCounter(current)
160-
}
161-
162-
func windowString(height int, message string, selected int) string {
163-
//fmt.Printf("\t\t\tHeight: %v\tMaxlines: %v", height, maxlines)
164-
//take message and return a number of lines that equals window height.
165-
//return a specific x line section of those lines, provided an offset of lines into the string
166-
167-
//height is a value that starts at 1, ie 1 line minimum returns one.
168-
// selected starts at 0, need to compensate for this.
169-
selected++
170-
171-
lines := strings.Split(message, "\n")
172-
if height >= len(lines) {
173-
return message
174-
}
175-
if selected > height {
176-
scrollline = height
177-
return strings.Join(lines[selected-height:selected], "\n")
178-
} else {
179-
// writeStringToFile("lines.txt", strings.Join(lines, "\n"))
180-
return strings.Join(lines[0:height], "\n")
181-
}
182-
183-
}
184-
185-
func icatexecuter() {
186-
filename := nameMatcher(selectedstring)
187-
// execute new command
188-
cmdstruct := exec.Command(cmd, args...)
189-
// open the out file for writing
190-
writeCmdToFile(filename, cmdstruct)
191-
fmt.Print("\t\t Wrote " + filename)
192-
}
193-
194-
func istatexecuter() {
195-
filename := nameMatcher(selectedstring) + ".mft"
196-
// execute new command
197-
cmdstruct := exec.Command(cmd, args...)
198-
// open the out file for writing
199-
writeCmdToFile(filename, cmdstruct)
200-
fmt.Print("\t\t Wrote " + filename + "\n")
201-
}
202-
203106
func main() {
204107

205108
// Define a cmd struct that consists of the executable, it's location and the arguments passed.
@@ -241,8 +144,6 @@ mainloop:
241144
cmd = "fls"
242145
current = windowString(windowheight, fullcurrent, selectedline)
243146

244-
//displayexecuter() //move these out eventually, unnessarily slow.
245-
246147
case termbox.KeyArrowDown: // on Arrow Down
247148
moveSelectedLine(1, maxlines)
248149
cmd = "fls"
@@ -313,11 +214,5 @@ mainloop:
313214
firstrun = false
314215
redrawAll()
315216
_, windowheight = termbox.Size()
316-
317-
//fmt.Printf("current dir\t%+v\n", &currentDir)
318-
319217
}
320-
321-
// Execute fls initially to get inodes of the root directory.
322-
323218
}

viewcontroller.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import "strings"
4+
5+
func windowString(height int, message string, selected int) string {
6+
//fmt.Printf("\t\t\tHeight: %v\tMaxlines: %v", height, maxlines)
7+
//take message and return a number of lines that equals window height.
8+
//return a specific x line section of those lines, provided an offset of lines into the string
9+
10+
//height is a value that starts at 1, ie 1 line minimum returns one.
11+
// selected starts at 0, need to compensate for this.
12+
selected++
13+
14+
lines := strings.Split(message, "\n")
15+
if height >= len(lines) {
16+
return message
17+
}
18+
if selected > height {
19+
scrollline = height
20+
return strings.Join(lines[selected-height:selected], "\n")
21+
} else {
22+
// writeStringToFile("lines.txt", strings.Join(lines, "\n"))
23+
return strings.Join(lines[0:height], "\n")
24+
}
25+
26+
}

0 commit comments

Comments
 (0)