Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaya-Sem committed Aug 17, 2024
1 parent 7fb8d29 commit 223db63
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
21 changes: 21 additions & 0 deletions cmd/tables/tableUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package table

import (
"fmt"
"github.com/charmbracelet/lipgloss"
"time"
)

Expand All @@ -12,6 +13,26 @@ const (
tableHeight = 10
)

var (
lowOccupancyStyle = lipgloss.NewStyle().Italic(true).Foreground(lipgloss.Color("2")) // green
mediumOccupancyStyle = lipgloss.NewStyle().Italic(true).Foreground(lipgloss.Color("214")) // orange
highOccupancyStyle = lipgloss.NewStyle().Italic(true).Foreground(lipgloss.Color("9")) // red
unknownOccupancyStyle = lipgloss.NewStyle().Italic(true).Faint(true).Italic(true)
)

func styleOccupancy(s string) string {
switch s {
case "low":
return lowOccupancyStyle.Render(s)
case "medium":
return mediumOccupancyStyle.Render(s)
case "high":
return highOccupancyStyle.Render(s)
default:
return unknownOccupancyStyle.Render(s)
}
}

// CalculateHumanRelativeTime used for calucating human-readable "from now" time. E.g 'in 20 minutes'
func CalculateHumanRelativeTime(departureTime string) string {
now := time.Now()
Expand Down
20 changes: 0 additions & 20 deletions cmd/tables/timetableTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,6 @@ import (
"github.com/charmbracelet/lipgloss"
)

var (
lowOccupancyStyle = lipgloss.NewStyle().Italic(true).Foreground(lipgloss.Color("2")) // green
mediumOccupancyStyle = lipgloss.NewStyle().Italic(true).Foreground(lipgloss.Color("214")) // orange
highOccupancyStyle = lipgloss.NewStyle().Italic(true).Foreground(lipgloss.Color("9")) // red
unknownOccupancyStyle = lipgloss.NewStyle().Italic(true).Faint(true).Italic(true)
)

func styleOccupancy(s string) string {
switch s {
case "low":
return lowOccupancyStyle.Render(s)
case "medium":
return mediumOccupancyStyle.Render(s)
case "high":
return highOccupancyStyle.Render(s)
default:
return unknownOccupancyStyle.Render(s)
}
}

type timetableTableModel struct {
table table.Model
selectedDetails string
Expand Down

0 comments on commit 223db63

Please sign in to comment.