Skip to content

Color output for commands #179

Closed
Closed

Description

@mmarchini

While trying to come up with a comprehensible output format for #115, I decided to play with colors in llnode commands outputs:

asciicast

Not entirely sure if this is something we want to have on llnode since we'll need to detect if the terminal supports color (I have no idea how to do that), but if we decide to have it I can open a PR with it.

Activity

  1. joyeecheung commented on Mar 22, 2018

    @joyeecheung
    Member

    We can use an environment variable or a command line flag to control the colors (for example to work around tests or other cases where we need to redirect the output to a file)

  2. joyeecheung commented on Mar 22, 2018

    @joyeecheung
    Member

    BTW I have this when I need to write the output of a command to a file when it's too long to read in the terminal (e.g. the result of v8 findjsinstance)

    ~/.lldb/to_file.py

    import lldb
    import sys
    
    def to_file(debugger, command, result, dict):
        # Change the output file to a path/name of your choice
        f = open("/tmp/temp-lldb-output.txt", "w")
        debugger.SetOutputFileHandle(f, True)
        # Change command to the command you want the output of
        debugger.HandleCommand(command)
        f.close()
        print >> sys.stderr, 'Written to /tmp/temp-lldb-output.txt'
        debugger.SetOutputFileHandle(sys.stdout, True)

    ~/.lldbinit

    comma script import ~/.lldb/to_file.py
    comma script add -f to_file.to_file to_file
    
  3. mmarchini commented on Mar 22, 2018

    @mmarchini
    ContributorAuthor

    Ohh, nice script! I usually do lldb node -c core -b -o "v8 findjsinstances" > output.txt, but I need to quit lldb to use this :/.

    I was thinking: we could have something like v8 settings set color on (off by default), and then use the llnode script to determine if the terminal is color-friendly. If it is, turn on color with --one-line "v8 settings set color on" before starting lldb. What do you think?

    Edit: This would also make it easier to have an environment variable and a flag, as you suggested 😄

  4. joyeecheung commented on Mar 22, 2018

    @joyeecheung
    Member
  5. gibfahn commented on Mar 26, 2018

    @gibfahn
    Member

    We can use an environment variable or a command line flag to control the colors (for example to work around tests or other cases where we need to redirect the output to a file)

    If we do this (which I think we should) I think the standard thing I've seen is to set --color=auto, which outputs color if the stdout/stderr is a tty, and not otherwise. Then you can have always or never as options. That seems to be what other programs I've used tend to have.

  6. Drieger commented on Aug 21, 2018

    @Drieger
    Contributor

    I started working on a prototype, using the rang library. Any thoughts and ideas are welcome. The proposed flag is still missing, I just need some guidance to know if current work is ok.

    Current work: master...Drieger:start_colorization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions