Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion about formatting #55

Closed
epipho opened this issue Feb 2, 2015 · 7 comments
Closed

Discussion about formatting #55

epipho opened this issue Feb 2, 2015 · 7 comments

Comments

@epipho
Copy link
Contributor

epipho commented Feb 2, 2015

Now that delve supports a majority of types, including complex arrays and structs I think it is worth looking at how to properly display them.

Here are my thoughts so far to get the discussion started.

  1. Support both a human readable format and a separate machine readable output format (for IDE integration).

  2. Standardize when the type name is shown in the human readable format. My first thought is to never show it when using the print command and add a ptype command to print the type of a variable on demand.

  3. Support slice syntax for printing arrays. print x prints the first 64 elements, print x[0] prints the first element, print x[10:12] prints elements 10 to 12 etc.

  4. Support pretty-printing for structs. This could be switched off and on. For example:
    Compact:

{f1: Value, f2: Value, f3: {f31: Value, f32: Value, f33: {f331: Value, f332: Value}}, f4: Value}

Pretty:

{
  f1: Value
  f2: Value
  f3: {
    f31: Value
    f32: Value
    f33: {
      f331: Value
      f332: Value
    }
  }
}
@derekparker
Copy link
Member

  1. Support both a human readable format and a separate machine readable output format (for IDE integration).

What did you have in mind for a machine readable output?

  1. Standardize when the type name is shown in the human readable format. My first thought is to never show it when using the print command and add a ptype command to print the type of a variable on demand.

Yeah, I definitely agree with this. I think this also extends into any nonessential information we display about variables, i.e. displaying len and cap for slices is most likely unnecessary. Maybe we have a command to display extended information about a variable, including type and any other metadata associated with it.

  1. Support slice syntax for printing arrays. print x prints the first 64 elements, print x[0] prints the first element, print x[10:12] prints elements 10 to 12 etc.

Absolutely.

  1. Support pretty-printing for structs. This could be switched off and on.

Good idea, maybe a flag for the print command, or a runtime configuration to enable pretty printing? I'm definitely open to suggestions.

@epipho
Copy link
Contributor Author

epipho commented Feb 4, 2015

What did you have in mind for a machine readable output?

Not sure, maybe json? Something standard so people can focus on integration rather than on how to parse the output.

Good idea, maybe a flag for the print command, or a runtime configuration to enable pretty printing? > I'm definitely open to suggestions.

I like GDB's combo of runtime config + startup script to set the defaults. Opens a lot of doors for customizing other output such as switching to machine readable output, chaning the default number of elements etc.

@derekparker
Copy link
Member

Not sure, maybe json? Something standard so people can focus on integration rather than on how to parse the output.

JSON sounds fine to me.

I like GDB's combo of runtime config + startup script to set the defaults. Opens a lot of doors for customizing other output such as switching to machine readable output, chaning the default number of elements etc.

Currently, there's no real way to configure Delve. I'd definitely like to talk through adding configuration to Delve. A startup script, or some sort of config file in the users home dir paired with maybe a command to set / list runtime variables.

@pnasrat
Copy link
Contributor

pnasrat commented Feb 4, 2015

+1 on JSON, it's pretty clear - definitely being able to log/redirect output to a file also (cf set logging file ) and enable/disable pagination for human interaction and scripted modes.

@pnasrat
Copy link
Contributor

pnasrat commented Feb 4, 2015

I also wonder if being able to output runtime/debug and pprof style info directly in delve would be useful. At least a quick hook to dump expvar into json may be worth it even if not the heap/gc/profile hooks.

@dlsniper
Copy link
Contributor

dlsniper commented Feb 9, 2015

May I suggest https://github.com/kr/pretty as a possible solution for pretty printing structs / maps.

As a small example:

package main

import "github.com/kr/pretty"

func main() {
    type (
        miniStr struct {
            mini string
        }

        str struct {
            payload  string
            payload2 miniStr
        }
    )

    a := map[string]map[string]str{
        "a": map[string]str{
            "b": str{
                payload: "c",
                payload2: miniStr{
                    mini:  "d",
                    mini2: "e",
                },
            },
        },
        "a2": map[string]str{
            "b2": str{
                payload: "c2",
                payload2: miniStr{
                    mini:  "d2",
                    mini2: "e2",
                },
            },
        },
    }

    pretty.Printf("%# v\n", a)
}
map[a:map[b:{payload:c payload2:{mini:d mini2:e}}] a2:map[b2:{payload:c2 payload2:{mini:d2 mini2:e2}}]]

map[string]map[string]main.str{
    "a": {
        "b": {
            payload:  "c",
            payload2: main.miniStr{mini:"d", mini2:"e"},
        },
    },
    "a2": {
        "b2": {
            payload:  "c2",
            payload2: main.miniStr{mini:"d2", mini2:"e2"},
        },
    },
}

@derekparker
Copy link
Member

Moving discussion related issues to mailing list. Please see (https://groups.google.com/forum/#!forum/delve-dev) for further discussion.

nclifton pushed a commit to nclifton/delve that referenced this issue Feb 24, 2021
* Remove brackets from the multipart contentids

* Removed the siml/smil mistake and the '.' on images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants