@@ -45,18 +45,17 @@ void RecordSession(struct outargs oa) {
4545 char * exec_cmd ;
4646 char cwd [PATH_MAX ];
4747
48- oa .env = SerializeEnv ();
48+ oa .rec . env = SerializeEnv ();
4949 exec_cmd = NULL ;
5050
51- if (!oa .format ) oa .format = ASCIINEMA_V1 ;
52- if (!oa .fileName ) oa .fileName = "events.cast" ;
51+ if (!oa .rec .filePath ) oa .rec .filePath = "events.cast" ;
5352
5453 if (pipe (controlfd ) != 0 ) die ("pipe" );
5554 oa .controlfd = controlfd [0 ];
5655
5756 TermGetWinSize (& rows , & cols );
58- oa .rows = rows ;
59- oa .cols = cols ;
57+ oa .rec . width = cols ;
58+ oa .rec . height = rows ;
6059
6160 if (getcwd (cwd , sizeof (cwd )) != NULL ) {
6261 printf ("CWD: %s\n" , cwd );
@@ -71,11 +70,11 @@ void RecordSession(struct outargs oa) {
7170 if (ioctl (STDIN_FILENO , TIOCGWINSZ , & win ) == -1 ) die ("ioctl(TIOCGWINSZ)" );
7271
7372 owin = rwin = win ;
74- if (!oa .rows || oa .rows > win .ws_row ) oa .rows = win .ws_row ;
75- if (!oa .cols || oa .cols > win .ws_col ) oa .cols = win .ws_col ;
73+ if (!oa .rec . width || oa .rec . width > win .ws_col ) oa .rec . width = win .ws_col ;
74+ if (!oa .rec . height || oa .rec . height > win .ws_row ) oa .rec . height = win .ws_row ;
7675
77- win .ws_row = oa .rows ;
78- win .ws_col = oa .cols ;
76+ win .ws_col = oa .rec . width ;
77+ win .ws_row = oa .rec . height ;
7978
8079 TermEnableRawMode ();
8180
@@ -278,8 +277,7 @@ static void handle_command(enum control_command cmd) {
278277}
279278
280279// This Function Is Responsible For Writing The Data To The File
281- static inline void handle_input (unsigned char * buf , size_t buflen , FileFormat format ) {
282- assert (format >= ASCIINEMA_V1 && format <= ASCIINEMA_V2 );
280+ static inline void handle_input (FILE * writerFile , unsigned char * buf , size_t buflen ) {
283281 static int first = 1 ;
284282 double delta ;
285283
@@ -300,7 +298,7 @@ static inline void handle_input(unsigned char *buf, size_t buflen, FileFormat fo
300298
301299 dur += delta ;
302300
303- WriteStdoutStart (( format == ASCIINEMA_V1 ? delta : dur ) / 1000 );
301+ Writer_OnBeforeStdoutData ( writerFile , delta / 1000.0f );
304302
305303 uint32_t state , cp ;
306304 state = 0 ;
@@ -313,29 +311,29 @@ static inline void handle_input(unsigned char *buf, size_t buflen, FileFormat fo
313311 uint32_t h , l ;
314312 h = ((cp - 0x10000 ) >> 10 ) + 0xd800 ;
315313 l = ((cp - 0x10000 ) & 0x3ff ) + 0xdc00 ;
316- WriteStdout_fprintf ( "\\u%04" PRIx32 "\\u%04" PRIx32 , h , l );
314+ Writer_OnStdoutData ( writerFile , "\\u%04" PRIx32 "\\u%04" PRIx32 , h , l );
317315 } else {
318- WriteStdout_fprintf ( "\\u%04" PRIx32 , cp );
316+ Writer_OnStdoutData ( writerFile , "\\u%04" PRIx32 , cp );
319317 }
320318 } else {
321- WriteStdout_fputs ( "\\ud83d\\udca9" );
319+ Writer_OnStdoutData ( writerFile , "\\ud83d\\udca9" );
322320 }
323321 } else {
324322 switch (buf [j ]) {
325323 case '"' :
326324 case '\\' :
327- WriteStdout_fputc ( '\\' ); // output backslash for escaping
328- WriteStdout_fputc ( buf [j ]); // print the character itself
325+ Writer_OnStdoutData ( writerFile , "\\" ); // output backslash for escaping
326+ Writer_OnStdoutData ( writerFile , "%c" , buf [j ]); // print the character itself
329327 break ;
330328 default :
331- WriteStdout_fputc ( buf [j ]);
329+ Writer_OnStdoutData ( writerFile , "%c" , buf [j ]);
332330 break ;
333331 }
334332 }
335333 }
336334 }
337335
338- WriteStdoutEnd ( );
336+ Writer_OnAfterStdoutData ( writerFile );
339337}
340338
341339/*
@@ -350,13 +348,11 @@ void StartOutputProcess(struct outargs *oa) {
350348 status = EXIT_SUCCESS ;
351349 master = oa -> masterfd ;
352350
353- assert (oa -> format >= ASCIINEMA_V1 && oa -> format <= ASCIINEMA_V2 );
354-
355351 start_paused = paused = oa -> start_paused ;
356352
357353 setbuf (stdout , NULL ); // Set The Stream To Be Un-Buffered
358- WriterInit (oa -> fileName );
359- WriteHeader ( oa );
354+ FILE * writerFile = Writer_Init (oa -> rec . filePath );
355+ Writer_WriteHeader ( writerFile , & oa -> rec );
360356
361357 if (close (STDIN_FILENO ) == -1 ) {
362358 die ("close" );
@@ -428,15 +424,17 @@ void StartOutputProcess(struct outargs *oa) {
428424 }
429425
430426 if (!paused ) {
431- handle_input (obuf , nread , oa -> format );
427+ handle_input (writerFile , obuf , nread );
432428 }
433429 }
434430 }
435431 }
436432
437433end :
438- WriteDuration (dur / 1000 );
439- WriterClose ();
434+ Writer_OnStdoutAllEnd (writerFile );
435+ Writer_WriteDuration (writerFile , dur / 1000.0f );
436+ Writer_Close (writerFile );
437+
440438 if (close (oa -> masterfd ) == -1 ) {
441439 die ("close" );
442440 }
0 commit comments