-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: localize asciinema recordings, use custom asciinema theme (#932)
- Loading branch information
Showing
13 changed files
with
671 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
./client/node_modules | ||
./server/dist | ||
./server/programs | ||
./server/tmp | ||
./client/node_modules/ | ||
./server/dist/ | ||
./server/programs/ | ||
./server/tmp/ |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,33 @@ | ||
/* Dark theme */ | ||
.asciinema-player-theme-sparkle { | ||
--term-color-foreground: #ffffff; | ||
--term-color-background: #1a202c; | ||
|
||
--term-color-0: #ffffff; | ||
--term-color-1: #f56565; | ||
--term-color-2: #9ae6b4; | ||
--term-color-3: #f6e05e; | ||
--term-color-4: #63b3ed; | ||
--term-color-5: #b794f4; | ||
--term-color-6: #76e4f7; | ||
--term-color-7: #171923; | ||
} | ||
|
||
/* Light theme */ | ||
.asciinema-player-theme-glitter { | ||
/* Foreground (default text) color */ | ||
--term-color-foreground: #1a202c; | ||
|
||
/* Background color */ | ||
--term-color-background: #ffffff; | ||
|
||
/* Palette of 16 standard ANSI colors */ | ||
--term-color-0: #171923; | ||
--term-color-1: #f56565; | ||
--term-color-2: #9ae6b4; | ||
--term-color-3: #f6e05e; | ||
--term-color-4: #63b3ed; | ||
--term-color-5: #b794f4; | ||
--term-color-6: #76e4f7; | ||
--term-color-7: #ffffff; | ||
} |
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 |
---|---|---|
@@ -1,30 +1,49 @@ | ||
import { FC } from 'react' | ||
import React, { useEffect, useRef, useState } from 'react' | ||
import 'asciinema-player/dist/bundle/asciinema-player.css' | ||
import '../../public/styles/asciicast.css' | ||
|
||
const AsciinemaFrame: FC<{ | ||
id: string | ||
autoplay?: boolean | ||
loop?: boolean | ||
dark?: boolean | ||
}> = ({ id, autoplay, loop, dark }) => ( | ||
<iframe | ||
src={`https://asciinema.org/a/${id}/iframe?theme=${dark ? 'solarized-light' : 'monokai'}&autoplay=${ | ||
autoplay ? 1 : 0 | ||
}&loop=${loop ? 1 : 0}&speed=0.75`} | ||
id={`asciicast-iframe-${id}`} | ||
name={`asciicast-iframe-${id}`} | ||
scrolling='no' | ||
data-allowfullscreen='true' | ||
style={{ | ||
overflow: 'hidden', | ||
margin: '0px', | ||
border: '0px', | ||
display: 'inline-block', | ||
width: '100%', | ||
float: 'none', | ||
visibility: 'visible', | ||
aspectRatio: '16 / 9', | ||
}} | ||
></iframe> | ||
) | ||
type AsciinemaPlayerProps = { | ||
src: string | ||
// START asciinemaOptions | ||
cols?: string | ||
rows?: string | ||
controls?: boolean | string | ||
autoPlay?: boolean | ||
preload?: boolean | ||
loop?: boolean | number | ||
startAt?: number | string | ||
speed?: number | ||
idleTimeLimit?: number | ||
theme?: string | ||
poster?: string | ||
fit?: string | ||
terminalfontSize?: string | ||
terminalFontFamily?: string | ||
// END asciinemaOptions | ||
} | ||
|
||
function AsciinemaFrame({ | ||
src, | ||
speed = 0.75, | ||
controls = false, | ||
...asciinemaOptions | ||
}: AsciinemaPlayerProps) { | ||
const ref = useRef<HTMLDivElement>(null) | ||
const [player, setPlayer] = useState<typeof import('asciinema-player')>() | ||
useEffect(() => { | ||
import('asciinema-player').then(p => { | ||
setPlayer(p) | ||
}) | ||
}, []) | ||
useEffect(() => { | ||
const currentRef = ref.current | ||
const instance = player?.create(src, currentRef, asciinemaOptions) | ||
return () => { | ||
instance?.dispose() | ||
} | ||
}, [src, player, asciinemaOptions]) | ||
|
||
return <div ref={ref} /> | ||
} | ||
|
||
export default AsciinemaFrame |
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,23 @@ | ||
declare module 'asciinema-player' { | ||
export function create( | ||
src: string, | ||
element: HTMLElement | null, | ||
// START asciinemaOptions | ||
opts: { | ||
cols?: string | ||
rows?: string | ||
controls?: boolean | string | ||
autoPlay?: boolean | ||
preload?: boolean | ||
loop?: boolean | number | ||
startAt?: number | string | ||
speed?: number | ||
idleTimeLimit?: number | ||
theme?: string | ||
poster?: string | ||
fit?: string | ||
terminalfontSize?: string | ||
terminalFontFamily?: string | ||
}, | ||
) | ||
} |
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
File renamed without changes.