-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b848e12
commit 0781576
Showing
9 changed files
with
90 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,41 @@ | ||
package output | ||
|
||
import ( | ||
"fmt" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"golang.org/x/term" | ||
"os" | ||
"sync" | ||
) | ||
|
||
type TaskOutput interface { | ||
AddTask(name, message string) | ||
FailTask(name, message string) | ||
SucceedTask(name, message string) | ||
InfoTask(name, message string) | ||
InfoMessage(message string) | ||
Error(message string) | ||
Quit() | ||
Close() | ||
GetChildren(name string) TaskOutput | ||
} | ||
|
||
func NewTaskOutput() TaskOutput { | ||
if term.IsTerminal(int(os.Stdout.Fd())) { | ||
m := taskOutputBubbleTea{ | ||
lock: &sync.RWMutex{}, | ||
tasks: make(map[string]*task), | ||
queue: make(chan interface{}, 10), | ||
} | ||
p := tea.NewProgram(m) | ||
m.program = p | ||
go func() { | ||
_, e := p.Run() | ||
if e != nil { | ||
fmt.Println("Error: " + e.Error()) | ||
} | ||
}() | ||
return &m | ||
} else { | ||
return taskOutputNoTerm{} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package output | ||
|
||
import "fmt" | ||
|
||
type taskOutputNoTerm struct { | ||
} | ||
|
||
func (m taskOutputNoTerm) AddTask(name, message string) { | ||
fmt.Printf("[BUSY] %s: %s", name, message) | ||
} | ||
|
||
func (m taskOutputNoTerm) FailTask(name, message string) { | ||
fmt.Printf("[FAILED] %s: %s", name, message) | ||
} | ||
|
||
func (m taskOutputNoTerm) SucceedTask(name, message string) { | ||
fmt.Printf("[SUCCESS] %s: %s", name, message) | ||
} | ||
|
||
func (m taskOutputNoTerm) InfoTask(name, message string) { | ||
fmt.Printf("[INFO] %s: %s", name, message) | ||
} | ||
|
||
func (m taskOutputNoTerm) InfoMessage(message string) { | ||
fmt.Printf("[INFO] %s", message) | ||
} | ||
|
||
func (m taskOutputNoTerm) Error(message string) { | ||
fmt.Printf("[ERROR] %s", message) | ||
} | ||
|
||
func (m taskOutputNoTerm) Close() { | ||
} | ||
|
||
func (m taskOutputNoTerm) GetChildren(name string) TaskOutput { | ||
return &m | ||
} |