11package main
22
33import (
4- "bufio"
54 "fmt"
65 "log"
76 "os/exec"
@@ -17,21 +16,21 @@ func Render(content *ParsedContent) {
1716 log .Fatalf ("failed to initialize termui: %v" , err )
1817 }
1918
20- content .content = replaceTabs (content .content )
19+ content .Content = replaceTabs (content .Content )
2120 termWidth , termHeight := ui .TerminalDimensions ()
2221
23- target := NewTarget (0 , len (content .rules ), content .rules )
24- target .Rows = getTargets (content .rules )
22+ target := NewTarget (0 , len (content .Rules ), content .Rules )
23+ target .Rows = getTargets (content .Rules )
2524
2625 highlighter := NewHighlighter ("vim" )
2726
2827 dependencyWidget := widgets .NewParagraph ()
2928 dependencyWidget .Title = "Dependencies"
30- dependencyWidget .Text = getDependency (content .rules , target .Index )
29+ dependencyWidget .Text = getDependency (content .Rules , target .Index )
3130
3231 contentWidget := widgets .NewParagraph ()
33- contentWidget .Title = content .filePath
34- contentWidget .Text = getContent (content .content , highlighter , content .rules , termHeight , target .Index )
32+ contentWidget .Title = content .FilePath
33+ contentWidget .Text = getContent (content .Content , highlighter , content .Rules , termHeight , target .Index )
3534
3635 grid := ui .NewGrid ()
3736 grid .SetRect (0 , 0 , termWidth , termHeight )
@@ -114,25 +113,14 @@ func Render(content *ParsedContent) {
114113 ui .Clear ()
115114 }
116115 target .Index = target .SelectedRow
117- dependencyWidget .Text = getDependency (content .rules , target .Index )
118- contentWidget .Text = getContent (content .content , highlighter , content .rules , termHeight , target .Index )
116+ dependencyWidget .Text = getDependency (content .Rules , target .Index )
117+ contentWidget .Text = getContent (content .Content , highlighter , content .Rules , termHeight , target .Index )
119118 ui .Render (grid )
120119 }
121-
122120 ui .Close ()
123- targetName := target .GetName ()
124- if run && targetName != "" {
125- cmd := exec .Command ("make" , "-f" + content .filePath , targetName )
126- stdout , _ := cmd .StdoutPipe ()
127- Check (cmd .Start )
128-
129- scanner := bufio .NewScanner (stdout )
130- scanner .Split (bufio .ScanLines )
131- for scanner .Scan () {
132- m := scanner .Text ()
133- fmt .Println (m )
134- }
135- Check (cmd .Wait )
121+
122+ if run {
123+ runTarget (target .GetName (), content .FilePath )
136124 }
137125}
138126
@@ -184,3 +172,13 @@ func replaceTabs(content []string) []string {
184172func isLetter (s string ) bool {
185173 return s [0 ] != '<' && s [len (s )- 1 ] != '>'
186174}
175+
176+ func runTarget (target , filePath string ) {
177+ if target != "" {
178+ // Compose command
179+ cmd := exec .Command ("make" , "-f" + filePath , target )
180+ // CombinedOutput will return both standard output and standard error
181+ stdoutStderr , _ := cmd .CombinedOutput ()
182+ fmt .Print (string (stdoutStderr ))
183+ }
184+ }
0 commit comments