-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use channels to pass data to the debug tui #75
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
67b4698
Move data channel out of handler
eharris128 ee46254
Mark TODO
eharris128 47a9527
Add debug key bindings
eharris128 61a36f5
Add TUI flags
eharris128 8cc0de0
Add TUI flags to debug cli
eharris128 ad306bf
Add debug event
eharris128 8479396
Implement debug tui with channel based data flow
eharris128 43808e5
Open debug tui from home tui
eharris128 f23999b
Merge branch 'master' into data-channels
eharris128 4a796f9
Rm uused flags
eharris128 69ec407
Allow debug --tui invocation with no other flags
eharris128 893dd4d
Support use of debug --tui to render debuggable containers
eharris128 02b1a05
Fix spelling
eharris128 cd6600a
Change name from data -> subscription
eharris128 814610f
Improve comment and fix typo
eharris128 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,9 @@ import ( | |
) | ||
|
||
const ( | ||
ofJSON = "json" | ||
ofText = "text" | ||
ofJSON = "json" | ||
ofText = "text" | ||
ofSubscription = "subscription" | ||
) | ||
|
||
type ExecutionContext struct { | ||
|
@@ -122,20 +123,34 @@ func NewExecutionContext( | |
} | ||
|
||
type Output struct { | ||
CmdName string | ||
Quiet bool | ||
OutputFormat string | ||
DataChannels map[string]chan interface{} | ||
CmdName string | ||
Quiet bool | ||
OutputFormat string | ||
DataChannels map[string]chan interface{} | ||
internalDataCh chan interface{} | ||
} | ||
|
||
func NewOutput(cmdName string, quiet bool, outputFormat string, channels map[string]chan interface{}) *Output { | ||
ref := &Output{ | ||
CmdName: cmdName, | ||
Quiet: quiet, | ||
OutputFormat: outputFormat, | ||
DataChannels: channels, | ||
CmdName: cmdName, | ||
Quiet: quiet, | ||
OutputFormat: outputFormat, | ||
DataChannels: channels, | ||
internalDataCh: make(chan interface{}), | ||
} | ||
|
||
// We want to listen to the internal channel for any data | ||
// And dump it onto the appropriate DataChannels | ||
go func() { | ||
for data := range ref.internalDataCh { | ||
if data != nil { | ||
for _, ch := range ref.DataChannels { | ||
ch <- data | ||
} | ||
} | ||
} | ||
}() | ||
|
||
return ref | ||
} | ||
|
||
|
@@ -272,6 +287,15 @@ func (ref *Output) Message(data string) { | |
|
||
} | ||
|
||
func (ref *Output) Data(channelKey string, data interface{}) { | ||
if ch, exists := ref.DataChannels[channelKey]; exists { | ||
ch <- data // Send data to the corresponding channel | ||
fmt.Printf("Data sent to channel '%s': %v\n", channelKey, data) | ||
} else { | ||
fmt.Printf("Channel for channelKey '%s' not found\n", channelKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use logrus log instead of fmt.Printf There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted. Will update / remove. |
||
} | ||
} | ||
|
||
func (ref *Output) State(state string, params ...OutVars) { | ||
if ref.Quiet { | ||
return | ||
|
@@ -344,7 +368,8 @@ var ( | |
) | ||
|
||
func (ref *Output) Info(infoType string, params ...OutVars) { | ||
if ref.Quiet { | ||
// TODO - carry this pattern to other Output methods | ||
if ref.Quiet && ref.OutputFormat != ofSubscription { | ||
return | ||
} | ||
|
||
|
@@ -379,7 +404,8 @@ func (ref *Output) Info(infoType string, params ...OutVars) { | |
fmt.Println(string(jsonData)) | ||
case ofText: | ||
fmt.Printf("cmd=%s info=%s%s%s\n", ref.CmdName, itcolor(infoType), sep, data) | ||
|
||
case ofSubscription: | ||
ref.internalDataCh <- msg // Send data to the internal channel | ||
default: | ||
log.Fatalf("Unknown console output flag: %s\n. It should be either 'text' or 'json", ref.OutputFormat) | ||
} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use logrus log instead of fmt.Printf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. Will update / remove.