6
6
"fmt"
7
7
"github.com/kardianos/osext"
8
8
"github.com/mattn/go-shellwords"
9
+ "github.com/tj/go-spin"
9
10
"io"
10
11
"io/ioutil"
11
12
"os"
@@ -46,6 +47,12 @@ func PrintlnVerbose(a ...interface{}) {
46
47
}
47
48
}
48
49
50
+ func PrintVerbose (a ... interface {}) {
51
+ if * verbose {
52
+ fmt .Print (a ... )
53
+ }
54
+ }
55
+
49
56
func main_load () {
50
57
51
58
if * dfu_path == "" {
@@ -198,12 +205,8 @@ func main_load() {
198
205
executablePath , _ := osext .ExecutableFolder ()
199
206
firmwarePath := executablePath + "/firmwares/" + * core + "/"
200
207
201
- // Save verbose flag
202
- verbose_user := * verbose
203
-
204
208
if needUpdateBLE || * force == true {
205
209
206
- * verbose = true
207
210
// flash current BLE firmware to partition 8
208
211
dfu_ble_flash_command := []string {dfu , dfu_flags , "-D" , firmwarePath + ble_firmware , "--alt" , "8" }
209
212
@@ -219,7 +222,6 @@ func main_load() {
219
222
220
223
if needUpdateRTOS || * force == true {
221
224
222
- * verbose = true
223
225
// flash current RTOS firmware to partition 2
224
226
dfu_rtos_flash_command := []string {dfu , dfu_flags , "-D" , firmwarePath + rtos_firmware , "--alt" , "2" }
225
227
@@ -233,9 +235,6 @@ func main_load() {
233
235
}
234
236
}
235
237
236
- // Restore verbose flag
237
- * verbose = verbose_user
238
-
239
238
// Finally flash the sketch
240
239
241
240
if * bin_file_name == "" {
@@ -373,24 +372,42 @@ func launchCommandAndWaitForOutput(command []string, stringToSearch string, prin
373
372
tellCommandNotToSpawnShell (oscmd )
374
373
stdout , _ := oscmd .StdoutPipe ()
375
374
stderr , _ := oscmd .StderrPipe ()
376
- multi := io .MultiReader (stderr , stdout )
375
+ multi := io .MultiReader (stdout , stderr )
376
+
377
+ s := spin .New ()
378
+ s .Set (spin .Spin1 )
379
+ showSpinner := false
380
+
381
+ if print_output {
382
+ if * verbose {
383
+ oscmd .Stdout = os .Stdout
384
+ oscmd .Stderr = os .Stderr
385
+ } else {
386
+ showSpinner = true
387
+ }
388
+ }
377
389
err := oscmd .Start ()
378
390
in := bufio .NewScanner (multi )
379
- in .Split (bufio .ScanLines )
391
+ in .Split (bufio .ScanRunes )
380
392
found := false
381
393
out := ""
382
394
for in .Scan () {
383
- if print_output {
384
- PrintlnVerbose (in .Text ())
395
+
396
+ if showSpinner {
397
+ fmt .Printf ("\r %s" , s .Next ())
385
398
}
386
- out += in .Text () + "\n "
399
+
400
+ out += in .Text ()
387
401
if stringToSearch != "" {
388
- if strings .Contains (in . Text () , stringToSearch ) {
402
+ if strings .Contains (out , stringToSearch ) {
389
403
found = true
390
404
}
391
405
}
392
406
}
393
407
err = oscmd .Wait ()
408
+ if showSpinner {
409
+ fmt .Println ("" )
410
+ }
394
411
return err , found , out
395
412
}
396
413
0 commit comments