mercurial/formatter.py
changeset 34131 0fa781320203
parent 33090 04b3743c1d7c
child 34255 d6af8da4a3b8
equal deleted inserted replaced
34130:ada8a19672ab 34131:0fa781320203
    50 ...     return fn(ui, ui.formatter(fn.__name__, opts))
    50 ...     return fn(ui, ui.formatter(fn.__name__, opts))
    51 
    51 
    52 Basic example:
    52 Basic example:
    53 
    53 
    54 >>> def files(ui, fm):
    54 >>> def files(ui, fm):
    55 ...     files = [('foo', 123, (0, 0)), ('bar', 456, (1, 0))]
    55 ...     files = [(b'foo', 123, (0, 0)), (b'bar', 456, (1, 0))]
    56 ...     for f in files:
    56 ...     for f in files:
    57 ...         fm.startitem()
    57 ...         fm.startitem()
    58 ...         fm.write('path', '%s', f[0])
    58 ...         fm.write(b'path', b'%s', f[0])
    59 ...         fm.condwrite(ui.verbose, 'date', '  %s',
    59 ...         fm.condwrite(ui.verbose, b'date', b'  %s',
    60 ...                      fm.formatdate(f[2], '%Y-%m-%d %H:%M:%S'))
    60 ...                      fm.formatdate(f[2], b'%Y-%m-%d %H:%M:%S'))
    61 ...         fm.data(size=f[1])
    61 ...         fm.data(size=f[1])
    62 ...         fm.plain('\\n')
    62 ...         fm.plain(b'\\n')
    63 ...     fm.end()
    63 ...     fm.end()
    64 >>> show(files)
    64 >>> show(files)
    65 foo
    65 foo
    66 bar
    66 bar
    67 >>> show(files, verbose=True)
    67 >>> show(files, verbose=True)
    68 foo  1970-01-01 00:00:00
    68 foo  1970-01-01 00:00:00
    69 bar  1970-01-01 00:00:01
    69 bar  1970-01-01 00:00:01
    70 >>> show(files, template='json')
    70 >>> show(files, template=b'json')
    71 [
    71 [
    72  {
    72  {
    73   "date": [0, 0],
    73   "date": [0, 0],
    74   "path": "foo",
    74   "path": "foo",
    75   "size": 123
    75   "size": 123
    78   "date": [1, 0],
    78   "date": [1, 0],
    79   "path": "bar",
    79   "path": "bar",
    80   "size": 456
    80   "size": 456
    81  }
    81  }
    82 ]
    82 ]
    83 >>> show(files, template='path: {path}\\ndate: {date|rfc3339date}\\n')
    83 >>> show(files, template=b'path: {path}\\ndate: {date|rfc3339date}\\n')
    84 path: foo
    84 path: foo
    85 date: 1970-01-01T00:00:00+00:00
    85 date: 1970-01-01T00:00:00+00:00
    86 path: bar
    86 path: bar
    87 date: 1970-01-01T00:00:01+00:00
    87 date: 1970-01-01T00:00:01+00:00
    88 
    88 
    89 Nested example:
    89 Nested example:
    90 
    90 
    91 >>> def subrepos(ui, fm):
    91 >>> def subrepos(ui, fm):
    92 ...     fm.startitem()
    92 ...     fm.startitem()
    93 ...     fm.write('repo', '[%s]\\n', 'baz')
    93 ...     fm.write(b'repo', b'[%s]\\n', b'baz')
    94 ...     files(ui, fm.nested('files'))
    94 ...     files(ui, fm.nested(b'files'))
    95 ...     fm.end()
    95 ...     fm.end()
    96 >>> show(subrepos)
    96 >>> show(subrepos)
    97 [baz]
    97 [baz]
    98 foo
    98 foo
    99 bar
    99 bar
   100 >>> show(subrepos, template='{repo}: {join(files % "{path}", ", ")}\\n')
   100 >>> show(subrepos, template=b'{repo}: {join(files % "{path}", ", ")}\\n')
   101 baz: foo, bar
   101 baz: foo, bar
   102 """
   102 """
   103 
   103 
   104 from __future__ import absolute_import
   104 from __future__ import absolute_import
   105 
   105