From 151360d5e7dd40745f7dfb8548bca3585845d2b8 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Fri, 26 Jan 2024 16:49:00 +0100 Subject: [PATCH] feat: basic nvim setup and other partially working stuff --- src/components/MusicPlayer.tsx | 10 ++++---- src/components/Nvim/Nvim.tsx | 19 ++++++++++++++ src/components/Nvim/NvimStatusBar.tsx | 12 +++++++++ src/components/Nvim/NvimTree.tsx | 11 ++++++++ src/components/Terminal.tsx | 2 ++ src/components/terminal/TerminalBox.tsx | 22 ++++++++++++++++ src/components/terminal/TerminalCell.tsx | 21 ++++++++++++++++ src/components/terminal/TerminalSubCanvas.tsx | 25 +++++++++++++++++++ src/pages/index.tsx | 5 +++- 9 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 src/components/Nvim/Nvim.tsx create mode 100644 src/components/Nvim/NvimStatusBar.tsx create mode 100644 src/components/Nvim/NvimTree.tsx create mode 100644 src/components/terminal/TerminalBox.tsx create mode 100644 src/components/terminal/TerminalCell.tsx create mode 100644 src/components/terminal/TerminalSubCanvas.tsx diff --git a/src/components/MusicPlayer.tsx b/src/components/MusicPlayer.tsx index 5ab913a..b14f132 100644 --- a/src/components/MusicPlayer.tsx +++ b/src/components/MusicPlayer.tsx @@ -39,7 +39,7 @@ export const MusicPlayer = (props: { }, 1000); return () => clearInterval(interval); - }, [setPlayed]); + }, [setPlayed, props.duration]); canvas.writeElement( new TerminalBoxElement(canvas.width, canvas.height), @@ -55,7 +55,7 @@ export const MusicPlayer = (props: { // Title and Artist inner.write(2, 0, `${props.title} ยท ${props.artist}`, { foreground: theme.cyan, - fontWeight: 800, + fontWeight: 700, }); inner.apply(0, 0, { char: "\udb81\udc0a", @@ -69,16 +69,16 @@ export const MusicPlayer = (props: { // Bar inner.write(0, 2, " ".repeat(inner.width), { foreground: theme.green, - background: theme.black, + background: "#55576d", }); inner.write(0, 2, " ".repeat((inner.width * played) / props.duration), { - foreground: theme.black, + foreground: "#55576d", background: theme.green, }); const time = `${formatDurationMSS(played)}/${formatDurationMSS( props.duration, )}`; - inner.write(inner.width / 2 - time.length / 2, 2, time); + inner.write(inner.width / 2 - time.length / 2, 2, time, { fontWeight: 800 }); canvas.writeElement(inner, 1, 1); return

{canvas.render()}

; diff --git a/src/components/Nvim/Nvim.tsx b/src/components/Nvim/Nvim.tsx new file mode 100644 index 0000000..dcbc2a0 --- /dev/null +++ b/src/components/Nvim/Nvim.tsx @@ -0,0 +1,19 @@ +import { NvimStatusBar } from "./NvimStatusBar"; +import { NvimTree } from "./NvimTree"; + +export const Nvim = () => { + return ( +
+
+
+ +
+
+
+ +
+ +
+
+ ); +}; diff --git a/src/components/Nvim/NvimStatusBar.tsx b/src/components/Nvim/NvimStatusBar.tsx new file mode 100644 index 0000000..138d698 --- /dev/null +++ b/src/components/Nvim/NvimStatusBar.tsx @@ -0,0 +1,12 @@ +import { useTerminal } from "~/context/TerminalContext"; +import { TerminalRenderer } from "~/utils/terminal/renderer"; + +export const NvimStatusBar = () => { + const { cols: width } = useTerminal(); + const canvas = new TerminalRenderer(width, 2); + + canvas.write(0, 0, "status line 1"); + canvas.write(0, 1, "status line 2"); + + return

{canvas.render()}

; +}; diff --git a/src/components/Nvim/NvimTree.tsx b/src/components/Nvim/NvimTree.tsx new file mode 100644 index 0000000..76681a7 --- /dev/null +++ b/src/components/Nvim/NvimTree.tsx @@ -0,0 +1,11 @@ +import { useTerminal } from "~/context/TerminalContext"; +import { TerminalRenderer } from "~/utils/terminal/renderer"; + +export const NvimTree = () => { + const { cols: width, rows: height } = useTerminal(); + const canvas = new TerminalRenderer(width * 0.15, height - 2); + + canvas.write(0, 0, "ijirjginrgi"); + + return

{canvas.render()}

; +}; diff --git a/src/components/Terminal.tsx b/src/components/Terminal.tsx index 2085016..17d18d8 100644 --- a/src/components/Terminal.tsx +++ b/src/components/Terminal.tsx @@ -38,6 +38,8 @@ export const Terminal = (props: { calculateSize(); + setTimeout(() => calculateSize(), 1); + window.addEventListener("resize", calculateSize); return () => { diff --git a/src/components/terminal/TerminalBox.tsx b/src/components/terminal/TerminalBox.tsx new file mode 100644 index 0000000..238d628 --- /dev/null +++ b/src/components/terminal/TerminalBox.tsx @@ -0,0 +1,22 @@ +import { useTerminalCanvas } from "~/context/TerminalCanvasContext"; +import { type CellStyle } from "~/utils/terminal/cell"; +import { TerminalBoxElement } from "~/utils/terminal/elements/box"; + +export const TerminalBox = (props: { + x: number; + y: number; + width: number; + height: number; + style?: CellStyle; +}) => { + const canvas = useTerminalCanvas(); + + const element = new TerminalBoxElement( + props.width, + props.height, + props.style ?? {}, + ); + canvas.writeElement(element, props.x, props.y); + + return null; +}; diff --git a/src/components/terminal/TerminalCell.tsx b/src/components/terminal/TerminalCell.tsx new file mode 100644 index 0000000..b13a6ee --- /dev/null +++ b/src/components/terminal/TerminalCell.tsx @@ -0,0 +1,21 @@ +import { useTerminalCanvas } from "~/context/TerminalCanvasContext"; +import { type CellStyle } from "~/utils/terminal/cell"; + +export const TerminalCell = (props: { + x: number; + y: number; + children: Array | string; + style?: CellStyle; +}) => { + const canvas = useTerminalCanvas(); + + const text = Array.isArray(props.children) + ? props.children.join("") + : props.children; + canvas.apply(props.x, props.y, { + char: text, + ...(props.style ?? {}), + }); + + return null; +}; diff --git a/src/components/terminal/TerminalSubCanvas.tsx b/src/components/terminal/TerminalSubCanvas.tsx new file mode 100644 index 0000000..87ebdae --- /dev/null +++ b/src/components/terminal/TerminalSubCanvas.tsx @@ -0,0 +1,25 @@ +import React, { type ReactNode, useState } from "react"; +import { + TerminalCanvasContextProvider, + useTerminalCanvas, +} from "~/context/TerminalCanvasContext"; +import { TerminalRenderer } from "~/utils/terminal/renderer"; + +export const TerminalSubCanvas = (props: { + x: number; + y: number; + width: number; + height: number; + children?: Array | ReactNode; +}) => { + const parent = useTerminalCanvas(); + const [canvas] = useState(new TerminalRenderer(props.width, props.height)); + + parent.writeElement(canvas, props.x, props.y); + + return ( + + {props.children} + + ); +}; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 61e81a6..61e36a0 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -2,6 +2,7 @@ import Head from "next/head"; import { Terminal } from "~/components/Terminal"; import { MusicVisualizer } from "~/components/MusicVisualizer"; import { MusicPlayer } from "~/components/MusicPlayer"; +import { Nvim } from "~/components/Nvim/Nvim"; export default function Home() { return ( @@ -16,7 +17,9 @@ export default function Home() { > - nvim + + +