1+ import { parseOptionalFloat } from "@prozilla-os/shared" ;
12import { formatError } from "../_utils/terminal.utils" ;
23import { Command } from "../command" ;
34import { Stream } from "../stream" ;
@@ -136,7 +137,7 @@ const EXTRA_WAGONS = [
136137 ] ,
137138] ;
138139
139- function generateLocomotive ( frame : number , wagonCount = 1 ) {
140+ function generateLocomotive ( frame : number , wagonCount = 1 , start = 50 ) {
140141 const smokeHeight = LOCOMOTIVE_SMOKE [ 0 ] . length ;
141142 const locomotiveHeight = LOCOMOTIVE_TOP . length + LOCOMOTIVE_BOTTOM [ 0 ] . length ;
142143 const wagonHeight = COAL_WAGON . length ;
@@ -147,7 +148,7 @@ function generateLocomotive(frame: number, wagonCount = 1) {
147148 const top = LOCOMOTIVE_TOP ;
148149 const bottom = LOCOMOTIVE_BOTTOM [ frame % LOCOMOTIVE_BOTTOM . length ] ;
149150
150- const distance = 50 - frame ;
151+ const distance = start - frame ;
151152 const locomotive = smoke . concat ( top , bottom ) . map ( ( line , index ) => {
152153 if ( index >= wagonStart && wagonCount > 0 ) {
153154 for ( let i = 0 ; i < wagonCount ; i ++ ) {
@@ -175,18 +176,23 @@ function generateLocomotive(frame: number, wagonCount = 1) {
175176export const sl = new Command ( )
176177 . setManual ( {
177178 purpose : "Show animations aimed to correct users who accidentally enter sl instead of ls. SL stands for Steam Locomotive." ,
178- usage : "sl\n"
179- + "sl -w number" ,
179+ usage : "sl [ -w ]" ,
180180 options : {
181181 "-w number" : "Set the amount of wagons (defaults to 1)" ,
182+ "-s speed" : `Set the speed of the locomotive (Defaults to ${ ANIMATION_SPEED } )` ,
182183 } ,
183184 } )
184185 . addOption ( {
185186 short : "w" ,
186187 long : "wagons" ,
187188 isInput : true ,
188189 } )
189- . setExecute ( function ( this : Command , _args , { inputs } ) {
190+ . addOption ( {
191+ short : "s" ,
192+ long : "speed" ,
193+ isInput : true ,
194+ } )
195+ . setExecute ( function ( this : Command , _args , { inputs, size } ) {
190196 let wagonCount = 1 ;
191197
192198 if ( inputs ?. w ) {
@@ -197,17 +203,19 @@ export const sl = new Command()
197203 }
198204 }
199205
206+ const delay = 100 / parseOptionalFloat ( inputs ?. s , ANIMATION_SPEED ) ;
207+
200208 const stream = new Stream ( ) ;
201209
202- let frame = 0 ;
210+ let frame = 0 ;
203211 const interval = setInterval ( ( ) => {
204- const text = generateLocomotive ( frame , wagonCount ) ;
212+ const text = generateLocomotive ( frame , wagonCount , size . x ) ;
205213 stream . send ( text ) ;
206214 frame ++ ;
207215
208216 if ( text . trim ( ) . length === 0 )
209217 stream . stop ( ) ;
210- } , 100 / ANIMATION_SPEED ) ;
218+ } , delay ) ;
211219
212220 stream . on ( Stream . STOP_EVENT , ( ) => {
213221 clearInterval ( interval ) ;
0 commit comments