From 43b03aa9599e8eb243fda86bcf1c49a90b54e363 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Mar 2020 21:03:38 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20a=20possibility=20?= =?UTF-8?q?to=20override=20cursor=20when=20using=20builder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kittik-slide/examples/builder.ts | 40 ++++++++++++++++++++++ src/kittik-slide/spec/SlideBuilder.spec.ts | 4 ++- src/kittik-slide/src/slide/Slide.ts | 2 +- src/kittik-slide/src/slide/SlideBuilder.ts | 7 ++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/kittik-slide/examples/builder.ts diff --git a/src/kittik-slide/examples/builder.ts b/src/kittik-slide/examples/builder.ts new file mode 100644 index 0000000..6fd84da --- /dev/null +++ b/src/kittik-slide/examples/builder.ts @@ -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)); diff --git a/src/kittik-slide/spec/SlideBuilder.spec.ts b/src/kittik-slide/spec/SlideBuilder.spec.ts index 52a9eb5..e43ff7b 100644 --- a/src/kittik-slide/spec/SlideBuilder.spec.ts +++ b/src/kittik-slide/spec/SlideBuilder.spec.ts @@ -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 diff --git a/src/kittik-slide/src/slide/Slide.ts b/src/kittik-slide/src/slide/Slide.ts index 4301873..5fe7ff0 100644 --- a/src/kittik-slide/src/slide/Slide.ts +++ b/src/kittik-slide/src/slide/Slide.ts @@ -19,10 +19,10 @@ export { SlideBuilder } from './SlideBuilder'; export { SlideDeclaration } from './SlideDeclaration'; export class Slide { - readonly cursor: Canvas = Canvas.create(); readonly shapes: Map = new Map(); readonly animations: Map = new Map(); readonly order: OrderDeclaration[] = []; + cursor: Canvas = Canvas.create(); constructor (cursor?: Canvas, declaration?: SlideDeclaration) { if (cursor !== undefined) { diff --git a/src/kittik-slide/src/slide/SlideBuilder.ts b/src/kittik-slide/src/slide/SlideBuilder.ts index 06299c0..fc73a62 100644 --- a/src/kittik-slide/src/slide/SlideBuilder.ts +++ b/src/kittik-slide/src/slide/SlideBuilder.ts @@ -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);