11package main
22
33import (
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- }
13294func 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-
203106func 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", ¤tDir)
318-
319217 }
320-
321- // Execute fls initially to get inodes of the root directory.
322-
323218}
0 commit comments