Skip to content

Commit

Permalink
feat: 🎸 add a possibility to override cursor when using builder
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaiklor committed Mar 28, 2020
1 parent d30c965 commit 43b03aa
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/kittik-slide/examples/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Canvas } from 'terminal-canvas';
import { AnimationBuilder, ShapeBuilder, SlideBuilder } from '..';

const cursor = Canvas.create().saveScreen().reset().hideCursor();

SlideBuilder
.start()
.withCursor(cursor)
.withShape(
'Hello, World',
ShapeBuilder
.start('Rectangle')
.withText('Hello, World')
.withBackground('aqua')
.withForeground('green')
.withX('center')
.withY('middle')
.end()
)
.withShape(
'Footer',
ShapeBuilder
.start('FigText')
.withText('kittik (c) ghaiklor')
.withX('center')
.withY('bottom')
.end()
)
.withAnimation(
'Printing',
AnimationBuilder
.start('Print')
.end()
)
.withOrder('Hello, World', ['Printing'])
.withOrder('Footer', ['Printing'])
.end()
.render()
.finally(() => cursor.restoreScreen().showCursor())
.catch(e => console.error(e));
4 changes: 3 additions & 1 deletion src/kittik-slide/spec/SlideBuilder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { SlideBuilder } from '../src/slide/SlideBuilder';
import { Canvas } from 'terminal-canvas';
import { ShapeBuilder, AnimationBuilder } from '../src/slide/Slide';
import { SlideBuilder } from '../src/slide/SlideBuilder';

describe('SlideBuilder', () => {
it('Should properly instantiate slide via builder', () => {
const slide = SlideBuilder
.start()
.withCursor(Canvas.create())
.withShape(
'Hello, World',
ShapeBuilder
Expand Down
2 changes: 1 addition & 1 deletion src/kittik-slide/src/slide/Slide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export { SlideBuilder } from './SlideBuilder';
export { SlideDeclaration } from './SlideDeclaration';

export class Slide {
readonly cursor: Canvas = Canvas.create();
readonly shapes: Map<string, ShapeRenderable> = new Map();
readonly animations: Map<string, Animationable> = new Map();
readonly order: OrderDeclaration[] = [];
cursor: Canvas = Canvas.create();

constructor (cursor?: Canvas, declaration?: SlideDeclaration) {
if (cursor !== undefined) {
Expand Down
7 changes: 7 additions & 0 deletions src/kittik-slide/src/slide/SlideBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Animationable } from 'kittik-animation-basic';
import { Canvas } from 'terminal-canvas';
import { ShapeRenderable } from 'kittik-shape-basic';
import { Slide } from './Slide';

export class SlideBuilder {
slide: Slide = new Slide();

withCursor (cursor: Canvas): this {
this.slide.cursor = cursor;

return this;
}

withShape (name: string, shape: ShapeRenderable): this {
this.slide.addShape(name, shape);

Expand Down

0 comments on commit 43b03aa

Please sign in to comment.