Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
build
docs
node_modules

/.idea/
.DS_Store
.aider*

21 changes: 14 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React, { useState, useEffect, useRef, KeyboardEvent, ChangeEvent, ReactNode, ReactNodeArray } from 'react';
import React, {
useState,
useEffect,
useRef,
KeyboardEvent,
ChangeEvent,
ReactNode,
ReactNodeArray,
ReactElement
} from 'react';
import TerminalInput from './linetypes/TerminalInput';
import TerminalOutput from './linetypes/TerminalOutput';
import './style.css';
import {IWindowButtonsProps, WindowButtons} from "./ui-elements/WindowButtons";

export enum ColorMode {
Light,
Expand All @@ -20,9 +30,10 @@ export interface Props {
yellowBtnCallback?: () => void;
greenBtnCallback?: () => void;
scrollToPosition?: boolean;
TopButtonsPanel?: (props: IWindowButtonsProps) => ReactElement | null;
}

const Terminal = ({name, prompt, height = "600px", colorMode, onInput, children, startingInputValue = "", redBtnCallback, yellowBtnCallback, greenBtnCallback, scrollToPosition = true}: Props) => {
const Terminal = ({name, prompt, height = "600px", colorMode, onInput, children, startingInputValue = "", redBtnCallback, yellowBtnCallback, greenBtnCallback, scrollToPosition = true, TopButtonsPanel = WindowButtons}: Props) => {
const [currentLineInput, setCurrentLineInput] = useState('');
const [cursorPos, setCursorPos] = useState(0);

Expand Down Expand Up @@ -117,11 +128,7 @@ const Terminal = ({name, prompt, height = "600px", colorMode, onInput, children,
}
return (
<div className={ classes.join(' ') } data-terminal-name={ name }>
<div className="react-terminal-window-buttons">
<button className={`${yellowBtnCallback ? "clickable": ""} red-btn`} disabled={!redBtnCallback} onClick={ redBtnCallback } />
<button className={`${yellowBtnCallback ? "clickable" : ""} yellow-btn`} disabled={!yellowBtnCallback} onClick={ yellowBtnCallback } />
<button className={`${greenBtnCallback ? "clickable" : ""} green-btn`} disabled={!greenBtnCallback} onClick={ greenBtnCallback } />
</div>
<TopButtonsPanel {...{redBtnCallback, yellowBtnCallback, greenBtnCallback}}/>
<div className="react-terminal" style={ { height } }>
{ children }
{ typeof onInput === 'function' && <div className="react-terminal-line react-terminal-input react-terminal-active-input" data-terminal-prompt={ prompt || '$' } key="terminal-line-prompt" >{ currentLineInput }<span className="cursor" style={{ left: `${cursorPos+1}px` }}></span></div> }
Expand Down
18 changes: 18 additions & 0 deletions src/ui-elements/WindowButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";

interface IWindowButtonsProps {
redBtnCallback?: () => void;
yellowBtnCallback?: () => void;
greenBtnCallback?: () => void;
}

const WindowButtons = ({ redBtnCallback, yellowBtnCallback, greenBtnCallback }: IWindowButtonsProps) => (
<div className="react-terminal-window-buttons">
<button className={`${yellowBtnCallback ? "clickable": ""} red-btn`} disabled={!redBtnCallback} onClick={ redBtnCallback } />
<button className={`${yellowBtnCallback ? "clickable" : ""} yellow-btn`} disabled={!yellowBtnCallback} onClick={ yellowBtnCallback } />
<button className={`${greenBtnCallback ? "clickable" : ""} green-btn`} disabled={!greenBtnCallback} onClick={ greenBtnCallback } />
</div>
);

export { WindowButtons, IWindowButtonsProps};
export default WindowButtons;
Loading