Skip to content

Commit

Permalink
fixed fatal crash issue
Browse files Browse the repository at this point in the history
  • Loading branch information
somnek committed May 27, 2023
1 parent 2a34932 commit aed2d68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
28 changes: 7 additions & 21 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,34 @@ func removeContainer(c *docker.Client, id string) {
ID: id,
Force: true,
}
if err := c.RemoveContainer(opts); err != nil {
log.Fatal(err)
}
_ = c.RemoveContainer(opts)
}

func restartContainer(c *docker.Client, id string) {
if err := c.RestartContainer(id, 5); err != nil {
log.Fatal(err)
}
_ = c.RestartContainer(id, 5)
}

func unPauseContainer(c *docker.Client, id string) {
if err := c.UnpauseContainer(id); err != nil {
log.Fatal(err)
}
_ = c.UnpauseContainer(id)
}

func pauseContainer(c *docker.Client, id string) {
if err := c.PauseContainer(id); err != nil {
log.Fatal(err)
}
_ = c.PauseContainer(id)
}

func killContainer(c *docker.Client, id string) {
opts := docker.KillContainerOptions{
ID: id,
}
if err := c.KillContainer(opts); err != nil {
log.Fatal(err)
}
_ = c.KillContainer(opts)
}

func startContainer(c *docker.Client, id string) {
if err := c.StartContainer(id, nil); err != nil {
log.Fatal(err)
}
_ = c.StartContainer(id, nil)
}

func stopContainer(c *docker.Client, id string) {
if err := c.StopContainer(id, 5); err != nil {
log.Fatal(err)
}
_ = c.StopContainer(id, 5)
}

func listContainers(c *docker.Client, showAll bool) []docker.APIContainers {
Expand Down
28 changes: 16 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (
var (
stateStyle = map[string]lipgloss.Style{
"created": lipgloss.NewStyle().Background(midPurple),
"running": lipgloss.NewStyle().Background(hotGreen),
"running": lipgloss.NewStyle().Background(green),
"paused": lipgloss.NewStyle().Background(yellow),
"restarting": lipgloss.NewStyle().Background(orange),
"exited": lipgloss.NewStyle().Background(midPink),
Expand All @@ -65,7 +65,7 @@ var (
MarginLeft(5)

titleStyle = lipgloss.NewStyle().
Background(celesBlue).
Background(orange).
Foreground(black).Bold(true).
Align(lipgloss.Center).
Blink(true)
Expand Down Expand Up @@ -238,8 +238,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
state := container.state
id := container.id
if state == "exited" || state == "created" {
startContainer(client, id)
m.logs += "🚀 Started " + container.name + "\n"
go startContainer(client, id)
if err != nil {
m.logs += fmt.Sprintf("🚧 %s\n", err.Error())
} else {
m.logs += "🚀 Started " + container.name + "\n"
}
} else {
m.logs += "🚧 " + container.name + " already running\n"
}
Expand Down Expand Up @@ -369,14 +373,14 @@ func (m model) View() string {
}
} else if m.page == 1 {
controls := `
x - remove container
r - restart container
K - kill container
s - stop container
u - start container
p - pause container
P - unpause container
esc - clear selection
x - remove
r - restart
K - kill
s - stop
u - start
p - pause
P - unpause
esc - clear
? - hide controls`
s += controls + "\n"

Expand Down

0 comments on commit aed2d68

Please sign in to comment.