Skip to content

spacing problems #38

@arderyp

Description

@arderyp

I logged a colored ansi output to a file with: script --quiet --command "ls -l --color=always" "$LOGFILE" > /dev/null.

When I cat the file, it looks good, the same as when I run ls -l --color=always natively on the command line (ubuntu).

The raw text from the file:

Script started on 2025-04-17 16:36:27-07:00 [TERM="xterm-256color" TTY="/dev/pts/21" COLUMNS="-1" LINES="-1"]
total 516^M
-rw-rw-r--  1 arderyp arderyp   7374 Apr 16 12:07 ^[[00mcomposer.json^[[0m^M
-rw-rw-r--  1 arderyp arderyp 415439 Apr 16 12:07 ^[[00mcomposer.lock^[[0m^M
-rw-rw-r--  1 arderyp arderyp   2873 Feb 14  2023 ^[[32mREADME.md^[[0m^M

Script done on 2025-04-17 16:36:27-07:00 [COMMAND_EXIT_CODE="0"]

However, the following code:

$file = $kernel->getProjectDir() . '/var/log/sync.log';
if (! $size = filesize($file)) {
    throw new Exception("failed to determine file size of: $file");
}
if (! $handler = fopen($file, 'r')) {
    throw new Exception("failed to open file handler for: $file");
}
if (! $text = fread($handler, $size)) {
    throw new Exception("failed to read text contents of: $file");
}
if (file_exists($file)) {
    $theme = new SolarizedXTermTheme();
    $converter = new AnsiToHtmlConverter();
    $html = $converter->convert($text);
}
$this->setTemplateParams(['log_file_contents' => $html]);
return $this->renderTemplate();

gives me proper color, but bad spacing, like:

composer.json
-rw-rw-r-- 1 arderyp arderyp 415439 Apr 16 12:07
composer.lock
drwxrwxr-x 4 arderyp arderyp 4096 Feb 20 21:03 

from command line:

total 516
-rw-rw-r--  1 arderyp arderyp   7413 Apr 17 16:37 composer.json
-rw-rw-r--  1 arderyp arderyp 417122 Apr 17 16:37 composer.lock
-rw-rw-r--  1 arderyp arderyp   2873 Feb 14  2023 README.md

When testing against other command that log lines prefixed with space, like:

THIS
    a
    b
    c

It shows up as collapsed

THIS
a
b
c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions