Skip to content

Commit

Permalink
Keep the poster theme consistent with the playback theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Mar 15, 2024
1 parent 420e7c8 commit ea189d2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/asciinema_web/controllers/recording/head_for_show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@
<meta name="robots" content="noindex, nofollow" />
<meta name="referrer" content="origin" />
<% end %>

<style :for={theme <- original_theme(@asciicast)}>
/* Keep the poster theme consistent with the playback theme */
div.ap-player {
--term-color-foreground: <%= theme.fg %>;
--term-color-background: <%= theme.bg %>;
<%= for {c, i} <- theme.palette do %>
--term-color-<%= i %>: <%= c %>;
<% end %>
}
</style>
10 changes: 10 additions & 0 deletions lib/asciinema_web/controllers/recording_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ defmodule AsciinemaWeb.RecordingHTML do
url(~p"/oembed?#{%{url: url(~p"/a/#{asciicast}"), format: format}}")
end

def original_theme(asciicast) do
case Media.original_theme(asciicast) do
nil ->
[]

theme ->
[%{fg: theme.fg, bg: theme.bg, palette: Enum.with_index(Tuple.to_list(theme.palette))}]
end
end

def duration(asciicast) do
if d = asciicast.duration do
d = round(d)
Expand Down
10 changes: 10 additions & 0 deletions lib/media.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ defmodule Asciinema.Media do
end
end

def original_theme(medium) do
case theme_name(medium) do
nil ->
Themes.custom_theme(medium.theme_fg, medium.theme_bg, medium.theme_palette)

_name ->
nil
end
end

def font_family(medium) do
case medium.terminal_font_family || Accounts.default_font_family(medium.user) do
"default" -> nil
Expand Down

0 comments on commit ea189d2

Please sign in to comment.