cronvel / terminal-kit

Terminal utilities for node.js
MIT License
3.08k stars 198 forks source link

term.table does not work in Azure pipeline #240

Closed guyappy closed 11 months ago

guyappy commented 11 months ago

Hi all,

I'm running the following command in an Azure DevOps pipeline:

        - task: PowerShell@2
          displayName: 'Linting OpenAPI specification'
          continueOnError: true
          inputs:
            targetType: 'inline'
            workingDirectory: TEAM-spectral-linter
            script: |
              Write-Host "Starting OpenAPI linter"
              node index.js --mode=file
            failOnStderr: false

This triggers the index.js to print the following table eventually which works fine on my local (Windows) machine:

input;

const rows = [["Severity","Code","Message","Path","Range from","Range to"],["warn","operation-description","Operation \"description\" must be present and non-empty string.","paths->/external/suniverse/v1/products->get","27:13","112:7"],["hint","recognize-mandatory-query-param","Check if the query parameter 'type' is really required.","paths->/external/suniverse/v1/products->get","27:13","112:7"],["hint","operation-tag-defined","Operation tags must be defined in global tags.","paths->/external/suniverse/v1/products->get->tags->0","29:10","29:20"],["error","error-response","Error response body must be an errors array with at least one of the following properties: \"status\", \"title\", \"detail\", \"id\", \"links\", \"about\", \"type\", \"source\", \"meta\" or \"code\". See https://eneco.sharepoint.com/sites/EnablingPlatforms-ST/SitePages/API_Conventions_Errors.aspx for more details about the errors object.","paths->/external/suniverse/v1/products->get->responses","50:21","111:9"],["hint","security-definition-description","It would be more descriptive if you provide a description for every security definition.","components->securitySchemes->apiKey","132:16","136:7"],["warn","oas3-unused-component","Potentially unused component has been detected.","components->responses->401Error","150:18","164:7"],["error","verify-top-level-members","Response contains invalid top level member: message. For more info see: https://eneco.sharepoint.com/sites/EnablingPlatforms-ST/SitePages/API_Conventions_Document_Structure.aspx#top-level","components->responses->Products422Error->content->application/json->schema->properties","170:28","185:15"]];
term.table( rows , {
    hasBorder: true ,
    contentHasMarkup: true ,
    borderChars: 'lightRounded' ,
    borderAttr: { color: 'blue' } ,
    // textAttr: { bgColor: 'default' } ,
    // firstCellTextAttr: { bgColor: 'blue' } ,
    firstRowTextAttr: { bgColor: 'blue',  } ,
    // firstColumnTextAttr: { bgColor: 'red' } ,
    width: 160
});

image

However, in the Azure DevOps pipeine it does not show anything in the logs. The rows.length result in shown in the below screenshot and I copied the output (the array) and put that above in the code block which works locally.

image

cronvel commented 11 months ago

Hi,

Since the lib write to stdout, if console.log() can write to the log, term.table() should as well. If not, then something is wrong on the Azure end.

guyappy commented 11 months ago

Thanks for the response!

I added the console.table command to check this;

      console.log(`rows length: ${rows.length}`)
      console.log(`rows: ${JSON.stringify(rows)}`)
      console.table(rows);
      term.table( rows , {
              hasBorder: true ,
              contentHasMarkup: true ,
              borderChars: 'lightRounded' ,
              borderAttr: { color: 'blue' } ,
              // textAttr: { bgColor: 'default' } ,
              // firstCellTextAttr: { bgColor: 'blue' } ,
              firstRowTextAttr: { bgColor: 'blue',  } ,
              // firstColumnTextAttr: { bgColor: 'red' } ,
              width: 160
      });

output on Azure is: image

guyappy commented 11 months ago

@cronvel can this one please be opened?

cronvel commented 11 months ago

As of version 3.0.1, your bug should be mostly fixed.

Also note that the lib is intended for creating rich terminal application, not to log things, you are probably using the wrong tool here. For example you will not have colors.

For your information, interacting with a terminal is done by sending it escape sequence, that are not always compatible between terminals, there is no standard way. Without a terminal, assuming we are writing to a file for some human to read that later, all escape sequences are striped, so no color, no fancy style, and so on.

By the way, avoid duplicating issues on purpose, that's just annoying.

guyappy commented 11 months ago

Thank you for the fix, now it works indeed!

I understand duplicating issues is annoying but this issue was simply closed without it being resolved and I did not get a reply anymore so I thought you had a filter on issues that are open only, hence I recreated. that makes sense, no?

cronvel commented 11 months ago

No problem, have a nice day.