Mercurial > hg
annotate mercurial/crecord.py @ 28886:c64926b365b6
test-import: fix output on Windows
There's a symlink conditionalized test above this that causes the rev to be 1.
It isn't important to this test, so ignore it.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 15 Mar 2016 21:47:43 -0400 |
parents | 86db5cb55d46 |
children | ee56a86e2782 |
rev | line source |
---|---|
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1 # stuff related specifically to patch manipulation / parsing |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
2 # |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
3 # Copyright 2008 Mark Edgington <edgimar@gmail.com> |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
4 # |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
7 # |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
8 # This code is based on the Mark Edgington's crecord extension. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
9 # (Itself based on Bryan O'Sullivan's record extension.) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
10 |
25940
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
11 from __future__ import absolute_import |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
12 |
25940
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
13 import locale |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
14 import os |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
15 import re |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
16 import signal |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
17 import struct |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
18 import sys |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
19 |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
20 from .i18n import _ |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
21 from . import ( |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
22 encoding, |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26421
diff
changeset
|
23 error, |
25940
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
24 patch as patchmod, |
27156
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
25 util, |
25940
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
26 ) |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28638
diff
changeset
|
27 stringio = util.stringio |
24314
348492ba632a
crecord: more import style
Matt Mackall <mpm@selenic.com>
parents:
24313
diff
changeset
|
28 |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
29 # This is required for ncurses to display non-ASCII characters in default user |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
30 # locale encoding correctly. --immerrr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
31 locale.setlocale(locale.LC_ALL, '') |
24317
f559cae7892f
crecord: fiddle with vertical whitespace
Matt Mackall <mpm@selenic.com>
parents:
24316
diff
changeset
|
32 |
28637
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
33 # patch comments based on the git one |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
34 diffhelptext = _("""# To remove '-' lines, make them ' ' lines (context). |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
35 # To remove '+' lines, delete them. |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
36 # Lines starting with # will be removed from the patch. |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
37 """) |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
38 |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
39 hunkhelptext = _("""# |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
40 # If the patch applies cleanly, the edited hunk will immediately be |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
41 # added to the record list. If it does not apply cleanly, a rejects file |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
42 # will be generated. You can use that when you try again. If all lines |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
43 # of the hunk are removed, then the edit is aborted and the hunk is left |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
44 # unchanged. |
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
45 """) |
28638
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
46 |
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
47 patchhelptext = _("""# |
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
48 # If the patch applies cleanly, the edited patch will immediately |
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
49 # be finalised. If it does not apply cleanly, rejects files will be |
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
50 # generated. You can use those when you try again. |
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
51 """) |
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
52 |
27528
7cc654610204
crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents:
26781
diff
changeset
|
53 try: |
24909
d71492ca2fdd
crecord: fix mixed imports warning
Matt Harbison <matt_harbison@yahoo.com>
parents:
24840
diff
changeset
|
54 import curses |
25940
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
55 import fcntl |
f4356e5094ba
crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25821
diff
changeset
|
56 import termios |
27528
7cc654610204
crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents:
26781
diff
changeset
|
57 curses.error |
7cc654610204
crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents:
26781
diff
changeset
|
58 fcntl.ioctl |
7cc654610204
crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents:
26781
diff
changeset
|
59 termios.TIOCGWINSZ |
7cc654610204
crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents:
26781
diff
changeset
|
60 except ImportError: |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
61 # I have no idea if wcurses works with crecord... |
24423
01b39e821d00
crecord: conditionalize the imports that are not available on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
24351
diff
changeset
|
62 try: |
01b39e821d00
crecord: conditionalize the imports that are not available on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
24351
diff
changeset
|
63 import wcurses as curses |
27528
7cc654610204
crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents:
26781
diff
changeset
|
64 curses.error |
24423
01b39e821d00
crecord: conditionalize the imports that are not available on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
24351
diff
changeset
|
65 except ImportError: |
27530
ba30ef5bba95
crecord: ensure that curses is False if not imported
Sean Farley <sean@farley.io>
parents:
27529
diff
changeset
|
66 # wcurses is not shipped on Windows by default, or python is not |
ba30ef5bba95
crecord: ensure that curses is False if not imported
Sean Farley <sean@farley.io>
parents:
27529
diff
changeset
|
67 # compiled with curses |
ba30ef5bba95
crecord: ensure that curses is False if not imported
Sean Farley <sean@farley.io>
parents:
27529
diff
changeset
|
68 curses = False |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
69 |
27529
940cedaee988
crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents:
27528
diff
changeset
|
70 def checkcurses(ui): |
940cedaee988
crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents:
27528
diff
changeset
|
71 """Return True if the user wants to use curses |
940cedaee988
crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents:
27528
diff
changeset
|
72 |
940cedaee988
crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents:
27528
diff
changeset
|
73 This method returns True if curses is found (and that python is built with |
940cedaee988
crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents:
27528
diff
changeset
|
74 it) and that the user has the correct flag for the ui. |
940cedaee988
crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents:
27528
diff
changeset
|
75 """ |
28543
f7874de435c5
crecord: use ui.interface to choose curses interface
Simon Farnsworth <simonfar@fb.com>
parents:
27937
diff
changeset
|
76 return curses and ui.interface("chunkselector") == "curses" |
27529
940cedaee988
crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents:
27528
diff
changeset
|
77 |
24316
d61aa383e2e5
crecord: fix underbar style for orig_stdout
Matt Mackall <mpm@selenic.com>
parents:
24315
diff
changeset
|
78 _origstdout = sys.__stdout__ # used by gethw() |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
79 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
80 class patchnode(object): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
81 """abstract class for patch graph nodes |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
82 (i.e. patchroot, header, hunk, hunkline) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
83 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
84 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
85 def firstchild(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
86 raise NotImplementedError("method must be implemented by subclass") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
87 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
88 def lastchild(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
89 raise NotImplementedError("method must be implemented by subclass") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
90 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
91 def allchildren(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
92 "Return a list of all of the direct children of this node" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
93 raise NotImplementedError("method must be implemented by subclass") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
94 def nextsibling(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
95 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
96 Return the closest next item of the same type where there are no items |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
97 of different types between the current item and this closest item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
98 If no such item exists, return None. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
99 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
100 raise NotImplementedError("method must be implemented by subclass") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
101 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
102 def prevsibling(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
103 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
104 Return the closest previous item of the same type where there are no |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
105 items of different types between the current item and this closest item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
106 If no such item exists, return None. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
107 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
108 raise NotImplementedError("method must be implemented by subclass") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
109 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
110 def parentitem(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
111 raise NotImplementedError("method must be implemented by subclass") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
112 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
113 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
114 def nextitem(self, constrainlevel=True, skipfolded=True): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
115 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
116 If constrainLevel == True, return the closest next item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
117 of the same type where there are no items of different types between |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
118 the current item and this closest item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
119 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
120 If constrainLevel == False, then try to return the next item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
121 closest to this item, regardless of item's type (header, hunk, or |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
122 HunkLine). |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
123 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
124 If skipFolded == True, and the current item is folded, then the child |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
125 items that are hidden due to folding will be skipped when determining |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
126 the next item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
127 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
128 If it is not possible to get the next item, return None. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
129 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
130 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
131 itemfolded = self.folded |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
132 except AttributeError: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
133 itemfolded = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
134 if constrainlevel: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
135 return self.nextsibling() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
136 elif skipfolded and itemfolded: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
137 nextitem = self.nextsibling() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
138 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
139 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
140 nextitem = self.parentitem().nextsibling() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
141 except AttributeError: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
142 nextitem = None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
143 return nextitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
144 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
145 # try child |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
146 item = self.firstchild() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
147 if item is not None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
148 return item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
149 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
150 # else try next sibling |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
151 item = self.nextsibling() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
152 if item is not None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
153 return item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
154 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
155 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
156 # else try parent's next sibling |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
157 item = self.parentitem().nextsibling() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
158 if item is not None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
159 return item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
160 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
161 # else return grandparent's next sibling (or None) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
162 return self.parentitem().parentitem().nextsibling() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
163 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
164 except AttributeError: # parent and/or grandparent was None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
165 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
166 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
167 def previtem(self, constrainlevel=True, skipfolded=True): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
168 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
169 If constrainLevel == True, return the closest previous item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
170 of the same type where there are no items of different types between |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
171 the current item and this closest item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
172 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
173 If constrainLevel == False, then try to return the previous item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
174 closest to this item, regardless of item's type (header, hunk, or |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
175 HunkLine). |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
176 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
177 If skipFolded == True, and the current item is folded, then the items |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
178 that are hidden due to folding will be skipped when determining the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
179 next item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
180 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
181 If it is not possible to get the previous item, return None. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
182 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
183 if constrainlevel: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
184 return self.prevsibling() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
185 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
186 # try previous sibling's last child's last child, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
187 # else try previous sibling's last child, else try previous sibling |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
188 prevsibling = self.prevsibling() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
189 if prevsibling is not None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
190 prevsiblinglastchild = prevsibling.lastchild() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
191 if ((prevsiblinglastchild is not None) and |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
192 not prevsibling.folded): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
193 prevsiblinglclc = prevsiblinglastchild.lastchild() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
194 if ((prevsiblinglclc is not None) and |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
195 not prevsiblinglastchild.folded): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
196 return prevsiblinglclc |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
197 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
198 return prevsiblinglastchild |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
199 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
200 return prevsibling |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
201 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
202 # try parent (or None) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
203 return self.parentitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
204 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
205 class patch(patchnode, list): # todo: rename patchroot |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
206 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
207 list of header objects representing the patch. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
208 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
209 def __init__(self, headerlist): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
210 self.extend(headerlist) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
211 # add parent patch object reference to each header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
212 for header in self: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
213 header.patch = self |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
214 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
215 class uiheader(patchnode): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
216 """patch header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
217 |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26587
diff
changeset
|
218 xxx shouldn't we move this to mercurial/patch.py ? |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
219 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
220 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
221 def __init__(self, header): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
222 self.nonuiheader = header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
223 # flag to indicate whether to apply this chunk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
224 self.applied = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
225 # flag which only affects the status display indicating if a node's |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
226 # children are partially applied (i.e. some applied, some not). |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
227 self.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
228 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
229 # flag to indicate whether to display as folded/unfolded to user |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
230 self.folded = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
231 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
232 # list of all headers in patch |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
233 self.patch = None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
234 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
235 # flag is False if this header was ever unfolded from initial state |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
236 self.neverunfolded = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
237 self.hunks = [uihunk(h, self) for h in self.hunks] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
238 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
239 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
240 def prettystr(self): |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28638
diff
changeset
|
241 x = stringio() |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
242 self.pretty(x) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
243 return x.getvalue() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
244 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
245 def nextsibling(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
246 numheadersinpatch = len(self.patch) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
247 indexofthisheader = self.patch.index(self) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
248 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
249 if indexofthisheader < numheadersinpatch - 1: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
250 nextheader = self.patch[indexofthisheader + 1] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
251 return nextheader |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
252 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
253 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
254 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
255 def prevsibling(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
256 indexofthisheader = self.patch.index(self) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
257 if indexofthisheader > 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
258 previousheader = self.patch[indexofthisheader - 1] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
259 return previousheader |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
260 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
261 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
262 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
263 def parentitem(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
264 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
265 there is no 'real' parent item of a header that can be selected, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
266 so return None. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
267 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
268 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
269 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
270 def firstchild(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
271 "return the first child of this item, if one exists. otherwise None." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
272 if len(self.hunks) > 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
273 return self.hunks[0] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
274 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
275 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
276 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
277 def lastchild(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
278 "return the last child of this item, if one exists. otherwise None." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
279 if len(self.hunks) > 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
280 return self.hunks[-1] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
281 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
282 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
283 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
284 def allchildren(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
285 "return a list of all of the direct children of this node" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
286 return self.hunks |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
287 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
288 def __getattr__(self, name): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
289 return getattr(self.nonuiheader, name) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
290 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
291 class uihunkline(patchnode): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
292 "represents a changed line in a hunk" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
293 def __init__(self, linetext, hunk): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
294 self.linetext = linetext |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
295 self.applied = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
296 # the parent hunk to which this line belongs |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
297 self.hunk = hunk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
298 # folding lines currently is not used/needed, but this flag is needed |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
299 # in the previtem method. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
300 self.folded = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
301 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
302 def prettystr(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
303 return self.linetext |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
304 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
305 def nextsibling(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
306 numlinesinhunk = len(self.hunk.changedlines) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
307 indexofthisline = self.hunk.changedlines.index(self) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
308 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
309 if (indexofthisline < numlinesinhunk - 1): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
310 nextline = self.hunk.changedlines[indexofthisline + 1] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
311 return nextline |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
312 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
313 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
314 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
315 def prevsibling(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
316 indexofthisline = self.hunk.changedlines.index(self) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
317 if indexofthisline > 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
318 previousline = self.hunk.changedlines[indexofthisline - 1] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
319 return previousline |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
320 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
321 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
322 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
323 def parentitem(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
324 "return the parent to the current item" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
325 return self.hunk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
326 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
327 def firstchild(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
328 "return the first child of this item, if one exists. otherwise None." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
329 # hunk-lines don't have children |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
330 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
331 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
332 def lastchild(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
333 "return the last child of this item, if one exists. otherwise None." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
334 # hunk-lines don't have children |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
335 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
336 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
337 class uihunk(patchnode): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
338 """ui patch hunk, wraps a hunk and keep track of ui behavior """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
339 maxcontext = 3 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
340 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
341 def __init__(self, hunk, header): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
342 self._hunk = hunk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
343 self.changedlines = [uihunkline(line, self) for line in hunk.hunk] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
344 self.header = header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
345 # used at end for detecting how many removed lines were un-applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
346 self.originalremoved = self.removed |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
347 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
348 # flag to indicate whether to display as folded/unfolded to user |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
349 self.folded = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
350 # flag to indicate whether to apply this chunk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
351 self.applied = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
352 # flag which only affects the status display indicating if a node's |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
353 # children are partially applied (i.e. some applied, some not). |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
354 self.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
355 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
356 def nextsibling(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
357 numhunksinheader = len(self.header.hunks) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
358 indexofthishunk = self.header.hunks.index(self) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
359 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
360 if (indexofthishunk < numhunksinheader - 1): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
361 nexthunk = self.header.hunks[indexofthishunk + 1] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
362 return nexthunk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
363 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
364 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
365 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
366 def prevsibling(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
367 indexofthishunk = self.header.hunks.index(self) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
368 if indexofthishunk > 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
369 previoushunk = self.header.hunks[indexofthishunk - 1] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
370 return previoushunk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
371 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
372 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
373 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
374 def parentitem(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
375 "return the parent to the current item" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
376 return self.header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
377 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
378 def firstchild(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
379 "return the first child of this item, if one exists. otherwise None." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
380 if len(self.changedlines) > 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
381 return self.changedlines[0] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
382 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
383 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
384 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
385 def lastchild(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
386 "return the last child of this item, if one exists. otherwise None." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
387 if len(self.changedlines) > 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
388 return self.changedlines[-1] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
389 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
390 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
391 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
392 def allchildren(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
393 "return a list of all of the direct children of this node" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
394 return self.changedlines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
395 def countchanges(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
396 """changedlines -> (n+,n-)""" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
397 add = len([l for l in self.changedlines if l.applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
398 and l.prettystr()[0] == '+']) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
399 rem = len([l for l in self.changedlines if l.applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
400 and l.prettystr()[0] == '-']) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
401 return add, rem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
402 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
403 def getfromtoline(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
404 # calculate the number of removed lines converted to context lines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
405 removedconvertedtocontext = self.originalremoved - self.removed |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
406 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
407 contextlen = (len(self.before) + len(self.after) + |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
408 removedconvertedtocontext) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
409 if self.after and self.after[-1] == '\\ no newline at end of file\n': |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
410 contextlen -= 1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
411 fromlen = contextlen + self.removed |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
412 tolen = contextlen + self.added |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
413 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
414 # diffutils manual, section "2.2.2.2 detailed description of unified |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
415 # format": "an empty hunk is considered to end at the line that |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
416 # precedes the hunk." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
417 # |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
418 # so, if either of hunks is empty, decrease its line start. --immerrr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
419 # but only do this if fromline > 0, to avoid having, e.g fromline=-1. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
420 fromline, toline = self.fromline, self.toline |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
421 if fromline != 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
422 if fromlen == 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
423 fromline -= 1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
424 if tolen == 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
425 toline -= 1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
426 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
427 fromtoline = '@@ -%d,%d +%d,%d @@%s\n' % ( |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
428 fromline, fromlen, toline, tolen, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
429 self.proc and (' ' + self.proc)) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
430 return fromtoline |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
431 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
432 def write(self, fp): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
433 # updated self.added/removed, which are used by getfromtoline() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
434 self.added, self.removed = self.countchanges() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
435 fp.write(self.getfromtoline()) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
436 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
437 hunklinelist = [] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
438 # add the following to the list: (1) all applied lines, and |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
439 # (2) all unapplied removal lines (convert these to context lines) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
440 for changedline in self.changedlines: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
441 changedlinestr = changedline.prettystr() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
442 if changedline.applied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
443 hunklinelist.append(changedlinestr) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
444 elif changedlinestr[0] == "-": |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
445 hunklinelist.append(" " + changedlinestr[1:]) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
446 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
447 fp.write(''.join(self.before + hunklinelist + self.after)) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
448 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
449 pretty = write |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
450 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
451 def prettystr(self): |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28638
diff
changeset
|
452 x = stringio() |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
453 self.pretty(x) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
454 return x.getvalue() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
455 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
456 def __getattr__(self, name): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
457 return getattr(self._hunk, name) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
458 def __repr__(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
459 return '<hunk %r@%d>' % (self.filename(), self.fromline) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
460 |
25310
c1f5ef76d1c2
record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents:
24909
diff
changeset
|
461 def filterpatch(ui, chunks, chunkselector, operation=None): |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
462 """interactively filter patch chunks into applied-only chunks""" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
463 |
25359
724421cb4745
record: add default value for operation argument
Laurent Charignon <lcharignon@fb.com>
parents:
25310
diff
changeset
|
464 if operation is None: |
724421cb4745
record: add default value for operation argument
Laurent Charignon <lcharignon@fb.com>
parents:
25310
diff
changeset
|
465 operation = _('confirm') |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
466 chunks = list(chunks) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
467 # convert chunks list into structure suitable for displaying/modifying |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
468 # with curses. create a list of headers only. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
469 headers = [c for c in chunks if isinstance(c, patchmod.header)] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
470 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
471 # if there are no changed files |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
472 if len(headers) == 0: |
27321
dcdf0a52ad36
crecord: add dictionary to default return value of filterpatch
Laurent Charignon <lcharignon@fb.com>
parents:
27156
diff
changeset
|
473 return [], {} |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
474 uiheaders = [uiheader(h) for h in headers] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
475 # let user choose headers/hunks/lines, and mark their applied flags |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
476 # accordingly |
27155
8d3c5797a175
commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents:
26781
diff
changeset
|
477 ret = chunkselector(ui, uiheaders) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
478 appliedhunklist = [] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
479 for hdr in uiheaders: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
480 if (hdr.applied and |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
481 (hdr.special() or len([h for h in hdr.hunks if h.applied]) > 0)): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
482 appliedhunklist.append(hdr) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
483 fixoffset = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
484 for hnk in hdr.hunks: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
485 if hnk.applied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
486 appliedhunklist.append(hnk) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
487 # adjust the 'to'-line offset of the hunk to be correct |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
488 # after de-activating some of the other hunks for this file |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
489 if fixoffset: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
490 #hnk = copy.copy(hnk) # necessary?? |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
491 hnk.toline += fixoffset |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
492 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
493 fixoffset += hnk.removed - hnk.added |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
494 |
27155
8d3c5797a175
commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents:
26781
diff
changeset
|
495 return (appliedhunklist, ret) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
496 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
497 def gethw(): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
498 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
499 magically get the current height and width of the window (without initscr) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
500 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
501 this is a rip-off of a rip-off - taken from the bpython code. it is |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
502 useful / necessary because otherwise curses.initscr() must be called, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
503 which can leave the terminal in a nasty state after exiting. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
504 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
505 h, w = struct.unpack( |
24316
d61aa383e2e5
crecord: fix underbar style for orig_stdout
Matt Mackall <mpm@selenic.com>
parents:
24315
diff
changeset
|
506 "hhhh", fcntl.ioctl(_origstdout, termios.TIOCGWINSZ, "\000"*8))[0:2] |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
507 return h, w |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
508 |
24342
be3ab98f11e0
record: change arguments of curses recording function
Laurent Charignon <lcharignon@fb.com>
parents:
24318
diff
changeset
|
509 def chunkselector(ui, headerlist): |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
510 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
511 curses interface to get selection of chunks, and mark the applied flags |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
512 of the chosen chunks. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
513 """ |
24779
23727465ff72
record: add message when starting record's curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24492
diff
changeset
|
514 ui.write(_('starting interactive selection\n')) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
515 chunkselector = curseschunkselector(headerlist, ui) |
25807
2cccaf937a7a
crecord: fix issue when backgrounding editor would leave artefact
Laurent Charignon <l.charignon@gmail.com>
parents:
25557
diff
changeset
|
516 f = signal.getsignal(signal.SIGTSTP) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
517 curses.wrapper(chunkselector.main) |
25820
701d8c362aa2
crecord: add error reporting for failure in curses interface initialization
Laurent Charignon <lcharignon@fb.com>
parents:
25807
diff
changeset
|
518 if chunkselector.initerr is not None: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26421
diff
changeset
|
519 raise error.Abort(chunkselector.initerr) |
25807
2cccaf937a7a
crecord: fix issue when backgrounding editor would leave artefact
Laurent Charignon <l.charignon@gmail.com>
parents:
25557
diff
changeset
|
520 # ncurses does not restore signal handler for SIGTSTP |
2cccaf937a7a
crecord: fix issue when backgrounding editor would leave artefact
Laurent Charignon <l.charignon@gmail.com>
parents:
25557
diff
changeset
|
521 signal.signal(signal.SIGTSTP, f) |
27155
8d3c5797a175
commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents:
26781
diff
changeset
|
522 return chunkselector.opts |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
523 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
524 def testdecorator(testfn, f): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
525 def u(*args, **kwargs): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
526 return f(testfn, *args, **kwargs) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
527 return u |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
528 |
24342
be3ab98f11e0
record: change arguments of curses recording function
Laurent Charignon <lcharignon@fb.com>
parents:
24318
diff
changeset
|
529 def testchunkselector(testfn, ui, headerlist): |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
530 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
531 test interface to get selection of chunks, and mark the applied flags |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
532 of the chosen chunks. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
533 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
534 chunkselector = curseschunkselector(headerlist, ui) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
535 if testfn and os.path.exists(testfn): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
536 testf = open(testfn) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
537 testcommands = map(lambda x: x.rstrip('\n'), testf.readlines()) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
538 testf.close() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
539 while True: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
540 if chunkselector.handlekeypressed(testcommands.pop(0), test=True): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
541 break |
27155
8d3c5797a175
commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents:
26781
diff
changeset
|
542 return chunkselector.opts |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
543 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
544 class curseschunkselector(object): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
545 def __init__(self, headerlist, ui): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
546 # put the headers into a patch object |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
547 self.headerlist = patch(headerlist) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
548 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
549 self.ui = ui |
27155
8d3c5797a175
commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents:
26781
diff
changeset
|
550 self.opts = {} |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
551 |
25556
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
552 self.errorstr = None |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
553 # list of all chunks |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
554 self.chunklist = [] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
555 for h in headerlist: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
556 self.chunklist.append(h) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
557 self.chunklist.extend(h.hunks) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
558 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
559 # dictionary mapping (fgcolor, bgcolor) pairs to the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
560 # corresponding curses color-pair value. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
561 self.colorpairs = {} |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
562 # maps custom nicknames of color-pairs to curses color-pair values |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
563 self.colorpairnames = {} |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
564 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
565 # the currently selected header, hunk, or hunk-line |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
566 self.currentselecteditem = self.headerlist[0] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
567 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
568 # updated when printing out patch-display -- the 'lines' here are the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
569 # line positions *in the pad*, not on the screen. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
570 self.selecteditemstartline = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
571 self.selecteditemendline = None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
572 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
573 # define indentation levels |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
574 self.headerindentnumchars = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
575 self.hunkindentnumchars = 3 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
576 self.hunklineindentnumchars = 6 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
577 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
578 # the first line of the pad to print to the screen |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
579 self.firstlineofpadtoprint = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
580 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
581 # keeps track of the number of lines in the pad |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
582 self.numpadlines = None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
583 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
584 self.numstatuslines = 2 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
585 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
586 # keep a running count of the number of lines printed to the pad |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
587 # (used for determining when the selected item begins/ends) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
588 self.linesprintedtopadsofar = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
589 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
590 # the first line of the pad which is visible on the screen |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
591 self.firstlineofpadtoprint = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
592 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
593 # stores optional text for a commit comment provided by the user |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
594 self.commenttext = "" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
595 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
596 # if the last 'toggle all' command caused all changes to be applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
597 self.waslasttoggleallapplied = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
598 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
599 def uparrowevent(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
600 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
601 try to select the previous item to the current item that has the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
602 most-indented level. for example, if a hunk is selected, try to select |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
603 the last hunkline of the hunk prior to the selected hunk. or, if |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
604 the first hunkline of a hunk is currently selected, then select the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
605 hunk itself. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
606 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
607 if the currently selected item is already at the top of the screen, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
608 scroll the screen down to show the new-selected item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
609 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
610 currentitem = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
611 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
612 nextitem = currentitem.previtem(constrainlevel=False) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
613 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
614 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
615 # if no parent item (i.e. currentitem is the first header), then |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
616 # no change... |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
617 nextitem = currentitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
618 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
619 self.currentselecteditem = nextitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
620 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
621 def uparrowshiftevent(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
622 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
623 select (if possible) the previous item on the same level as the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
624 currently selected item. otherwise, select (if possible) the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
625 parent-item of the currently selected item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
626 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
627 if the currently selected item is already at the top of the screen, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
628 scroll the screen down to show the new-selected item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
629 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
630 currentitem = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
631 nextitem = currentitem.previtem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
632 # if there's no previous item on this level, try choosing the parent |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
633 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
634 nextitem = currentitem.parentitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
635 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
636 # if no parent item (i.e. currentitem is the first header), then |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
637 # no change... |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
638 nextitem = currentitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
639 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
640 self.currentselecteditem = nextitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
641 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
642 def downarrowevent(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
643 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
644 try to select the next item to the current item that has the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
645 most-indented level. for example, if a hunk is selected, select |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
646 the first hunkline of the selected hunk. or, if the last hunkline of |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
647 a hunk is currently selected, then select the next hunk, if one exists, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
648 or if not, the next header if one exists. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
649 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
650 if the currently selected item is already at the bottom of the screen, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
651 scroll the screen up to show the new-selected item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
652 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
653 #self.startprintline += 1 #debug |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
654 currentitem = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
655 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
656 nextitem = currentitem.nextitem(constrainlevel=False) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
657 # if there's no next item, keep the selection as-is |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
658 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
659 nextitem = currentitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
660 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
661 self.currentselecteditem = nextitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
662 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
663 def downarrowshiftevent(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
664 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
665 if the cursor is already at the bottom chunk, scroll the screen up and |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
666 move the cursor-position to the subsequent chunk. otherwise, only move |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
667 the cursor position down one chunk. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
668 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
669 # todo: update docstring |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
670 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
671 currentitem = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
672 nextitem = currentitem.nextitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
673 # if there's no previous item on this level, try choosing the parent's |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
674 # nextitem. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
675 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
676 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
677 nextitem = currentitem.parentitem().nextitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
678 except AttributeError: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
679 # parentitem returned None, so nextitem() can't be called |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
680 nextitem = None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
681 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
682 # if no next item on parent-level, then no change... |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
683 nextitem = currentitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
684 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
685 self.currentselecteditem = nextitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
686 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
687 def rightarrowevent(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
688 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
689 select (if possible) the first of this item's child-items. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
690 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
691 currentitem = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
692 nextitem = currentitem.firstchild() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
693 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
694 # turn off folding if we want to show a child-item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
695 if currentitem.folded: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
696 self.togglefolded(currentitem) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
697 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
698 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
699 # if no next item on parent-level, then no change... |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
700 nextitem = currentitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
701 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
702 self.currentselecteditem = nextitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
703 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
704 def leftarrowevent(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
705 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
706 if the current item can be folded (i.e. it is an unfolded header or |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
707 hunk), then fold it. otherwise try select (if possible) the parent |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
708 of this item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
709 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
710 currentitem = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
711 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
712 # try to fold the item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
713 if not isinstance(currentitem, uihunkline): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
714 if not currentitem.folded: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
715 self.togglefolded(item=currentitem) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
716 return |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
717 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
718 # if it can't be folded, try to select the parent item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
719 nextitem = currentitem.parentitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
720 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
721 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
722 # if no item on parent-level, then no change... |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
723 nextitem = currentitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
724 if not nextitem.folded: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
725 self.togglefolded(item=nextitem) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
726 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
727 self.currentselecteditem = nextitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
728 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
729 def leftarrowshiftevent(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
730 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
731 select the header of the current item (or fold current item if the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
732 current item is already a header). |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
733 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
734 currentitem = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
735 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
736 if isinstance(currentitem, uiheader): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
737 if not currentitem.folded: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
738 self.togglefolded(item=currentitem) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
739 return |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
740 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
741 # select the parent item recursively until we're at a header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
742 while True: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
743 nextitem = currentitem.parentitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
744 if nextitem is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
745 break |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
746 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
747 currentitem = nextitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
748 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
749 self.currentselecteditem = currentitem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
750 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
751 def updatescroll(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
752 "scroll the screen to fully show the currently-selected" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
753 selstart = self.selecteditemstartline |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
754 selend = self.selecteditemendline |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
755 #selnumlines = selend - selstart |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
756 padstart = self.firstlineofpadtoprint |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
757 padend = padstart + self.yscreensize - self.numstatuslines - 1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
758 # 'buffered' pad start/end values which scroll with a certain |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
759 # top/bottom context margin |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
760 padstartbuffered = padstart + 3 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
761 padendbuffered = padend - 3 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
762 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
763 if selend > padendbuffered: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
764 self.scrolllines(selend - padendbuffered) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
765 elif selstart < padstartbuffered: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
766 # negative values scroll in pgup direction |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
767 self.scrolllines(selstart - padstartbuffered) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
768 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
769 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
770 def scrolllines(self, numlines): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
771 "scroll the screen up (down) by numlines when numlines >0 (<0)." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
772 self.firstlineofpadtoprint += numlines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
773 if self.firstlineofpadtoprint < 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
774 self.firstlineofpadtoprint = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
775 if self.firstlineofpadtoprint > self.numpadlines - 1: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
776 self.firstlineofpadtoprint = self.numpadlines - 1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
777 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
778 def toggleapply(self, item=None): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
779 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
780 toggle the applied flag of the specified item. if no item is specified, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
781 toggle the flag of the currently selected item. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
782 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
783 if item is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
784 item = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
785 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
786 item.applied = not item.applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
787 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
788 if isinstance(item, uiheader): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
789 item.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
790 if item.applied: |
24492
efa094701a05
record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents:
24425
diff
changeset
|
791 # apply all its hunks |
efa094701a05
record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents:
24425
diff
changeset
|
792 for hnk in item.hunks: |
efa094701a05
record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents:
24425
diff
changeset
|
793 hnk.applied = True |
efa094701a05
record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents:
24425
diff
changeset
|
794 # apply all their hunklines |
efa094701a05
record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents:
24425
diff
changeset
|
795 for hunkline in hnk.changedlines: |
efa094701a05
record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents:
24425
diff
changeset
|
796 hunkline.applied = True |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
797 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
798 # un-apply all its hunks |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
799 for hnk in item.hunks: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
800 hnk.applied = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
801 hnk.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
802 # un-apply all their hunklines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
803 for hunkline in hnk.changedlines: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
804 hunkline.applied = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
805 elif isinstance(item, uihunk): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
806 item.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
807 # apply all it's hunklines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
808 for hunkline in item.changedlines: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
809 hunkline.applied = item.applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
810 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
811 siblingappliedstatus = [hnk.applied for hnk in item.header.hunks] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
812 allsiblingsapplied = not (False in siblingappliedstatus) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
813 nosiblingsapplied = not (True in siblingappliedstatus) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
814 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
815 siblingspartialstatus = [hnk.partial for hnk in item.header.hunks] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
816 somesiblingspartial = (True in siblingspartialstatus) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
817 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
818 #cases where applied or partial should be removed from header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
819 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
820 # if no 'sibling' hunks are applied (including this hunk) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
821 if nosiblingsapplied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
822 if not item.header.special(): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
823 item.header.applied = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
824 item.header.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
825 else: # some/all parent siblings are applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
826 item.header.applied = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
827 item.header.partial = (somesiblingspartial or |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
828 not allsiblingsapplied) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
829 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
830 elif isinstance(item, uihunkline): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
831 siblingappliedstatus = [ln.applied for ln in item.hunk.changedlines] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
832 allsiblingsapplied = not (False in siblingappliedstatus) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
833 nosiblingsapplied = not (True in siblingappliedstatus) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
834 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
835 # if no 'sibling' lines are applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
836 if nosiblingsapplied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
837 item.hunk.applied = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
838 item.hunk.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
839 elif allsiblingsapplied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
840 item.hunk.applied = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
841 item.hunk.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
842 else: # some siblings applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
843 item.hunk.applied = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
844 item.hunk.partial = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
845 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
846 parentsiblingsapplied = [hnk.applied for hnk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
847 in item.hunk.header.hunks] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
848 noparentsiblingsapplied = not (True in parentsiblingsapplied) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
849 allparentsiblingsapplied = not (False in parentsiblingsapplied) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
850 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
851 parentsiblingspartial = [hnk.partial for hnk |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
852 in item.hunk.header.hunks] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
853 someparentsiblingspartial = (True in parentsiblingspartial) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
854 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
855 # if all parent hunks are not applied, un-apply header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
856 if noparentsiblingsapplied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
857 if not item.hunk.header.special(): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
858 item.hunk.header.applied = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
859 item.hunk.header.partial = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
860 # set the applied and partial status of the header if needed |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
861 else: # some/all parent siblings are applied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
862 item.hunk.header.applied = True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
863 item.hunk.header.partial = (someparentsiblingspartial or |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
864 not allparentsiblingsapplied) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
865 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
866 def toggleall(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
867 "toggle the applied flag of all items." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
868 if self.waslasttoggleallapplied: # then unapply them this time |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
869 for item in self.headerlist: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
870 if item.applied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
871 self.toggleapply(item) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
872 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
873 for item in self.headerlist: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
874 if not item.applied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
875 self.toggleapply(item) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
876 self.waslasttoggleallapplied = not self.waslasttoggleallapplied |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
877 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
878 def togglefolded(self, item=None, foldparent=False): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
879 "toggle folded flag of specified item (defaults to currently selected)" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
880 if item is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
881 item = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
882 if foldparent or (isinstance(item, uiheader) and item.neverunfolded): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
883 if not isinstance(item, uiheader): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
884 # we need to select the parent item in this case |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
885 self.currentselecteditem = item = item.parentitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
886 elif item.neverunfolded: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
887 item.neverunfolded = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
888 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
889 # also fold any foldable children of the parent/current item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
890 if isinstance(item, uiheader): # the original or 'new' item |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
891 for child in item.allchildren(): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
892 child.folded = not item.folded |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
893 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
894 if isinstance(item, (uiheader, uihunk)): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
895 item.folded = not item.folded |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
896 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
897 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
898 def alignstring(self, instr, window): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
899 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
900 add whitespace to the end of a string in order to make it fill |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
901 the screen in the x direction. the current cursor position is |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
902 taken into account when making this calculation. the string can span |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
903 multiple lines. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
904 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
905 y, xstart = window.getyx() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
906 width = self.xscreensize |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
907 # turn tabs into spaces |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
908 instr = instr.expandtabs(4) |
24351
cdc4f3af2497
crecord: use colwidth instead of ucolwidth
Matt Mackall <mpm@selenic.com>
parents:
24342
diff
changeset
|
909 strwidth = encoding.colwidth(instr) |
24315
7d5f935bd705
crecord: use encoding.ucolwidth
Matt Mackall <mpm@selenic.com>
parents:
24314
diff
changeset
|
910 numspaces = (width - ((strwidth + xstart) % width) - 1) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
911 return instr + " " * numspaces + "\n" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
912 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
913 def printstring(self, window, text, fgcolor=None, bgcolor=None, pair=None, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
914 pairname=None, attrlist=None, towin=True, align=True, showwhtspc=False): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
915 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
916 print the string, text, with the specified colors and attributes, to |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
917 the specified curses window object. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
918 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
919 the foreground and background colors are of the form |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
920 curses.color_xxxx, where xxxx is one of: [black, blue, cyan, green, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
921 magenta, red, white, yellow]. if pairname is provided, a color |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
922 pair will be looked up in the self.colorpairnames dictionary. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
923 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
924 attrlist is a list containing text attributes in the form of |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
925 curses.a_xxxx, where xxxx can be: [bold, dim, normal, standout, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
926 underline]. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
927 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
928 if align == True, whitespace is added to the printed string such that |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
929 the string stretches to the right border of the window. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
930 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
931 if showwhtspc == True, trailing whitespace of a string is highlighted. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
932 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
933 # preprocess the text, converting tabs to spaces |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
934 text = text.expandtabs(4) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
935 # strip \n, and convert control characters to ^[char] representation |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
936 text = re.sub(r'[\x00-\x08\x0a-\x1f]', |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
937 lambda m:'^' + chr(ord(m.group()) + 64), text.strip('\n')) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
938 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
939 if pair is not None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
940 colorpair = pair |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
941 elif pairname is not None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
942 colorpair = self.colorpairnames[pairname] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
943 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
944 if fgcolor is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
945 fgcolor = -1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
946 if bgcolor is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
947 bgcolor = -1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
948 if (fgcolor, bgcolor) in self.colorpairs: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
949 colorpair = self.colorpairs[(fgcolor, bgcolor)] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
950 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
951 colorpair = self.getcolorpair(fgcolor, bgcolor) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
952 # add attributes if possible |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
953 if attrlist is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
954 attrlist = [] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
955 if colorpair < 256: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
956 # then it is safe to apply all attributes |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
957 for textattr in attrlist: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
958 colorpair |= textattr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
959 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
960 # just apply a select few (safe?) attributes |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
961 for textattr in (curses.A_UNDERLINE, curses.A_BOLD): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
962 if textattr in attrlist: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
963 colorpair |= textattr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
964 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
965 y, xstart = self.chunkpad.getyx() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
966 t = "" # variable for counting lines printed |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
967 # if requested, show trailing whitespace |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
968 if showwhtspc: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
969 origlen = len(text) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
970 text = text.rstrip(' \n') # tabs have already been expanded |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
971 strippedlen = len(text) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
972 numtrailingspaces = origlen - strippedlen |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
973 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
974 if towin: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
975 window.addstr(text, colorpair) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
976 t += text |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
977 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
978 if showwhtspc: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
979 wscolorpair = colorpair | curses.A_REVERSE |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
980 if towin: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
981 for i in range(numtrailingspaces): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
982 window.addch(curses.ACS_CKBOARD, wscolorpair) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
983 t += " " * numtrailingspaces |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
984 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
985 if align: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
986 if towin: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
987 extrawhitespace = self.alignstring("", window) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
988 window.addstr(extrawhitespace, colorpair) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
989 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
990 # need to use t, since the x position hasn't incremented |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
991 extrawhitespace = self.alignstring(t, window) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
992 t += extrawhitespace |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
993 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
994 # is reset to 0 at the beginning of printitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
995 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
996 linesprinted = (xstart + len(t)) / self.xscreensize |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
997 self.linesprintedtopadsofar += linesprinted |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
998 return t |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
999 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1000 def updatescreen(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1001 self.statuswin.erase() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1002 self.chunkpad.erase() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1003 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1004 printstring = self.printstring |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1005 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1006 # print out the status lines at the top |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1007 try: |
25556
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1008 if self.errorstr is not None: |
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1009 printstring(self.statuswin, self.errorstr, pairname='legend') |
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1010 printstring(self.statuswin, 'Press any key to continue', |
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1011 pairname='legend') |
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1012 self.statuswin.refresh() |
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1013 return |
27937
3d3b4ac369f2
crecord: fix help bar display issue (issue5063)
Laurent Charignon <lcharignon@fb.com>
parents:
27936
diff
changeset
|
1014 line1 = ("SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; " |
3d3b4ac369f2
crecord: fix help bar display issue (issue5063)
Laurent Charignon <lcharignon@fb.com>
parents:
27936
diff
changeset
|
1015 "(space/A) toggle hunk/all; (e)dit hunk;") |
3d3b4ac369f2
crecord: fix help bar display issue (issue5063)
Laurent Charignon <lcharignon@fb.com>
parents:
27936
diff
changeset
|
1016 line2 = (" (f)old/unfold; (c)onfirm applied; (q)uit; (?) help " |
3d3b4ac369f2
crecord: fix help bar display issue (issue5063)
Laurent Charignon <lcharignon@fb.com>
parents:
27936
diff
changeset
|
1017 "| [X]=hunk applied **=folded, toggle [a]mend mode") |
3d3b4ac369f2
crecord: fix help bar display issue (issue5063)
Laurent Charignon <lcharignon@fb.com>
parents:
27936
diff
changeset
|
1018 |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1019 printstring(self.statuswin, |
27937
3d3b4ac369f2
crecord: fix help bar display issue (issue5063)
Laurent Charignon <lcharignon@fb.com>
parents:
27936
diff
changeset
|
1020 util.ellipsis(line1, self.xscreensize - 1), |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1021 pairname="legend") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1022 printstring(self.statuswin, |
27937
3d3b4ac369f2
crecord: fix help bar display issue (issue5063)
Laurent Charignon <lcharignon@fb.com>
parents:
27936
diff
changeset
|
1023 util.ellipsis(line2, self.xscreensize - 1), |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1024 pairname="legend") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1025 except curses.error: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1026 pass |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1027 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1028 # print out the patch in the remaining part of the window |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1029 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1030 self.printitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1031 self.updatescroll() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1032 self.chunkpad.refresh(self.firstlineofpadtoprint, 0, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1033 self.numstatuslines, 0, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1034 self.yscreensize + 1 - self.numstatuslines, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1035 self.xscreensize) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1036 except curses.error: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1037 pass |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1038 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1039 # refresh([pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol]) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1040 self.statuswin.refresh() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1041 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1042 def getstatusprefixstring(self, item): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1043 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1044 create a string to prefix a line with which indicates whether 'item' |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1045 is applied and/or folded. |
28579
f571ea254f75
crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents:
28543
diff
changeset
|
1046 """ |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1047 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1048 # create checkbox string |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1049 if item.applied: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1050 if not isinstance(item, uihunkline) and item.partial: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1051 checkbox = "[~]" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1052 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1053 checkbox = "[x]" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1054 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1055 checkbox = "[ ]" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1056 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1057 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1058 if item.folded: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1059 checkbox += "**" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1060 if isinstance(item, uiheader): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1061 # one of "m", "a", or "d" (modified, added, deleted) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1062 filestatus = item.changetype |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1063 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1064 checkbox += filestatus + " " |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1065 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1066 checkbox += " " |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1067 if isinstance(item, uiheader): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1068 # add two more spaces for headers |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1069 checkbox += " " |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1070 except AttributeError: # not foldable |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1071 checkbox += " " |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1072 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1073 return checkbox |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1074 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1075 def printheader(self, header, selected=False, towin=True, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1076 ignorefolding=False): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1077 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1078 print the header to the pad. if countlines is True, don't print |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1079 anything, but just count the number of lines which would be printed. |
28579
f571ea254f75
crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents:
28543
diff
changeset
|
1080 """ |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1081 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1082 outstr = "" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1083 text = header.prettystr() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1084 chunkindex = self.chunklist.index(header) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1085 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1086 if chunkindex != 0 and not header.folded: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1087 # add separating line before headers |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1088 outstr += self.printstring(self.chunkpad, '_' * self.xscreensize, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1089 towin=towin, align=False) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1090 # select color-pair based on if the header is selected |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1091 colorpair = self.getcolorpair(name=selected and "selected" or "normal", |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1092 attrlist=[curses.A_BOLD]) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1093 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1094 # print out each line of the chunk, expanding it to screen width |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1095 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1096 # number of characters to indent lines on this level by |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1097 indentnumchars = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1098 checkbox = self.getstatusprefixstring(header) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1099 if not header.folded or ignorefolding: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1100 textlist = text.split("\n") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1101 linestr = checkbox + textlist[0] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1102 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1103 linestr = checkbox + header.filename() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1104 outstr += self.printstring(self.chunkpad, linestr, pair=colorpair, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1105 towin=towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1106 if not header.folded or ignorefolding: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1107 if len(textlist) > 1: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1108 for line in textlist[1:]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1109 linestr = " "*(indentnumchars + len(checkbox)) + line |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1110 outstr += self.printstring(self.chunkpad, linestr, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1111 pair=colorpair, towin=towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1112 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1113 return outstr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1114 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1115 def printhunklinesbefore(self, hunk, selected=False, towin=True, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1116 ignorefolding=False): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1117 "includes start/end line indicator" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1118 outstr = "" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1119 # where hunk is in list of siblings |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1120 hunkindex = hunk.header.hunks.index(hunk) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1121 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1122 if hunkindex != 0: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1123 # add separating line before headers |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1124 outstr += self.printstring(self.chunkpad, ' '*self.xscreensize, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1125 towin=towin, align=False) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1126 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1127 colorpair = self.getcolorpair(name=selected and "selected" or "normal", |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1128 attrlist=[curses.A_BOLD]) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1129 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1130 # print out from-to line with checkbox |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1131 checkbox = self.getstatusprefixstring(hunk) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1132 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1133 lineprefix = " "*self.hunkindentnumchars + checkbox |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1134 frtoline = " " + hunk.getfromtoline().strip("\n") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1135 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1136 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1137 outstr += self.printstring(self.chunkpad, lineprefix, towin=towin, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1138 align=False) # add uncolored checkbox/indent |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1139 outstr += self.printstring(self.chunkpad, frtoline, pair=colorpair, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1140 towin=towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1141 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1142 if hunk.folded and not ignorefolding: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1143 # skip remainder of output |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1144 return outstr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1145 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1146 # print out lines of the chunk preceeding changed-lines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1147 for line in hunk.before: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1148 linestr = " "*(self.hunklineindentnumchars + len(checkbox)) + line |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1149 outstr += self.printstring(self.chunkpad, linestr, towin=towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1150 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1151 return outstr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1152 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1153 def printhunklinesafter(self, hunk, towin=True, ignorefolding=False): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1154 outstr = "" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1155 if hunk.folded and not ignorefolding: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1156 return outstr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1157 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1158 # a bit superfluous, but to avoid hard-coding indent amount |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1159 checkbox = self.getstatusprefixstring(hunk) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1160 for line in hunk.after: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1161 linestr = " "*(self.hunklineindentnumchars + len(checkbox)) + line |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1162 outstr += self.printstring(self.chunkpad, linestr, towin=towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1163 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1164 return outstr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1165 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1166 def printhunkchangedline(self, hunkline, selected=False, towin=True): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1167 outstr = "" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1168 checkbox = self.getstatusprefixstring(hunkline) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1169 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1170 linestr = hunkline.prettystr().strip("\n") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1171 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1172 # select color-pair based on whether line is an addition/removal |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1173 if selected: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1174 colorpair = self.getcolorpair(name="selected") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1175 elif linestr.startswith("+"): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1176 colorpair = self.getcolorpair(name="addition") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1177 elif linestr.startswith("-"): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1178 colorpair = self.getcolorpair(name="deletion") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1179 elif linestr.startswith("\\"): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1180 colorpair = self.getcolorpair(name="normal") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1181 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1182 lineprefix = " "*self.hunklineindentnumchars + checkbox |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1183 outstr += self.printstring(self.chunkpad, lineprefix, towin=towin, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1184 align=False) # add uncolored checkbox/indent |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1185 outstr += self.printstring(self.chunkpad, linestr, pair=colorpair, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1186 towin=towin, showwhtspc=True) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1187 return outstr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1188 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1189 def printitem(self, item=None, ignorefolding=False, recursechildren=True, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1190 towin=True): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1191 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1192 use __printitem() to print the the specified item.applied. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1193 if item is not specified, then print the entire patch. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1194 (hiding folded elements, etc. -- see __printitem() docstring) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1195 """ |
28579
f571ea254f75
crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents:
28543
diff
changeset
|
1196 |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1197 if item is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1198 item = self.headerlist |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1199 if recursechildren: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1200 self.linesprintedtopadsofar = 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1201 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1202 outstr = [] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1203 self.__printitem(item, ignorefolding, recursechildren, outstr, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1204 towin=towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1205 return ''.join(outstr) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1206 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1207 def outofdisplayedarea(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1208 y, _ = self.chunkpad.getyx() # cursor location |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1209 # * 2 here works but an optimization would be the max number of |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1210 # consecutive non selectable lines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1211 # i.e the max number of context line for any hunk in the patch |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1212 miny = min(0, self.firstlineofpadtoprint - self.yscreensize) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1213 maxy = self.firstlineofpadtoprint + self.yscreensize * 2 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1214 return y < miny or y > maxy |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1215 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1216 def handleselection(self, item, recursechildren): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1217 selected = (item is self.currentselecteditem) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1218 if selected and recursechildren: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1219 # assumes line numbering starting from line 0 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1220 self.selecteditemstartline = self.linesprintedtopadsofar |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1221 selecteditemlines = self.getnumlinesdisplayed(item, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1222 recursechildren=False) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1223 self.selecteditemendline = (self.selecteditemstartline + |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1224 selecteditemlines - 1) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1225 return selected |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1226 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1227 def __printitem(self, item, ignorefolding, recursechildren, outstr, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1228 towin=True): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1229 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1230 recursive method for printing out patch/header/hunk/hunk-line data to |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1231 screen. also returns a string with all of the content of the displayed |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1232 patch (not including coloring, etc.). |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1233 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1234 if ignorefolding is True, then folded items are printed out. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1235 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1236 if recursechildren is False, then only print the item without its |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1237 child items. |
28579
f571ea254f75
crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents:
28543
diff
changeset
|
1238 """ |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1239 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1240 if towin and self.outofdisplayedarea(): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1241 return |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1242 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1243 selected = self.handleselection(item, recursechildren) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1244 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1245 # patch object is a list of headers |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1246 if isinstance(item, patch): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1247 if recursechildren: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1248 for hdr in item: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1249 self.__printitem(hdr, ignorefolding, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1250 recursechildren, outstr, towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1251 # todo: eliminate all isinstance() calls |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1252 if isinstance(item, uiheader): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1253 outstr.append(self.printheader(item, selected, towin=towin, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1254 ignorefolding=ignorefolding)) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1255 if recursechildren: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1256 for hnk in item.hunks: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1257 self.__printitem(hnk, ignorefolding, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1258 recursechildren, outstr, towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1259 elif (isinstance(item, uihunk) and |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1260 ((not item.header.folded) or ignorefolding)): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1261 # print the hunk data which comes before the changed-lines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1262 outstr.append(self.printhunklinesbefore(item, selected, towin=towin, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1263 ignorefolding=ignorefolding)) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1264 if recursechildren: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1265 for l in item.changedlines: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1266 self.__printitem(l, ignorefolding, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1267 recursechildren, outstr, towin) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1268 outstr.append(self.printhunklinesafter(item, towin=towin, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1269 ignorefolding=ignorefolding)) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1270 elif (isinstance(item, uihunkline) and |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1271 ((not item.hunk.folded) or ignorefolding)): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1272 outstr.append(self.printhunkchangedline(item, selected, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1273 towin=towin)) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1274 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1275 return outstr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1276 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1277 def getnumlinesdisplayed(self, item=None, ignorefolding=False, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1278 recursechildren=True): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1279 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1280 return the number of lines which would be displayed if the item were |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1281 to be printed to the display. the item will not be printed to the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1282 display (pad). |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1283 if no item is given, assume the entire patch. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1284 if ignorefolding is True, folded items will be unfolded when counting |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1285 the number of lines. |
28579
f571ea254f75
crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents:
28543
diff
changeset
|
1286 """ |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1287 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1288 # temporarily disable printing to windows by printstring |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1289 patchdisplaystring = self.printitem(item, ignorefolding, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1290 recursechildren, towin=False) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1291 numlines = len(patchdisplaystring) / self.xscreensize |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1292 return numlines |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1293 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1294 def sigwinchhandler(self, n, frame): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1295 "handle window resizing" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1296 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1297 curses.endwin() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1298 self.yscreensize, self.xscreensize = gethw() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1299 self.statuswin.resize(self.numstatuslines, self.xscreensize) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1300 self.numpadlines = self.getnumlinesdisplayed(ignorefolding=True) + 1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1301 self.chunkpad = curses.newpad(self.numpadlines, self.xscreensize) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1302 # todo: try to resize commit message window if possible |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1303 except curses.error: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1304 pass |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1305 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1306 def getcolorpair(self, fgcolor=None, bgcolor=None, name=None, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1307 attrlist=None): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1308 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1309 get a curses color pair, adding it to self.colorpairs if it is not |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1310 already defined. an optional string, name, can be passed as a shortcut |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1311 for referring to the color-pair. by default, if no arguments are |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1312 specified, the white foreground / black background color-pair is |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1313 returned. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1314 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1315 it is expected that this function will be used exclusively for |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1316 initializing color pairs, and not curses.init_pair(). |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1317 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1318 attrlist is used to 'flavor' the returned color-pair. this information |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1319 is not stored in self.colorpairs. it contains attribute values like |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1320 curses.A_BOLD. |
28579
f571ea254f75
crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents:
28543
diff
changeset
|
1321 """ |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1322 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1323 if (name is not None) and name in self.colorpairnames: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1324 # then get the associated color pair and return it |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1325 colorpair = self.colorpairnames[name] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1326 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1327 if fgcolor is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1328 fgcolor = -1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1329 if bgcolor is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1330 bgcolor = -1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1331 if (fgcolor, bgcolor) in self.colorpairs: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1332 colorpair = self.colorpairs[(fgcolor, bgcolor)] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1333 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1334 pairindex = len(self.colorpairs) + 1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1335 curses.init_pair(pairindex, fgcolor, bgcolor) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1336 colorpair = self.colorpairs[(fgcolor, bgcolor)] = ( |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1337 curses.color_pair(pairindex)) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1338 if name is not None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1339 self.colorpairnames[name] = curses.color_pair(pairindex) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1340 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1341 # add attributes if possible |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1342 if attrlist is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1343 attrlist = [] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1344 if colorpair < 256: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1345 # then it is safe to apply all attributes |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1346 for textattr in attrlist: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1347 colorpair |= textattr |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1348 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1349 # just apply a select few (safe?) attributes |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1350 for textattrib in (curses.A_UNDERLINE, curses.A_BOLD): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1351 if textattrib in attrlist: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1352 colorpair |= textattrib |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1353 return colorpair |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1354 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1355 def initcolorpair(self, *args, **kwargs): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1356 "same as getcolorpair." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1357 self.getcolorpair(*args, **kwargs) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1358 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1359 def helpwindow(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1360 "print a help window to the screen. exit after any keypress." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1361 helptext = """ [press any key to return to the patch-display] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1362 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1363 crecord allows you to interactively choose among the changes you have made, |
24840
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1364 and confirm only those changes you select for further processing by the command |
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1365 you are running (commit/shelve/revert), after confirming the selected |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1366 changes, the unselected changes are still present in your working copy, so you |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1367 can use crecord multiple times to split large changes into smaller changesets. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1368 the following are valid keystrokes: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1369 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1370 [space] : (un-)select item ([~]/[x] = partly/fully applied) |
27936
fedd81659643
crecord: fix typo in the help text
Laurent Charignon <lcharignon@fb.com>
parents:
27914
diff
changeset
|
1371 A : (un-)select all items |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1372 up/down-arrow [k/j] : go to previous/next unfolded item |
25460
bd4bcfa48c9e
crecord: fix three typos introduced while moving crecord into core
Laurent Charignon <lcharignon@fb.com>
parents:
25447
diff
changeset
|
1373 pgup/pgdn [K/J] : go to previous/next item of same type |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1374 right/left-arrow [l/h] : go to child item / parent item |
25460
bd4bcfa48c9e
crecord: fix three typos introduced while moving crecord into core
Laurent Charignon <lcharignon@fb.com>
parents:
25447
diff
changeset
|
1375 shift-left-arrow [H] : go to parent header / fold selected header |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1376 f : fold / unfold item, hiding/revealing its children |
25447
093d38165e5a
crecord: fix a typo introduced when moving crecord to core
Laurent Charignon <lcharignon@fb.com>
parents:
24840
diff
changeset
|
1377 F : fold / unfold parent item and all of its ancestors |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1378 m : edit / resume editing the commit message |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1379 e : edit the currently selected hunk |
27156
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1380 a : toggle amend mode (hg rev >= 2.2), only with commit -i |
24840
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1381 c : confirm selected changes |
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1382 r : review/edit and confirm selected changes |
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1383 q : quit without confirming (no changes will be made) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1384 ? : help (what you're currently reading)""" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1385 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1386 helpwin = curses.newwin(self.yscreensize, 0, 0, 0) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1387 helplines = helptext.split("\n") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1388 helplines = helplines + [" "]*( |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1389 self.yscreensize - self.numstatuslines - len(helplines) - 1) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1390 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1391 for line in helplines: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1392 self.printstring(helpwin, line, pairname="legend") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1393 except curses.error: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1394 pass |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1395 helpwin.refresh() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1396 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1397 helpwin.getkey() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1398 except curses.error: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1399 pass |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1400 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1401 def confirmationwindow(self, windowtext): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1402 "display an informational window, then wait for and return a keypress." |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1403 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1404 confirmwin = curses.newwin(self.yscreensize, 0, 0, 0) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1405 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1406 lines = windowtext.split("\n") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1407 for line in lines: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1408 self.printstring(confirmwin, line, pairname="selected") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1409 except curses.error: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1410 pass |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1411 self.stdscr.refresh() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1412 confirmwin.refresh() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1413 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1414 response = chr(self.stdscr.getch()) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1415 except ValueError: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1416 response = None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1417 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1418 return response |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1419 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1420 def confirmcommit(self, review=False): |
24840
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1421 """ask for 'y' to be pressed to confirm selected. return True if |
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1422 confirmed.""" |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1423 if review: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1424 confirmtext = ( |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1425 """if you answer yes to the following, the your currently chosen patch chunks |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1426 will be loaded into an editor. you may modify the patch from the editor, and |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1427 save the changes if you wish to change the patch. otherwise, you can just |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1428 close the editor without saving to accept the current patch as-is. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1429 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1430 note: don't add/remove lines unless you also modify the range information. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1431 failing to follow this rule will result in the commit aborting. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1432 |
24840
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1433 are you sure you want to review/edit and confirm the selected changes [yn]? |
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1434 """) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1435 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1436 confirmtext = ( |
24840
a5e3634ba024
record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents:
24779
diff
changeset
|
1437 "are you sure you want to confirm the selected changes [yn]? ") |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1438 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1439 response = self.confirmationwindow(confirmtext) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1440 if response is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1441 response = "n" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1442 if response.lower().startswith("y"): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1443 return True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1444 else: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1445 return False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1446 |
27156
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1447 def toggleamend(self, opts, test): |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1448 """Toggle the amend flag. |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1449 |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1450 When the amend flag is set, a commit will modify the most recently |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1451 committed changeset, instead of creating a new changeset. Otherwise, a |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1452 new changeset will be created (the normal commit behavior). |
28579
f571ea254f75
crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents:
28543
diff
changeset
|
1453 """ |
27156
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1454 |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1455 try: |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1456 ver = float(util.version()[:3]) |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1457 except ValueError: |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1458 ver = 1 |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1459 if ver < 2.19: |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1460 msg = ("The amend option is unavailable with hg versions < 2.2\n\n" |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1461 "Press any key to continue.") |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1462 elif opts.get('amend') is None: |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1463 opts['amend'] = True |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1464 msg = ("Amend option is turned on -- commiting the currently " |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1465 "selected changes will not create a new changeset, but " |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1466 "instead update the most recently committed changeset.\n\n" |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1467 "Press any key to continue.") |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1468 elif opts.get('amend') is True: |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1469 opts['amend'] = None |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1470 msg = ("Amend option is turned off -- commiting the currently " |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1471 "selected changes will create a new changeset.\n\n" |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1472 "Press any key to continue.") |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1473 if not test: |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1474 self.confirmationwindow(msg) |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1475 |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1476 def recenterdisplayedarea(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1477 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1478 once we scrolled with pg up pg down we can be pointing outside of the |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1479 display zone. we print the patch with towin=False to compute the |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26587
diff
changeset
|
1480 location of the selected item even though it is outside of the displayed |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1481 zone and then update the scroll. |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1482 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1483 self.printitem(towin=False) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1484 self.updatescroll() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1485 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1486 def toggleedit(self, item=None, test=False): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1487 """ |
28580
8b41ad798fb7
crecord: fix docblock indentation
Ryan McElroy <rmcelroy@fb.com>
parents:
28579
diff
changeset
|
1488 edit the currently selected chunk |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1489 """ |
25555
838fa1932ff8
crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents:
25461
diff
changeset
|
1490 def updateui(self): |
838fa1932ff8
crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents:
25461
diff
changeset
|
1491 self.numpadlines = self.getnumlinesdisplayed(ignorefolding=True) + 1 |
838fa1932ff8
crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents:
25461
diff
changeset
|
1492 self.chunkpad = curses.newpad(self.numpadlines, self.xscreensize) |
838fa1932ff8
crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents:
25461
diff
changeset
|
1493 self.updatescroll() |
838fa1932ff8
crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents:
25461
diff
changeset
|
1494 self.stdscr.refresh() |
838fa1932ff8
crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents:
25461
diff
changeset
|
1495 self.statuswin.refresh() |
838fa1932ff8
crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents:
25461
diff
changeset
|
1496 self.stdscr.keypad(1) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1497 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1498 def editpatchwitheditor(self, chunk): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1499 if chunk is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1500 self.ui.write(_('cannot edit patch for whole file')) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1501 self.ui.write("\n") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1502 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1503 if chunk.header.binary(): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1504 self.ui.write(_('cannot edit patch for binary file')) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1505 self.ui.write("\n") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1506 return None |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1507 |
28636
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1508 # write the initial patch |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28638
diff
changeset
|
1509 patch = stringio() |
28637
4874b8efe7d2
crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28636
diff
changeset
|
1510 patch.write(diffhelptext + hunkhelptext) |
28636
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1511 chunk.header.write(patch) |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1512 chunk.write(patch) |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1513 |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1514 # start the editor and wait for it to complete |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1515 try: |
28636
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1516 patch = self.ui.edit(patch.getvalue(), "", |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1517 extra={"suffix": ".diff"}) |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1518 except error.Abort as exc: |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1519 self.errorstr = str(exc) |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1520 return None |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1521 |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1522 # remove comment lines |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1523 patch = [line + '\n' for line in patch.splitlines() |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1524 if not line.startswith('#')] |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1525 return patchmod.parsepatch(patch) |
de64020bb4ec
crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28581
diff
changeset
|
1526 |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1527 if item is None: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1528 item = self.currentselecteditem |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1529 if isinstance(item, uiheader): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1530 return |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1531 if isinstance(item, uihunkline): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1532 item = item.parentitem() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1533 if not isinstance(item, uihunk): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1534 return |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1535 |
27914
505a10b504ed
crecord: edit during hg crecord should preserve cursor position (issue5041)
Laurent Charignon <lcharignon@fb.com>
parents:
27533
diff
changeset
|
1536 # To go back to that hunk or its replacement at the end of the edit |
505a10b504ed
crecord: edit during hg crecord should preserve cursor position (issue5041)
Laurent Charignon <lcharignon@fb.com>
parents:
27533
diff
changeset
|
1537 itemindex = item.parentitem().hunks.index(item) |
505a10b504ed
crecord: edit during hg crecord should preserve cursor position (issue5041)
Laurent Charignon <lcharignon@fb.com>
parents:
27533
diff
changeset
|
1538 |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1539 beforeadded, beforeremoved = item.added, item.removed |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1540 newpatches = editpatchwitheditor(self, item) |
25557
52c552a05414
crecord: exit edition of hunk with non-zero status does not interrupt session
Laurent Charignon <lcharignon@fb.com>
parents:
25556
diff
changeset
|
1541 if newpatches is None: |
52c552a05414
crecord: exit edition of hunk with non-zero status does not interrupt session
Laurent Charignon <lcharignon@fb.com>
parents:
25556
diff
changeset
|
1542 if not test: |
52c552a05414
crecord: exit edition of hunk with non-zero status does not interrupt session
Laurent Charignon <lcharignon@fb.com>
parents:
25556
diff
changeset
|
1543 updateui(self) |
52c552a05414
crecord: exit edition of hunk with non-zero status does not interrupt session
Laurent Charignon <lcharignon@fb.com>
parents:
25556
diff
changeset
|
1544 return |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1545 header = item.header |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1546 editedhunkindex = header.hunks.index(item) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1547 hunksbefore = header.hunks[:editedhunkindex] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1548 hunksafter = header.hunks[editedhunkindex + 1:] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1549 newpatchheader = newpatches[0] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1550 newhunks = [uihunk(h, header) for h in newpatchheader.hunks] |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1551 newadded = sum([h.added for h in newhunks]) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1552 newremoved = sum([h.removed for h in newhunks]) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1553 offset = (newadded - beforeadded) - (newremoved - beforeremoved) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1554 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1555 for h in hunksafter: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1556 h.toline += offset |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1557 for h in newhunks: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1558 h.folded = False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1559 header.hunks = hunksbefore + newhunks + hunksafter |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1560 if self.emptypatch(): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1561 header.hunks = hunksbefore + [item] + hunksafter |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1562 self.currentselecteditem = header |
27914
505a10b504ed
crecord: edit during hg crecord should preserve cursor position (issue5041)
Laurent Charignon <lcharignon@fb.com>
parents:
27533
diff
changeset
|
1563 if len(header.hunks) > itemindex: |
505a10b504ed
crecord: edit during hg crecord should preserve cursor position (issue5041)
Laurent Charignon <lcharignon@fb.com>
parents:
27533
diff
changeset
|
1564 self.currentselecteditem = header.hunks[itemindex] |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1565 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1566 if not test: |
25555
838fa1932ff8
crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents:
25461
diff
changeset
|
1567 updateui(self) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1568 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1569 def emptypatch(self): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1570 item = self.headerlist |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1571 if not item: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1572 return True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1573 for header in item: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1574 if header.hunks: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1575 return False |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1576 return True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1577 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1578 def handlekeypressed(self, keypressed, test=False): |
28581
3c8f0a605504
crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents:
28580
diff
changeset
|
1579 """ |
3c8f0a605504
crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents:
28580
diff
changeset
|
1580 Perform actions based on pressed keys. |
3c8f0a605504
crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents:
28580
diff
changeset
|
1581 |
3c8f0a605504
crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents:
28580
diff
changeset
|
1582 Return true to exit the main loop. |
3c8f0a605504
crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents:
28580
diff
changeset
|
1583 """ |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1584 if keypressed in ["k", "KEY_UP"]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1585 self.uparrowevent() |
25460
bd4bcfa48c9e
crecord: fix three typos introduced while moving crecord into core
Laurent Charignon <lcharignon@fb.com>
parents:
25447
diff
changeset
|
1586 if keypressed in ["K", "KEY_PPAGE"]: |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1587 self.uparrowshiftevent() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1588 elif keypressed in ["j", "KEY_DOWN"]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1589 self.downarrowevent() |
25460
bd4bcfa48c9e
crecord: fix three typos introduced while moving crecord into core
Laurent Charignon <lcharignon@fb.com>
parents:
25447
diff
changeset
|
1590 elif keypressed in ["J", "KEY_NPAGE"]: |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1591 self.downarrowshiftevent() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1592 elif keypressed in ["l", "KEY_RIGHT"]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1593 self.rightarrowevent() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1594 elif keypressed in ["h", "KEY_LEFT"]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1595 self.leftarrowevent() |
25460
bd4bcfa48c9e
crecord: fix three typos introduced while moving crecord into core
Laurent Charignon <lcharignon@fb.com>
parents:
25447
diff
changeset
|
1596 elif keypressed in ["H", "KEY_SLEFT"]: |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1597 self.leftarrowshiftevent() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1598 elif keypressed in ["q"]: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26421
diff
changeset
|
1599 raise error.Abort(_('user quit')) |
27156
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1600 elif keypressed in ['a']: |
55fa7c3900ae
commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents:
27155
diff
changeset
|
1601 self.toggleamend(self.opts, test) |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1602 elif keypressed in ["c"]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1603 if self.confirmcommit(): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1604 return True |
28638
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
1605 elif test and keypressed in ['X']: |
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
1606 return True |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1607 elif keypressed in ["r"]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1608 if self.confirmcommit(review=True): |
28638
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
1609 self.opts['review'] = True |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1610 return True |
28638
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
1611 elif test and keypressed in ['R']: |
44319097e7b9
crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
28637
diff
changeset
|
1612 self.opts['review'] = True |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1613 return True |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1614 elif keypressed in [' '] or (test and keypressed in ["TOGGLE"]): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1615 self.toggleapply() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1616 elif keypressed in ['A']: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1617 self.toggleall() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1618 elif keypressed in ['e']: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1619 self.toggleedit(test=test) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1620 elif keypressed in ["f"]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1621 self.togglefolded() |
25447
093d38165e5a
crecord: fix a typo introduced when moving crecord to core
Laurent Charignon <lcharignon@fb.com>
parents:
24840
diff
changeset
|
1622 elif keypressed in ["F"]: |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1623 self.togglefolded(foldparent=True) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1624 elif keypressed in ["?"]: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1625 self.helpwindow() |
25419
6e62a5b3442d
crecord: fix blue artifact bug coming back from help screen
Laurent Charignon <lcharignon@fb.com>
parents:
25359
diff
changeset
|
1626 self.stdscr.clear() |
6e62a5b3442d
crecord: fix blue artifact bug coming back from help screen
Laurent Charignon <lcharignon@fb.com>
parents:
25359
diff
changeset
|
1627 self.stdscr.refresh() |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1628 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1629 def main(self, stdscr): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1630 """ |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1631 method to be wrapped by curses.wrapper() for selecting chunks. |
28579
f571ea254f75
crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents:
28543
diff
changeset
|
1632 """ |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1633 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1634 signal.signal(signal.SIGWINCH, self.sigwinchhandler) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1635 self.stdscr = stdscr |
25820
701d8c362aa2
crecord: add error reporting for failure in curses interface initialization
Laurent Charignon <lcharignon@fb.com>
parents:
25807
diff
changeset
|
1636 # error during initialization, cannot be printed in the curses |
701d8c362aa2
crecord: add error reporting for failure in curses interface initialization
Laurent Charignon <lcharignon@fb.com>
parents:
25807
diff
changeset
|
1637 # interface, it should be printed by the calling code |
701d8c362aa2
crecord: add error reporting for failure in curses interface initialization
Laurent Charignon <lcharignon@fb.com>
parents:
25807
diff
changeset
|
1638 self.initerr = None |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1639 self.yscreensize, self.xscreensize = self.stdscr.getmaxyx() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1640 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1641 curses.start_color() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1642 curses.use_default_colors() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1643 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1644 # available colors: black, blue, cyan, green, magenta, white, yellow |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1645 # init_pair(color_id, foreground_color, background_color) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1646 self.initcolorpair(None, None, name="normal") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1647 self.initcolorpair(curses.COLOR_WHITE, curses.COLOR_MAGENTA, |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1648 name="selected") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1649 self.initcolorpair(curses.COLOR_RED, None, name="deletion") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1650 self.initcolorpair(curses.COLOR_GREEN, None, name="addition") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1651 self.initcolorpair(curses.COLOR_WHITE, curses.COLOR_BLUE, name="legend") |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1652 # newwin([height, width,] begin_y, begin_x) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1653 self.statuswin = curses.newwin(self.numstatuslines, 0, 0, 0) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1654 self.statuswin.keypad(1) # interpret arrow-key, etc. esc sequences |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1655 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1656 # figure out how much space to allocate for the chunk-pad which is |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1657 # used for displaying the patch |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1658 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1659 # stupid hack to prevent getnumlinesdisplayed from failing |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1660 self.chunkpad = curses.newpad(1, self.xscreensize) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1661 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1662 # add 1 so to account for last line text reaching end of line |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1663 self.numpadlines = self.getnumlinesdisplayed(ignorefolding=True) + 1 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1664 |
25821
d68544b69736
crecord: throws error instead of crashing for large diffs
Laurent Charignon <lcharignon@fb.com>
parents:
25820
diff
changeset
|
1665 try: |
d68544b69736
crecord: throws error instead of crashing for large diffs
Laurent Charignon <lcharignon@fb.com>
parents:
25820
diff
changeset
|
1666 self.chunkpad = curses.newpad(self.numpadlines, self.xscreensize) |
d68544b69736
crecord: throws error instead of crashing for large diffs
Laurent Charignon <lcharignon@fb.com>
parents:
25820
diff
changeset
|
1667 except curses.error: |
d68544b69736
crecord: throws error instead of crashing for large diffs
Laurent Charignon <lcharignon@fb.com>
parents:
25820
diff
changeset
|
1668 self.initerr = _('this diff is too large to be displayed') |
d68544b69736
crecord: throws error instead of crashing for large diffs
Laurent Charignon <lcharignon@fb.com>
parents:
25820
diff
changeset
|
1669 return |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1670 # initialize selecteitemendline (initial start-line is 0) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1671 self.selecteditemendline = self.getnumlinesdisplayed( |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1672 self.currentselecteditem, recursechildren=False) |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1673 |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1674 while True: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1675 self.updatescreen() |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1676 try: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1677 keypressed = self.statuswin.getkey() |
25556
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1678 if self.errorstr is not None: |
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1679 self.errorstr = None |
40f0e9e5b821
crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents:
25555
diff
changeset
|
1680 continue |
24310
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1681 except curses.error: |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1682 keypressed = "foobar" |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1683 if self.handlekeypressed(keypressed): |
6409fb6c934d
record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
1684 break |