Skip to content

Commit

Permalink
feat(movie): Remove margins on smaller terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Apr 18, 2024
1 parent 56a7c0a commit 0aabe52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/movie/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Player struct {
log *log.Entry
durationHook log_hooks.Duration
profile termenv.Profile
small bool

speed float64
playCtx context.Context
Expand Down Expand Up @@ -178,6 +179,8 @@ func (p Player) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !p.isPlaying() {
return p, p.play()
}
case tea.WindowSizeMsg:
p.small = msg.Width < p.movie.Width+10
}
return p, nil
}
Expand All @@ -187,13 +190,18 @@ func (p Player) View() string {
p.optionViewCache = p.OptionsView()
}

return appStyle.RenderWithProfile(p.profile, lipgloss.JoinVertical(
content := lipgloss.JoinVertical(
lipgloss.Center,
p.movie.screenStyle.RenderWithProfile(p.profile, p.movie.Frames[p.frame].Data),
progressStyle.RenderWithProfile(p.profile, p.movie.Frames[p.frame].Progress),
p.optionViewCache,
p.helpViewCache,
))
)

if p.small {
return smallAppStyle.RenderWithProfile(p.profile, content)
}
return appStyle.RenderWithProfile(p.profile, content)
}

func (p *Player) OptionsView() string {
Expand Down
2 changes: 2 additions & 0 deletions internal/movie/player_styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var (
appStyle = lipgloss.NewStyle().
Margin(2, 4)

smallAppStyle = lipgloss.NewStyle()

borderColor = lipgloss.AdaptiveColor{Light: "7", Dark: "8"}

screenStyle = lipgloss.NewStyle().
Expand Down

0 comments on commit 0aabe52

Please sign in to comment.