Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ go run widgets/segmentdisplay/segmentdisplaydemo/segmentdisplaydemo.go

[<img src="./doc/images/segmentdisplaydemo.gif" alt="segmentdisplaydemo" type="image/gif">](widgets/segmentdisplay/segmentdisplaydemo/segmentdisplaydemo.go)

## The TreeView
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge from the devel branch and resolve the conflict.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this require a new PR? keithknott26 wants to merge 3 commits into mum4k:devel I thought i was merging to devel


Displays a tree view which provides a hierarchical and collapsible view for displaying and interacting with nested data structures.
[treeviewdemo](widgets/treeview/treeviewdemo/treeviewdemo.go).

```go
go run widgets/treeview/treeviewdemo/treeviewdemo.go
```

[<img src="./doc/images/treeviewdemo.gif" alt="treeviewdemo" type="image/gif">](widgets/treeview/treeviewdemo/treeviewdemo.go)

## The Tab

Displays a tabbed view for displaying and interacting with multiple widgets. It also includes an optional feature to follow the notifications or alarms by navigating to the respective tab.
[tabdemo](widgets/tab/tabemo/tabdemo.go).

```go
go run widgets/tab/tabdemo/tabdemo.go
```

[<img src="./doc/images/tabdemo.gif" alt="tabdemo" type="image/gif">](widgets/tab/tabdemo/tabdemo.go)

# Contributing

If you are willing to contribute, improve the infrastructure or develop a
Expand Down Expand Up @@ -219,7 +241,7 @@ Termdash uses [this branching model](https://nvie.com/posts/a-successful-git-bra
- [perfstat](https://github.com/flaviostutz/perfstat): Analyze and show tips about possible bottlenecks in Linux systems.
- [gex](https://github.com/Tosch110/gex): Cosmos SDK explorer in-terminal.
- [ali](https://github.com/nakabonne/ali): ALI HTTP load testing tool with realtime analysis.

- [suimon](https://github.com/bartosian/suimon): SUI blockchain explorer and monitor.
# Disclaimer

This is not an official Google product.
Binary file added doc/images/tabdemo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions widgets/tab/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Package tab provides configuration options for the tabbed interface.
package tab

import "github.com/mum4k/termdash/cell"

// Option represents a configuration option for the Tab.
type Option interface {
// set applies the option to the provided Options struct.
set(*Options)
}

// Options holds the configuration for the Tab.
type Options struct {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to treeview and the other tabs - can we make all these fields private (starting with lowercase letter)? Or do they need to be part of the API? Looks like users can use the functions below to set them.

Tabs []*Tab // List of tabs.
LabelColor cell.Color // Color of the tab labels.
ActiveTabColor cell.Color // Background color of the active tab.
InactiveTabColor cell.Color // Background color of inactive tabs.
ActiveIcon string // Icon for active tabs.
InactiveIcon string // Icon for inactive tabs.
NotificationIcon string // Icon for tabs with notifications.
EnableLogging bool // Enables logging for debugging.
FollowNotifications bool // Whether to follow notifications automatically.
}

// NewOptions initializes default options or applies provided options.
func NewOptions(opts ...Option) *Options {
o := &Options{
Tabs: []*Tab{},
LabelColor: cell.ColorWhite,
ActiveTabColor: cell.ColorBlue,
InactiveTabColor: cell.ColorBlack,
ActiveIcon: "⦿",
InactiveIcon: "○",
NotificationIcon: "⚠",
EnableLogging: false,
FollowNotifications: false,
}
for _, opt := range opts {
opt.set(o)
}
return o
}

// option is a function that modifies Options.
type option func(*Options)

// set implements Option.set.
func (o option) set(opts *Options) {
o(opts)
}

// Tabs sets the root tabs of the Tab widget.
func Tabs(tabs ...*Tab) Option {
return option(func(o *Options) {
o.Tabs = tabs
})
}

// ActiveIcon sets custom icons for the active state.
func ActiveIcon(active string) Option {
return option(func(o *Options) {
o.ActiveIcon = active
})
}

// InactiveIcon sets custom icons for the inactive state.
func InactiveIcon(inactive string) Option {
return option(func(o *Options) {
o.InactiveIcon = inactive
})
}

// NotificationIcon sets custom icons for notifications.
func NotificationIcon(notification string) Option {
return option(func(o *Options) {
o.NotificationIcon = notification
})
}

// LabelColor sets the color of the tab labels.
func LabelColor(color cell.Color) Option {
return option(func(o *Options) {
o.LabelColor = color
})
}

// ActiveTabColor sets the background color of the active tab.
func ActiveTabColor(color cell.Color) Option {
return option(func(o *Options) {
o.ActiveTabColor = color
})
}

// InactiveTabColor sets the background color of inactive tabs.
func InactiveTabColor(color cell.Color) Option {
return option(func(o *Options) {
o.InactiveTabColor = color
})
}

// EnableLogging enables or disables logging for debugging.
func EnableLogging(enable bool) Option {
return option(func(o *Options) {
o.EnableLogging = enable
})
}

// FollowNotifications sets whether the app should follow notifications automatically.
func FollowNotifications(enable bool) Option {
return option(func(o *Options) {
o.FollowNotifications = enable
})
}
27 changes: 27 additions & 0 deletions widgets/tab/tab_content.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Package tab provides functionality for managing tabbed interfaces.
package tab

import (
"github.com/mum4k/termdash/container"
)

// Content displays the content of the active tab.
type Content struct {
tm *Manager // Reference to the Tab Manager.
}

// NewContent creates a new Content.
func NewContent(tm *Manager) *Content {
return &Content{
tm: tm,
}
}

// Update updates the content based on the active tab.
func (c *Content) Update(cont *container.Container) error {
activeTab := c.tm.GetActiveTab()
if activeTab == nil {
return nil
}
return cont.Update("tabContent", activeTab.Content)
}
Loading