-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
107 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package models | ||
|
||
import ( | ||
"dockerniceui/utils" | ||
"fmt" | ||
|
||
"github.com/charmbracelet/bubbles/viewport" | ||
"github.com/charmbracelet/glamour" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/docker/docker/api/types/volume" | ||
) | ||
|
||
func NewVolumeDetail(volume *volume.Volume, createTable utils.CreateTableFunc) (viewport.Model, error) { | ||
content := getContentVolume(volume) | ||
const width = 120 | ||
|
||
vp := viewport.New(width, 30) | ||
vp.Style = lipgloss.NewStyle(). | ||
BorderStyle(lipgloss.RoundedBorder()). | ||
BorderForeground(lipgloss.Color("62")). | ||
PaddingRight(2) | ||
|
||
renderer, err := glamour.NewTermRenderer( | ||
glamour.WithAutoStyle(), | ||
glamour.WithWordWrap(width), | ||
) | ||
if err != nil { | ||
return viewport.Model{}, err | ||
} | ||
|
||
str, err := renderer.Render(content) | ||
if err != nil { | ||
return viewport.Model{}, err | ||
} | ||
|
||
vp.SetContent(str) | ||
|
||
return vp, nil | ||
} | ||
|
||
func getContentVolume(volume *volume.Volume) string { | ||
// content := ` | ||
// # Volume detail | ||
|
||
// | Type | Value | | ||
// | ---- | ----- | | ||
// | ID | 1234567890 | | ||
// | Created | my-network | | ||
// | Mount path | bridge | | ||
// | Driver | local | | ||
// | Labels | false | ||
|
||
// # Containers using this volume | ||
|
||
// | Name | Mounted at | Read -only | ||
// | -- | ---- | ------------ | ------------ | | ||
// | 1234567890 | my-container | | ||
// | 1234567890 | my-container | | ||
|
||
//` | ||
response := "" | ||
response += utils.CreateTable("# Volume detail", []string{"Type", "Value"}, | ||
[][]string{ | ||
{"ID", volume.Name}, | ||
{"Created", volume.CreatedAt}, | ||
{"Mount path", volume.Mountpoint}, | ||
{"Driver", volume.Driver}, | ||
{"Labels", fmt.Sprintf("%v", volume.Labels)}, | ||
}) | ||
|
||
return response | ||
} |
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