annotate mercurial/crecord.py @ 33302:36a415b5a4b2

localrepo: add sparse caches The sparse extension maintains caches for the sparse files to a signature and a signature to a matcher. This allows the sparse matchers to be resolved quickly, which is apparently something that can occur in loops. This patch ports the sparse caches to the localrepo class pretty much as-is. There is potentially room to improve the caching mechanism. But that can be done as a follow-up. The default invalidatecaches() now clears the relevant sparse cache. invalidatesignaturecache() has been moved to sparse.py.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 06 Jul 2017 12:20:53 -0700
parents 66117dae87f9
children 1e71a27dee97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f4356e5094ba crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25821
diff changeset
18 from .i18n import _
f4356e5094ba crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25821
diff changeset
19 from . import (
f4356e5094ba crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25821
diff changeset
20 encoding,
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26421
diff changeset
21 error,
25940
f4356e5094ba crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25821
diff changeset
22 patch as patchmod,
30315
0911191dc4c9 crecord: use scmutil.termsize()
Yuya Nishihara <yuya@tcha.org>
parents: 29957
diff changeset
23 scmutil,
27156
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
24 util,
25940
f4356e5094ba crecord: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25821
diff changeset
25 )
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
26 stringio = util.stringio
24314
348492ba632a crecord: more import style
Matt Mackall <mpm@selenic.com>
parents: 24313
diff changeset
27
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
28 # 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
29 # locale encoding correctly. --immerrr
29697
00269c6e4f6e py3: use unicode literals in crecord.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29327
diff changeset
30 locale.setlocale(locale.LC_ALL, u'')
24317
f559cae7892f crecord: fiddle with vertical whitespace
Matt Mackall <mpm@selenic.com>
parents: 24316
diff changeset
31
28637
4874b8efe7d2 crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28636
diff changeset
32 # 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
33 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
34 # 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
35 # 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
36 """)
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 hunkhelptext = _("""#
4874b8efe7d2 crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28636
diff changeset
39 # 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
40 # 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
41 # 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
42 # 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
43 # unchanged.
4874b8efe7d2 crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28636
diff changeset
44 """)
28638
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28637
diff changeset
45
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28637
diff changeset
46 patchhelptext = _("""#
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28637
diff changeset
47 # 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
48 # 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
49 # 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
50 """)
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28637
diff changeset
51
27528
7cc654610204 crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents: 26781
diff changeset
52 try:
24909
d71492ca2fdd crecord: fix mixed imports warning
Matt Harbison <matt_harbison@yahoo.com>
parents: 24840
diff changeset
53 import curses
27528
7cc654610204 crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents: 26781
diff changeset
54 curses.error
7cc654610204 crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents: 26781
diff changeset
55 except ImportError:
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
56 # 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
57 try:
01b39e821d00 crecord: conditionalize the imports that are not available on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 24351
diff changeset
58 import wcurses as curses
27528
7cc654610204 crecord: use try/except for import of curses
Sean Farley <sean@farley.io>
parents: 26781
diff changeset
59 curses.error
24423
01b39e821d00 crecord: conditionalize the imports that are not available on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 24351
diff changeset
60 except ImportError:
27530
ba30ef5bba95 crecord: ensure that curses is False if not imported
Sean Farley <sean@farley.io>
parents: 27529
diff changeset
61 # 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
62 # compiled with curses
ba30ef5bba95 crecord: ensure that curses is False if not imported
Sean Farley <sean@farley.io>
parents: 27529
diff changeset
63 curses = False
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
64
27529
940cedaee988 crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents: 27528
diff changeset
65 def checkcurses(ui):
940cedaee988 crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents: 27528
diff changeset
66 """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
67
940cedaee988 crecord: add helper function to determine if we should use curses
Sean Farley <sean@farley.io>
parents: 27528
diff changeset
68 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
69 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
70 """
28543
f7874de435c5 crecord: use ui.interface to choose curses interface
Simon Farnsworth <simonfar@fb.com>
parents: 27937
diff changeset
71 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
72
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
73 class patchnode(object):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
74 """abstract class for patch graph nodes
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
75 (i.e. patchroot, header, hunk, hunkline)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
76 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
77
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
78 def firstchild(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
79 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
80
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
81 def lastchild(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
82 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
83
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
84 def allchildren(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
85 "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
86 raise NotImplementedError("method must be implemented by subclass")
29076
36d3535c6a47 crecord: add/remove blank lines (coding style)
Anton Shestakov <av6@dwimlabs.net>
parents: 28926
diff changeset
87
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
88 def nextsibling(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
89 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
90 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
91 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
92 If no such item exists, return None.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
93 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
94 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
95
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
96 def prevsibling(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
97 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
98 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
99 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
100 If no such item exists, return None.
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 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
103
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
104 def parentitem(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
105 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
106
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
107 def nextitem(self, skipfolded=True):
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
108 """
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
109 Try to return the next item closest to this item, regardless of item's
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
110 type (header, hunk, or hunkline).
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
111
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
112 If skipfolded == True, and the current item is folded, then the child
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
113 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
114 the next item.
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 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
117 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
118 try:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
119 itemfolded = self.folded
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
120 except AttributeError:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
121 itemfolded = False
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
122 if skipfolded and itemfolded:
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
123 nextitem = self.nextsibling()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
124 if nextitem is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
125 try:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
126 nextitem = self.parentitem().nextsibling()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
127 except AttributeError:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
128 nextitem = None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
129 return nextitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
130 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
131 # try child
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
132 item = self.firstchild()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
133 if item is not None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
134 return item
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
135
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
136 # else try next sibling
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
137 item = self.nextsibling()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
138 if item is not None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
139 return item
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
140
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
141 try:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
142 # else try parent's next sibling
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
143 item = self.parentitem().nextsibling()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
144 if item is not None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
145 return item
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
146
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
147 # 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
148 return self.parentitem().parentitem().nextsibling()
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 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
151 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
152
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
153 def previtem(self):
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
154 """
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
155 Try to return the previous item closest to this item, regardless of
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
156 item's type (header, hunk, or hunkline).
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
157
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
158 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
159 """
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
160 # try previous sibling's last child's last child,
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
161 # else try previous sibling's last child, else try previous sibling
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
162 prevsibling = self.prevsibling()
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
163 if prevsibling is not None:
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
164 prevsiblinglastchild = prevsibling.lastchild()
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
165 if ((prevsiblinglastchild is not None) and
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
166 not prevsibling.folded):
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
167 prevsiblinglclc = prevsiblinglastchild.lastchild()
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
168 if ((prevsiblinglclc is not None) and
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
169 not prevsiblinglastchild.folded):
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
170 return prevsiblinglclc
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
171 else:
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
172 return prevsiblinglastchild
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
173 else:
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
174 return prevsibling
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
175
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
176 # try parent (or None)
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
177 return self.parentitem()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
178
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
179 class patch(patchnode, list): # todo: rename patchroot
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 list of header objects representing the patch.
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 def __init__(self, headerlist):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
184 self.extend(headerlist)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
185 # 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
186 for header in self:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
187 header.patch = self
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
188
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
189 class uiheader(patchnode):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
190 """patch header
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
191
26781
1aee2ab0f902 spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents: 26587
diff changeset
192 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
193 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
194
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
195 def __init__(self, header):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
196 self.nonuiheader = header
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
197 # 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
198 self.applied = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
199 # 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
200 # 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
201 self.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
202
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
203 # 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
204 self.folded = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
205
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
206 # list of all headers in patch
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
207 self.patch = None
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 # 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
210 self.neverunfolded = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
211 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
212
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
213 def prettystr(self):
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
214 x = stringio()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
215 self.pretty(x)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
216 return x.getvalue()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
217
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
218 def nextsibling(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
219 numheadersinpatch = len(self.patch)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
220 indexofthisheader = self.patch.index(self)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
221
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
222 if indexofthisheader < numheadersinpatch - 1:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
223 nextheader = self.patch[indexofthisheader + 1]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
224 return nextheader
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
225 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
226 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
227
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
228 def prevsibling(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
229 indexofthisheader = self.patch.index(self)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
230 if indexofthisheader > 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
231 previousheader = self.patch[indexofthisheader - 1]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
232 return previousheader
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
233 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
234 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
235
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
236 def parentitem(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
237 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
238 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
239 so return None.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
240 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
241 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
242
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
243 def firstchild(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
244 "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
245 if len(self.hunks) > 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
246 return self.hunks[0]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
247 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
248 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
249
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
250 def lastchild(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
251 "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
252 if len(self.hunks) > 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
253 return self.hunks[-1]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
254 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
255 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
256
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
257 def allchildren(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
258 "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
259 return self.hunks
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
260
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
261 def __getattr__(self, name):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
262 return getattr(self.nonuiheader, name)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
263
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
264 class uihunkline(patchnode):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
265 "represents a changed line in a hunk"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
266 def __init__(self, linetext, hunk):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
267 self.linetext = linetext
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
268 self.applied = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
269 # 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
270 self.hunk = hunk
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
271 # 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
272 # in the previtem method.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
273 self.folded = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
274
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
275 def prettystr(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
276 return self.linetext
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
277
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
278 def nextsibling(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
279 numlinesinhunk = len(self.hunk.changedlines)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
280 indexofthisline = self.hunk.changedlines.index(self)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
281
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
282 if (indexofthisline < numlinesinhunk - 1):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
283 nextline = self.hunk.changedlines[indexofthisline + 1]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
284 return nextline
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
285 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
286 return None
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 prevsibling(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
289 indexofthisline = self.hunk.changedlines.index(self)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
290 if indexofthisline > 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
291 previousline = self.hunk.changedlines[indexofthisline - 1]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
292 return previousline
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
293 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
294 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
295
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
296 def parentitem(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
297 "return the parent to the current item"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
298 return self.hunk
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
299
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
300 def firstchild(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
301 "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
302 # hunk-lines don't have children
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
303 return None
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 lastchild(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
306 "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
307 # hunk-lines don't have children
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
308 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
309
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
310 class uihunk(patchnode):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
311 """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
312 maxcontext = 3
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
313
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
314 def __init__(self, hunk, header):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
315 self._hunk = hunk
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
316 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
317 self.header = header
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
318 # 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
319 self.originalremoved = self.removed
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
320
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
321 # 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
322 self.folded = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
323 # 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
324 self.applied = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
325 # 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
326 # 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
327 self.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
328
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
329 def nextsibling(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
330 numhunksinheader = len(self.header.hunks)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
331 indexofthishunk = self.header.hunks.index(self)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
332
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
333 if (indexofthishunk < numhunksinheader - 1):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
334 nexthunk = self.header.hunks[indexofthishunk + 1]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
335 return nexthunk
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
336 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
337 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
338
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
339 def prevsibling(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
340 indexofthishunk = self.header.hunks.index(self)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
341 if indexofthishunk > 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
342 previoushunk = self.header.hunks[indexofthishunk - 1]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
343 return previoushunk
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
344 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
345 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
346
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
347 def parentitem(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
348 "return the parent to the current item"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
349 return self.header
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
350
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
351 def firstchild(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
352 "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
353 if len(self.changedlines) > 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
354 return self.changedlines[0]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
355 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
356 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
357
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
358 def lastchild(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
359 "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
360 if len(self.changedlines) > 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
361 return self.changedlines[-1]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
362 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
363 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
364
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
365 def allchildren(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
366 "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
367 return self.changedlines
29076
36d3535c6a47 crecord: add/remove blank lines (coding style)
Anton Shestakov <av6@dwimlabs.net>
parents: 28926
diff changeset
368
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
369 def countchanges(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
370 """changedlines -> (n+,n-)"""
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
371 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
372 and l.prettystr()[0] == '+'])
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
373 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
374 and l.prettystr()[0] == '-'])
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
375 return add, rem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
376
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
377 def getfromtoline(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
378 # 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
379 removedconvertedtocontext = self.originalremoved - self.removed
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
380
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
381 contextlen = (len(self.before) + len(self.after) +
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
382 removedconvertedtocontext)
29862
e7766022a61a crecord: properly handle files with No newline at eof (issue5268)
timeless <timeless@mozdev.org>
parents: 29327
diff changeset
383 if self.after and self.after[-1] == '\\ No newline at end of file\n':
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
384 contextlen -= 1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
385 fromlen = contextlen + self.removed
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
386 tolen = contextlen + self.added
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
387
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
388 # 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
389 # 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
390 # precedes the hunk."
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 # 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
393 # 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
394 fromline, toline = self.fromline, self.toline
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
395 if fromline != 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
396 if fromlen == 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
397 fromline -= 1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
398 if tolen == 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
399 toline -= 1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
400
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
401 fromtoline = '@@ -%d,%d +%d,%d @@%s\n' % (
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
402 fromline, fromlen, toline, tolen,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
403 self.proc and (' ' + self.proc))
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
404 return fromtoline
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
405
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
406 def write(self, fp):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
407 # 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
408 self.added, self.removed = self.countchanges()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
409 fp.write(self.getfromtoline())
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
410
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
411 hunklinelist = []
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
412 # 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
413 # (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
414 for changedline in self.changedlines:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
415 changedlinestr = changedline.prettystr()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
416 if changedline.applied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
417 hunklinelist.append(changedlinestr)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
418 elif changedlinestr[0] == "-":
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
419 hunklinelist.append(" " + changedlinestr[1:])
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
420
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
421 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
422
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
423 pretty = write
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
424
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
425 def prettystr(self):
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
426 x = stringio()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
427 self.pretty(x)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
428 return x.getvalue()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
429
32979
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
430 def reversehunk(self):
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
431 """return a recordhunk which is the reverse of the hunk
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
432
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
433 Assuming the displayed patch is diff(A, B) result. The returned hunk is
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
434 intended to be applied to B, instead of A.
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
435
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
436 For example, when A is "0\n1\n2\n6\n" and B is "0\n3\n4\n5\n6\n", and
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
437 the user made the following selection:
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
438
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
439 0
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
440 [x] -1 [x]: selected
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
441 [ ] -2 [ ]: not selected
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
442 [x] +3
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
443 [ ] +4
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
444 [x] +5
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
445 6
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
446
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
447 This function returns a hunk like:
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
448
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
449 0
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
450 -3
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
451 -4
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
452 -5
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
453 +1
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
454 +4
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
455 6
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
456
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
457 Note "4" was first deleted then added. That's because "4" exists in B
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
458 side and "-4" must exist between "-3" and "-5" to make the patch
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
459 applicable to B.
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
460 """
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
461 dels = []
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
462 adds = []
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
463 for line in self.changedlines:
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
464 text = line.linetext
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
465 if line.applied:
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
466 if text[0] == '+':
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
467 dels.append(text[1:])
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
468 elif text[0] == '-':
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
469 adds.append(text[1:])
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
470 elif text[0] == '+':
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
471 dels.append(text[1:])
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
472 adds.append(text[1:])
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
473 hunk = ['-%s' % l for l in dels] + ['+%s' % l for l in adds]
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
474 h = self._hunk
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
475 return patchmod.recordhunk(h.header, h.toline, h.fromline, h.proc,
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
476 h.before, hunk, h.after)
66117dae87f9 patch: rewrite reversehunks (issue5337)
Jun Wu <quark@fb.com>
parents: 31933
diff changeset
477
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
478 def __getattr__(self, name):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
479 return getattr(self._hunk, name)
29076
36d3535c6a47 crecord: add/remove blank lines (coding style)
Anton Shestakov <av6@dwimlabs.net>
parents: 28926
diff changeset
480
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
481 def __repr__(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
482 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
483
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
484 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
485 """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
486 chunks = list(chunks)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
487 # 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
488 # 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
489 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
490
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
491 # if there are no changed files
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
492 if len(headers) == 0:
27321
dcdf0a52ad36 crecord: add dictionary to default return value of filterpatch
Laurent Charignon <lcharignon@fb.com>
parents: 27156
diff changeset
493 return [], {}
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
494 uiheaders = [uiheader(h) for h in headers]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
495 # 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
496 # accordingly
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
497 ret = chunkselector(ui, uiheaders, operation=operation)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
498 appliedhunklist = []
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
499 for hdr in uiheaders:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
500 if (hdr.applied and
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
501 (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
502 appliedhunklist.append(hdr)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
503 fixoffset = 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
504 for hnk in hdr.hunks:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
505 if hnk.applied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
506 appliedhunklist.append(hnk)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
507 # 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
508 # 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
509 if fixoffset:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
510 #hnk = copy.copy(hnk) # necessary??
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
511 hnk.toline += fixoffset
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
512 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
513 fixoffset += hnk.removed - hnk.added
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
514
27155
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 26781
diff changeset
515 return (appliedhunklist, ret)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
516
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
517 def chunkselector(ui, headerlist, operation=None):
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
518 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
519 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
520 of the chosen chunks.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
521 """
24779
23727465ff72 record: add message when starting record's curses interface
Laurent Charignon <lcharignon@fb.com>
parents: 24492
diff changeset
522 ui.write(_('starting interactive selection\n'))
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
523 chunkselector = curseschunkselector(headerlist, ui, operation)
31933
b2478a996a82 crecord: avoid setting non-existing SIGTSTP signal on windows (issue5512)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31932
diff changeset
524 origsigtstp = sentinel = object()
b2478a996a82 crecord: avoid setting non-existing SIGTSTP signal on windows (issue5512)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31932
diff changeset
525 if util.safehasattr(signal, 'SIGTSTP'):
b2478a996a82 crecord: avoid setting non-existing SIGTSTP signal on windows (issue5512)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31932
diff changeset
526 origsigtstp = signal.getsignal(signal.SIGTSTP)
31932
20a68f714f9b crecord: ensure we reinstall the SIGTSTP handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31931
diff changeset
527 try:
20a68f714f9b crecord: ensure we reinstall the SIGTSTP handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31931
diff changeset
528 curses.wrapper(chunkselector.main)
20a68f714f9b crecord: ensure we reinstall the SIGTSTP handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31931
diff changeset
529 if chunkselector.initerr is not None:
20a68f714f9b crecord: ensure we reinstall the SIGTSTP handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31931
diff changeset
530 raise error.Abort(chunkselector.initerr)
20a68f714f9b crecord: ensure we reinstall the SIGTSTP handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31931
diff changeset
531 # ncurses does not restore signal handler for SIGTSTP
20a68f714f9b crecord: ensure we reinstall the SIGTSTP handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31931
diff changeset
532 finally:
31933
b2478a996a82 crecord: avoid setting non-existing SIGTSTP signal on windows (issue5512)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31932
diff changeset
533 if origsigtstp is not sentinel:
b2478a996a82 crecord: avoid setting non-existing SIGTSTP signal on windows (issue5512)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31932
diff changeset
534 signal.signal(signal.SIGTSTP, origsigtstp)
27155
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 26781
diff changeset
535 return chunkselector.opts
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
536
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
537 def testdecorator(testfn, f):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
538 def u(*args, **kwargs):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
539 return f(testfn, *args, **kwargs)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
540 return u
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
541
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
542 def testchunkselector(testfn, ui, headerlist, operation=None):
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 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
545 of the chosen chunks.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
546 """
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
547 chunkselector = curseschunkselector(headerlist, ui, operation)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
548 if testfn and os.path.exists(testfn):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
549 testf = open(testfn)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
550 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
551 testf.close()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
552 while True:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
553 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
554 break
27155
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 26781
diff changeset
555 return chunkselector.opts
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
556
30548
8d9745ff1e62 crecord: change the verb according to the operation
Jun Wu <quark@fb.com>
parents: 30547
diff changeset
557 _headermessages = { # {operation: text}
8d9745ff1e62 crecord: change the verb according to the operation
Jun Wu <quark@fb.com>
parents: 30547
diff changeset
558 'revert': _('Select hunks to revert'),
8d9745ff1e62 crecord: change the verb according to the operation
Jun Wu <quark@fb.com>
parents: 30547
diff changeset
559 'discard': _('Select hunks to discard'),
8d9745ff1e62 crecord: change the verb according to the operation
Jun Wu <quark@fb.com>
parents: 30547
diff changeset
560 None: _('Select hunks to record'),
8d9745ff1e62 crecord: change the verb according to the operation
Jun Wu <quark@fb.com>
parents: 30547
diff changeset
561 }
8d9745ff1e62 crecord: change the verb according to the operation
Jun Wu <quark@fb.com>
parents: 30547
diff changeset
562
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
563 class curseschunkselector(object):
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
564 def __init__(self, headerlist, ui, operation=None):
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
565 # put the headers into a patch object
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
566 self.headerlist = patch(headerlist)
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 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
569 self.opts = {}
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
570
25556
40f0e9e5b821 crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents: 25555
diff changeset
571 self.errorstr = None
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
572 # list of all chunks
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
573 self.chunklist = []
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
574 for h in headerlist:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
575 self.chunklist.append(h)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
576 self.chunklist.extend(h.hunks)
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 # dictionary mapping (fgcolor, bgcolor) pairs to the
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
579 # corresponding curses color-pair value.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
580 self.colorpairs = {}
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
581 # 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
582 self.colorpairnames = {}
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 # 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
585 self.currentselecteditem = self.headerlist[0]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
586
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
587 # 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
588 # 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
589 self.selecteditemstartline = 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
590 self.selecteditemendline = None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
591
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
592 # define indentation levels
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
593 self.headerindentnumchars = 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
594 self.hunkindentnumchars = 3
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
595 self.hunklineindentnumchars = 6
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
596
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
597 # 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
598 self.firstlineofpadtoprint = 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
599
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
600 # 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
601 self.numpadlines = None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
602
30545
f3cff00c7a00 crecord: make _getstatuslines update numstatuslines
Jun Wu <quark@fb.com>
parents: 30544
diff changeset
603 self.numstatuslines = 1
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
604
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
605 # 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
606 # (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
607 self.linesprintedtopadsofar = 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
608
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
609 # 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
610 self.firstlineofpadtoprint = 0
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 # 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
613 self.commenttext = ""
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
614
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
615 # 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
616 self.waslasttoggleallapplied = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
617
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
618 # affects some ui text
30548
8d9745ff1e62 crecord: change the verb according to the operation
Jun Wu <quark@fb.com>
parents: 30547
diff changeset
619 if operation not in _headermessages:
31649
4bc3e55cf386 crecord: use ProgrammingError
Jun Wu <quark@fb.com>
parents: 30981
diff changeset
620 raise error.ProgrammingError('unexpected operation: %s' % operation)
30533
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
621 self.operation = operation
40fe96fc7cd2 crecord: add an "operation" field
Jun Wu <quark@fb.com>
parents: 30332
diff changeset
622
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
623 def uparrowevent(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
624 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
625 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
626 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
627 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
628 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
629 hunk itself.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
630 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
631 currentitem = self.currentselecteditem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
632
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
633 nextitem = currentitem.previtem()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
634
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 uparrowshiftevent(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 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
645 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
646 parent-item of the currently selected item.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
647 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
648 currentitem = self.currentselecteditem
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
649 nextitem = currentitem.prevsibling()
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
650 # if there's no previous sibling, try choosing the parent
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
651 if nextitem is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
652 nextitem = currentitem.parentitem()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
653 if nextitem is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
654 # 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
655 # no change...
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
656 nextitem = currentitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
657
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
658 self.currentselecteditem = nextitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
659
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
660 def downarrowevent(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
661 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
662 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
663 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
664 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
665 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
666 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
667 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
668 #self.startprintline += 1 #debug
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
669 currentitem = self.currentselecteditem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
670
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
671 nextitem = currentitem.nextitem()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
672 # 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
673 if nextitem is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
674 nextitem = currentitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
675
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
676 self.currentselecteditem = nextitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
677
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
678 def downarrowshiftevent(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
679 """
29081
4abca4cbe768 crecord: update downarrowshiftevent() docstring, remove todo
Anton Shestakov <av6@dwimlabs.net>
parents: 29080
diff changeset
680 select (if possible) the next item on the same level as the currently
4abca4cbe768 crecord: update downarrowshiftevent() docstring, remove todo
Anton Shestakov <av6@dwimlabs.net>
parents: 29080
diff changeset
681 selected item. otherwise, select (if possible) the next item on the
4abca4cbe768 crecord: update downarrowshiftevent() docstring, remove todo
Anton Shestakov <av6@dwimlabs.net>
parents: 29080
diff changeset
682 same level as the parent item of the currently selected item.
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
683 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
684 currentitem = self.currentselecteditem
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
685 nextitem = currentitem.nextsibling()
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
686 # if there's no next sibling, try choosing the parent's nextsibling
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
687 if nextitem is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
688 try:
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
689 nextitem = currentitem.parentitem().nextsibling()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
690 except AttributeError:
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
691 # parentitem returned None, so nextsibling() can't be called
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
692 nextitem = None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
693 if nextitem is None:
29130
ed2a3818c1fc crecord: call prevsibling() and nextsibling() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 29081
diff changeset
694 # if parent has no next sibling, then no change...
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
695 nextitem = currentitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
696
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
697 self.currentselecteditem = nextitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
698
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
699 def rightarrowevent(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
700 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
701 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
702 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
703 currentitem = self.currentselecteditem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
704 nextitem = currentitem.firstchild()
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 # 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
707 if currentitem.folded:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
708 self.togglefolded(currentitem)
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 if nextitem is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
711 # 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
712 nextitem = currentitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
713
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
714 self.currentselecteditem = nextitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
715
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
716 def leftarrowevent(self):
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 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
719 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
720 of this item.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
721 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
722 currentitem = self.currentselecteditem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
723
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
724 # try to fold the item
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
725 if not isinstance(currentitem, uihunkline):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
726 if not currentitem.folded:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
727 self.togglefolded(item=currentitem)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
728 return
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
729
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
730 # 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
731 nextitem = currentitem.parentitem()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
732
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
733 if nextitem is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
734 # 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
735 nextitem = currentitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
736 if not nextitem.folded:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
737 self.togglefolded(item=nextitem)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
738
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
739 self.currentselecteditem = nextitem
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 def leftarrowshiftevent(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
742 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
743 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
744 current item is already a header).
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
745 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
746 currentitem = self.currentselecteditem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
747
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
748 if isinstance(currentitem, uiheader):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
749 if not currentitem.folded:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
750 self.togglefolded(item=currentitem)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
751 return
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
752
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
753 # 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
754 while True:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
755 nextitem = currentitem.parentitem()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
756 if nextitem is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
757 break
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
758 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
759 currentitem = nextitem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
760
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
761 self.currentselecteditem = currentitem
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 def updatescroll(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
764 "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
765 selstart = self.selecteditemstartline
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
766 selend = self.selecteditemendline
29942
3664537386ab crecord: delete commented line
Nathan Goldbaum <ngoldbau@illinois.edu>
parents: 29937
diff changeset
767
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
768 padstart = self.firstlineofpadtoprint
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
769 padend = padstart + self.yscreensize - self.numstatuslines - 1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
770 # '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
771 # top/bottom context margin
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
772 padstartbuffered = padstart + 3
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
773 padendbuffered = padend - 3
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
774
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
775 if selend > padendbuffered:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
776 self.scrolllines(selend - padendbuffered)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
777 elif selstart < padstartbuffered:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
778 # negative values scroll in pgup direction
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
779 self.scrolllines(selstart - padstartbuffered)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
780
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
781 def scrolllines(self, numlines):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
782 "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
783 self.firstlineofpadtoprint += numlines
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
784 if self.firstlineofpadtoprint < 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
785 self.firstlineofpadtoprint = 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
786 if self.firstlineofpadtoprint > self.numpadlines - 1:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
787 self.firstlineofpadtoprint = self.numpadlines - 1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
788
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
789 def toggleapply(self, item=None):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
790 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
791 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
792 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
793 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
794 if item is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
795 item = self.currentselecteditem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
796
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
797 item.applied = not item.applied
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
798
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
799 if isinstance(item, uiheader):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
800 item.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
801 if item.applied:
24492
efa094701a05 record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents: 24425
diff changeset
802 # apply all its hunks
efa094701a05 record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents: 24425
diff changeset
803 for hnk in item.hunks:
efa094701a05 record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents: 24425
diff changeset
804 hnk.applied = True
efa094701a05 record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents: 24425
diff changeset
805 # apply all their hunklines
efa094701a05 record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents: 24425
diff changeset
806 for hunkline in hnk.changedlines:
efa094701a05 record_curses: fix ui bug for newly added file
Laurent Charignon <lcharignon@fb.com>
parents: 24425
diff changeset
807 hunkline.applied = True
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
808 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
809 # un-apply all its hunks
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
810 for hnk in item.hunks:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
811 hnk.applied = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
812 hnk.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
813 # un-apply all their hunklines
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
814 for hunkline in hnk.changedlines:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
815 hunkline.applied = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
816 elif isinstance(item, uihunk):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
817 item.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
818 # apply all it's hunklines
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
819 for hunkline in item.changedlines:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
820 hunkline.applied = item.applied
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
821
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
822 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
823 allsiblingsapplied = not (False in siblingappliedstatus)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
824 nosiblingsapplied = not (True in siblingappliedstatus)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
825
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
826 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
827 somesiblingspartial = (True in siblingspartialstatus)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
828
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
829 #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
830
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
831 # 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
832 if nosiblingsapplied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
833 if not item.header.special():
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
834 item.header.applied = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
835 item.header.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
836 else: # some/all parent siblings are applied
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
837 item.header.applied = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
838 item.header.partial = (somesiblingspartial or
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
839 not allsiblingsapplied)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
840
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
841 elif isinstance(item, uihunkline):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
842 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
843 allsiblingsapplied = not (False in siblingappliedstatus)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
844 nosiblingsapplied = not (True in siblingappliedstatus)
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 # if no 'sibling' lines are applied
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
847 if nosiblingsapplied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
848 item.hunk.applied = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
849 item.hunk.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
850 elif allsiblingsapplied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
851 item.hunk.applied = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
852 item.hunk.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
853 else: # some siblings applied
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
854 item.hunk.applied = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
855 item.hunk.partial = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
856
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
857 parentsiblingsapplied = [hnk.applied for hnk
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
858 in item.hunk.header.hunks]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
859 noparentsiblingsapplied = not (True in parentsiblingsapplied)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
860 allparentsiblingsapplied = not (False in parentsiblingsapplied)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
861
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
862 parentsiblingspartial = [hnk.partial for hnk
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
863 in item.hunk.header.hunks]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
864 someparentsiblingspartial = (True in parentsiblingspartial)
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 # 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
867 if noparentsiblingsapplied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
868 if not item.hunk.header.special():
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
869 item.hunk.header.applied = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
870 item.hunk.header.partial = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
871 # 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
872 else: # some/all parent siblings are applied
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
873 item.hunk.header.applied = True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
874 item.hunk.header.partial = (someparentsiblingspartial or
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
875 not allparentsiblingsapplied)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
876
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
877 def toggleall(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
878 "toggle the applied flag of all items."
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
879 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
880 for item in self.headerlist:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
881 if item.applied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
882 self.toggleapply(item)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
883 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
884 for item in self.headerlist:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
885 if not item.applied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
886 self.toggleapply(item)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
887 self.waslasttoggleallapplied = not self.waslasttoggleallapplied
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 def togglefolded(self, item=None, foldparent=False):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
890 "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
891 if item is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
892 item = self.currentselecteditem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
893 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
894 if not isinstance(item, uiheader):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
895 # 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
896 self.currentselecteditem = item = item.parentitem()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
897 elif item.neverunfolded:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
898 item.neverunfolded = False
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 # 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
901 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
902 for child in item.allchildren():
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
903 child.folded = not item.folded
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 if isinstance(item, (uiheader, uihunk)):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
906 item.folded = not item.folded
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
907
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
908 def alignstring(self, instr, window):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
909 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
910 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
911 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
912 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
913 multiple lines.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
914 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
915 y, xstart = window.getyx()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
916 width = self.xscreensize
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
917 # turn tabs into spaces
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
918 instr = instr.expandtabs(4)
24351
cdc4f3af2497 crecord: use colwidth instead of ucolwidth
Matt Mackall <mpm@selenic.com>
parents: 24342
diff changeset
919 strwidth = encoding.colwidth(instr)
24315
7d5f935bd705 crecord: use encoding.ucolwidth
Matt Mackall <mpm@selenic.com>
parents: 24314
diff changeset
920 numspaces = (width - ((strwidth + xstart) % width) - 1)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
921 return instr + " " * numspaces + "\n"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
922
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
923 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
924 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
925 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
926 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
927 the specified curses window object.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
928
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
929 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
930 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
931 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
932 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
933
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
934 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
935 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
936 underline].
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
937
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
938 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
939 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
940
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
941 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
942 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
943 # preprocess the text, converting tabs to spaces
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
944 text = text.expandtabs(4)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
945 # 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
946 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
947 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
948
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
949 if pair is not None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
950 colorpair = pair
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
951 elif pairname is not None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
952 colorpair = self.colorpairnames[pairname]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
953 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
954 if fgcolor is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
955 fgcolor = -1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
956 if bgcolor is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
957 bgcolor = -1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
958 if (fgcolor, bgcolor) in self.colorpairs:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
959 colorpair = self.colorpairs[(fgcolor, bgcolor)]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
960 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
961 colorpair = self.getcolorpair(fgcolor, bgcolor)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
962 # add attributes if possible
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
963 if attrlist is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
964 attrlist = []
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
965 if colorpair < 256:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
966 # 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
967 for textattr in attrlist:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
968 colorpair |= textattr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
969 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
970 # just apply a select few (safe?) attributes
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
971 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
972 if textattr in attrlist:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
973 colorpair |= textattr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
974
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
975 y, xstart = self.chunkpad.getyx()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
976 t = "" # variable for counting lines printed
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
977 # if requested, show trailing whitespace
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 origlen = len(text)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
980 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
981 strippedlen = len(text)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
982 numtrailingspaces = origlen - strippedlen
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
983
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
984 if towin:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
985 window.addstr(text, colorpair)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
986 t += text
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
987
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
988 if showwhtspc:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
989 wscolorpair = colorpair | curses.A_REVERSE
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
990 if towin:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
991 for i in range(numtrailingspaces):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
992 window.addch(curses.ACS_CKBOARD, wscolorpair)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
993 t += " " * numtrailingspaces
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
994
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
995 if align:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
996 if towin:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
997 extrawhitespace = self.alignstring("", window)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
998 window.addstr(extrawhitespace, colorpair)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
999 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1000 # 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
1001 extrawhitespace = self.alignstring(t, window)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1002 t += extrawhitespace
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 # 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
1005
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1006 linesprinted = (xstart + len(t)) / self.xscreensize
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1007 self.linesprintedtopadsofar += linesprinted
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1008 return t
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1009
30546
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1010 def _getstatuslinesegments(self):
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1011 """-> [str]. return segments"""
30547
5129ed3c2548 crecord: change help text for the space key dynamically
Jun Wu <quark@fb.com>
parents: 30546
diff changeset
1012 selected = self.currentselecteditem.applied
30546
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1013 segments = [
30548
8d9745ff1e62 crecord: change the verb according to the operation
Jun Wu <quark@fb.com>
parents: 30547
diff changeset
1014 _headermessages[self.operation],
30546
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1015 '-',
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1016 _('[x]=selected **=collapsed'),
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1017 _('c: confirm'),
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1018 _('q: abort'),
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1019 _('arrow keys: move/expand/collapse'),
30547
5129ed3c2548 crecord: change help text for the space key dynamically
Jun Wu <quark@fb.com>
parents: 30546
diff changeset
1020 _('space: deselect') if selected else _('space: select'),
30546
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1021 _('?: help'),
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1022 ]
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1023 return segments
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1024
30544
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1025 def _getstatuslines(self):
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1026 """() -> [str]. return short help used in the top status window"""
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1027 if self.errorstr is not None:
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1028 lines = [self.errorstr, _('Press any key to continue')]
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1029 else:
30546
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1030 # wrap segments to lines
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1031 segments = self._getstatuslinesegments()
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1032 width = self.xscreensize
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1033 lines = []
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1034 lastwidth = width
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1035 for s in segments:
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1036 w = encoding.colwidth(s)
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1037 sep = ' ' * (1 + (s and s[0] not in '-['))
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1038 if lastwidth + w + len(sep) >= width:
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1039 lines.append(s)
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1040 lastwidth = w
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1041 else:
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1042 lines[-1] += sep + s
9b674957e2e4 crecord: rewrite status line text (BC)
Jun Wu <quark@fb.com>
parents: 30545
diff changeset
1043 lastwidth += w + len(sep)
30545
f3cff00c7a00 crecord: make _getstatuslines update numstatuslines
Jun Wu <quark@fb.com>
parents: 30544
diff changeset
1044 if len(lines) != self.numstatuslines:
f3cff00c7a00 crecord: make _getstatuslines update numstatuslines
Jun Wu <quark@fb.com>
parents: 30544
diff changeset
1045 self.numstatuslines = len(lines)
f3cff00c7a00 crecord: make _getstatuslines update numstatuslines
Jun Wu <quark@fb.com>
parents: 30544
diff changeset
1046 self.statuswin.resize(self.numstatuslines, self.xscreensize)
30544
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1047 return [util.ellipsis(l, self.xscreensize - 1) for l in lines]
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1048
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1049 def updatescreen(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1050 self.statuswin.erase()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1051 self.chunkpad.erase()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1052
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1053 printstring = self.printstring
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1054
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1055 # 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
1056 try:
30544
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1057 for line in self._getstatuslines():
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1058 printstring(self.statuswin, line, pairname="legend")
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1059 self.statuswin.refresh()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1060 except curses.error:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1061 pass
30544
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1062 if self.errorstr is not None:
d4035372db8d crecord: move status window text calculation to a separate method
Jun Wu <quark@fb.com>
parents: 30535
diff changeset
1063 return
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1064
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1065 # 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
1066 try:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1067 self.printitem()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1068 self.updatescroll()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1069 self.chunkpad.refresh(self.firstlineofpadtoprint, 0,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1070 self.numstatuslines, 0,
30545
f3cff00c7a00 crecord: make _getstatuslines update numstatuslines
Jun Wu <quark@fb.com>
parents: 30544
diff changeset
1071 self.yscreensize - self.numstatuslines,
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1072 self.xscreensize)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1073 except curses.error:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1074 pass
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1075
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1076 def getstatusprefixstring(self, item):
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 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
1079 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
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 # create checkbox string
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1083 if item.applied:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1084 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
1085 checkbox = "[~]"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1086 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1087 checkbox = "[x]"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1088 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1089 checkbox = "[ ]"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1090
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1091 try:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1092 if item.folded:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1093 checkbox += "**"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1094 if isinstance(item, uiheader):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1095 # 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
1096 filestatus = item.changetype
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1097
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1098 checkbox += filestatus + " "
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1099 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1100 checkbox += " "
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1101 if isinstance(item, uiheader):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1102 # add two more spaces for headers
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1103 checkbox += " "
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1104 except AttributeError: # not foldable
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1105 checkbox += " "
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1106
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1107 return checkbox
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1108
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1109 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
1110 ignorefolding=False):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1111 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1112 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
1113 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
1114 """
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1115
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1116 outstr = ""
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1117 text = header.prettystr()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1118 chunkindex = self.chunklist.index(header)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1119
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1120 if chunkindex != 0 and not header.folded:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1121 # add separating line before headers
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1122 outstr += self.printstring(self.chunkpad, '_' * self.xscreensize,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1123 towin=towin, align=False)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1124 # 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
1125 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
1126 attrlist=[curses.A_BOLD])
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1127
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1128 # 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
1129
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1130 # 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
1131 indentnumchars = 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1132 checkbox = self.getstatusprefixstring(header)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1133 if not header.folded or ignorefolding:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1134 textlist = text.split("\n")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1135 linestr = checkbox + textlist[0]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1136 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1137 linestr = checkbox + header.filename()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1138 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
1139 towin=towin)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1140 if not header.folded or ignorefolding:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1141 if len(textlist) > 1:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1142 for line in textlist[1:]:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1143 linestr = " "*(indentnumchars + len(checkbox)) + line
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1144 outstr += self.printstring(self.chunkpad, linestr,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1145 pair=colorpair, towin=towin)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1146
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1147 return outstr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1148
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1149 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
1150 ignorefolding=False):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1151 "includes start/end line indicator"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1152 outstr = ""
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1153 # where hunk is in list of siblings
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1154 hunkindex = hunk.header.hunks.index(hunk)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1155
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1156 if hunkindex != 0:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1157 # add separating line before headers
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1158 outstr += self.printstring(self.chunkpad, ' '*self.xscreensize,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1159 towin=towin, align=False)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1160
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1161 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
1162 attrlist=[curses.A_BOLD])
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 # print out from-to line with checkbox
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1165 checkbox = self.getstatusprefixstring(hunk)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1166
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1167 lineprefix = " "*self.hunkindentnumchars + checkbox
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1168 frtoline = " " + hunk.getfromtoline().strip("\n")
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 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
1171 align=False) # add uncolored checkbox/indent
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1172 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
1173 towin=towin)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1174
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1175 if hunk.folded and not ignorefolding:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1176 # skip remainder of output
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1177 return outstr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1178
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1179 # 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
1180 for line in hunk.before:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1181 linestr = " "*(self.hunklineindentnumchars + len(checkbox)) + line
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1182 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
1183
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1184 return outstr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1185
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1186 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
1187 outstr = ""
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1188 if hunk.folded and not ignorefolding:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1189 return outstr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1190
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1191 # 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
1192 checkbox = self.getstatusprefixstring(hunk)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1193 for line in hunk.after:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1194 linestr = " "*(self.hunklineindentnumchars + len(checkbox)) + line
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1195 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
1196
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1197 return outstr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1198
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1199 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
1200 outstr = ""
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1201 checkbox = self.getstatusprefixstring(hunkline)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1202
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1203 linestr = hunkline.prettystr().strip("\n")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1204
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1205 # 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
1206 if selected:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1207 colorpair = self.getcolorpair(name="selected")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1208 elif linestr.startswith("+"):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1209 colorpair = self.getcolorpair(name="addition")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1210 elif linestr.startswith("-"):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1211 colorpair = self.getcolorpair(name="deletion")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1212 elif linestr.startswith("\\"):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1213 colorpair = self.getcolorpair(name="normal")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1214
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1215 lineprefix = " "*self.hunklineindentnumchars + checkbox
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1216 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
1217 align=False) # add uncolored checkbox/indent
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1218 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
1219 towin=towin, showwhtspc=True)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1220 return outstr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1221
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1222 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
1223 towin=True):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1224 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1225 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
1226 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
1227 (hiding folded elements, etc. -- see __printitem() docstring)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1228 """
28579
f571ea254f75 crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents: 28543
diff changeset
1229
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1230 if item is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1231 item = self.headerlist
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1232 if recursechildren:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1233 self.linesprintedtopadsofar = 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1234
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1235 outstr = []
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1236 self.__printitem(item, ignorefolding, recursechildren, outstr,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1237 towin=towin)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1238 return ''.join(outstr)
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 def outofdisplayedarea(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1241 y, _ = self.chunkpad.getyx() # cursor location
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1242 # * 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
1243 # consecutive non selectable lines
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1244 # 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
1245 miny = min(0, self.firstlineofpadtoprint - self.yscreensize)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1246 maxy = self.firstlineofpadtoprint + self.yscreensize * 2
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1247 return y < miny or y > maxy
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1248
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1249 def handleselection(self, item, recursechildren):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1250 selected = (item is self.currentselecteditem)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1251 if selected and recursechildren:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1252 # assumes line numbering starting from line 0
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1253 self.selecteditemstartline = self.linesprintedtopadsofar
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1254 selecteditemlines = self.getnumlinesdisplayed(item,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1255 recursechildren=False)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1256 self.selecteditemendline = (self.selecteditemstartline +
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1257 selecteditemlines - 1)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1258 return selected
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1259
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1260 def __printitem(self, item, ignorefolding, recursechildren, outstr,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1261 towin=True):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1262 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1263 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
1264 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
1265 patch (not including coloring, etc.).
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1266
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1267 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
1268
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1269 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
1270 child items.
28579
f571ea254f75 crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents: 28543
diff changeset
1271 """
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1272
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1273 if towin and self.outofdisplayedarea():
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1274 return
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1275
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1276 selected = self.handleselection(item, recursechildren)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1277
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1278 # patch object is a list of headers
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1279 if isinstance(item, patch):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1280 if recursechildren:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1281 for hdr in item:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1282 self.__printitem(hdr, ignorefolding,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1283 recursechildren, outstr, towin)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1284 # todo: eliminate all isinstance() calls
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1285 if isinstance(item, uiheader):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1286 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
1287 ignorefolding=ignorefolding))
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1288 if recursechildren:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1289 for hnk in item.hunks:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1290 self.__printitem(hnk, ignorefolding,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1291 recursechildren, outstr, towin)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1292 elif (isinstance(item, uihunk) and
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1293 ((not item.header.folded) or ignorefolding)):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1294 # 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
1295 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
1296 ignorefolding=ignorefolding))
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1297 if recursechildren:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1298 for l in item.changedlines:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1299 self.__printitem(l, ignorefolding,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1300 recursechildren, outstr, towin)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1301 outstr.append(self.printhunklinesafter(item, towin=towin,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1302 ignorefolding=ignorefolding))
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1303 elif (isinstance(item, uihunkline) and
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1304 ((not item.hunk.folded) or ignorefolding)):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1305 outstr.append(self.printhunkchangedline(item, selected,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1306 towin=towin))
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1307
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1308 return outstr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1309
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1310 def getnumlinesdisplayed(self, item=None, ignorefolding=False,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1311 recursechildren=True):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1312 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1313 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
1314 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
1315 display (pad).
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1316 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
1317 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
1318 the number of lines.
28579
f571ea254f75 crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents: 28543
diff changeset
1319 """
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1320
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1321 # temporarily disable printing to windows by printstring
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1322 patchdisplaystring = self.printitem(item, ignorefolding,
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1323 recursechildren, towin=False)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1324 numlines = len(patchdisplaystring) / self.xscreensize
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1325 return numlines
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1326
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1327 def sigwinchhandler(self, n, frame):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1328 "handle window resizing"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1329 try:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1330 curses.endwin()
30315
0911191dc4c9 crecord: use scmutil.termsize()
Yuya Nishihara <yuya@tcha.org>
parents: 29957
diff changeset
1331 self.xscreensize, self.yscreensize = scmutil.termsize(self.ui)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1332 self.statuswin.resize(self.numstatuslines, self.xscreensize)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1333 self.numpadlines = self.getnumlinesdisplayed(ignorefolding=True) + 1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1334 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
1335 except curses.error:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1336 pass
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1337
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1338 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
1339 attrlist=None):
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 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
1342 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
1343 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
1344 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
1345 returned.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1346
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1347 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
1348 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
1349
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1350 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
1351 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
1352 curses.A_BOLD.
28579
f571ea254f75 crecord: clean up empty lines at ends of docblocks
Ryan McElroy <rmcelroy@fb.com>
parents: 28543
diff changeset
1353 """
24310
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 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
1356 # 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
1357 colorpair = self.colorpairnames[name]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1358 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1359 if fgcolor is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1360 fgcolor = -1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1361 if bgcolor is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1362 bgcolor = -1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1363 if (fgcolor, bgcolor) in self.colorpairs:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1364 colorpair = self.colorpairs[(fgcolor, bgcolor)]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1365 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1366 pairindex = len(self.colorpairs) + 1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1367 curses.init_pair(pairindex, fgcolor, bgcolor)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1368 colorpair = self.colorpairs[(fgcolor, bgcolor)] = (
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1369 curses.color_pair(pairindex))
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1370 if name is not None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1371 self.colorpairnames[name] = curses.color_pair(pairindex)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1372
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1373 # add attributes if possible
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1374 if attrlist is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1375 attrlist = []
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1376 if colorpair < 256:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1377 # 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
1378 for textattr in attrlist:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1379 colorpair |= textattr
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1380 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1381 # just apply a select few (safe?) attributes
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1382 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
1383 if textattrib in attrlist:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1384 colorpair |= textattrib
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1385 return colorpair
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1386
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1387 def initcolorpair(self, *args, **kwargs):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1388 "same as getcolorpair."
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1389 self.getcolorpair(*args, **kwargs)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1390
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1391 def helpwindow(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1392 "print a help window to the screen. exit after any keypress."
30535
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1393 helptext = _(
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1394 """ [press any key to return to the patch-display]
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1395
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1396 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
1397 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
1398 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
1399 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
1400 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
1401 the following are valid keystrokes:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1402
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1403 [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
1404 A : (un-)select all items
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1405 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
1406 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
1407 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
1408 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
1409 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
1410 F : fold / unfold parent item and all of its ancestors
29957
7d053ba73178 crecord: add an event that scrolls the selected line to the top of the screen
Nathan Goldbaum <ngoldbau@illinois.edu>
parents: 29942
diff changeset
1411 ctrl-l : scroll the selected line to the top of the screen
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1412 m : edit / resume editing the commit message
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1413 e : edit the currently selected hunk
29077
6ecd1a00977e crecord: drop the version condition for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29076
diff changeset
1414 a : toggle amend mode, only with commit -i
24840
a5e3634ba024 record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents: 24779
diff changeset
1415 c : confirm selected changes
a5e3634ba024 record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents: 24779
diff changeset
1416 r : review/edit and confirm selected changes
a5e3634ba024 record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents: 24779
diff changeset
1417 q : quit without confirming (no changes will be made)
30535
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1418 ? : help (what you're currently reading)""")
24310
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 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
1421 helplines = helptext.split("\n")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1422 helplines = helplines + [" "]*(
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1423 self.yscreensize - self.numstatuslines - len(helplines) - 1)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1424 try:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1425 for line in helplines:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1426 self.printstring(helpwin, line, pairname="legend")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1427 except curses.error:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1428 pass
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1429 helpwin.refresh()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1430 try:
30981
a0c4e57074fe crecord: log blocked time waiting for curses input
Simon Farnsworth <simonfar@fb.com>
parents: 30797
diff changeset
1431 with self.ui.timeblockedsection('crecord'):
a0c4e57074fe crecord: log blocked time waiting for curses input
Simon Farnsworth <simonfar@fb.com>
parents: 30797
diff changeset
1432 helpwin.getkey()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1433 except curses.error:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1434 pass
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1435
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1436 def confirmationwindow(self, windowtext):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1437 "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
1438
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1439 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
1440 try:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1441 lines = windowtext.split("\n")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1442 for line in lines:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1443 self.printstring(confirmwin, line, pairname="selected")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1444 except curses.error:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1445 pass
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1446 self.stdscr.refresh()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1447 confirmwin.refresh()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1448 try:
30981
a0c4e57074fe crecord: log blocked time waiting for curses input
Simon Farnsworth <simonfar@fb.com>
parents: 30797
diff changeset
1449 with self.ui.timeblockedsection('crecord'):
a0c4e57074fe crecord: log blocked time waiting for curses input
Simon Farnsworth <simonfar@fb.com>
parents: 30797
diff changeset
1450 response = chr(self.stdscr.getch())
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1451 except ValueError:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1452 response = None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1453
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1454 return response
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1455
28926
0411b7998d9b crecord: cleanup the remains of commit confirmation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 28925
diff changeset
1456 def reviewcommit(self):
24840
a5e3634ba024 record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents: 24779
diff changeset
1457 """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
1458 confirmed."""
30535
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1459 confirmtext = _(
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1460 """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
1461 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
1462 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
1463 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
1464
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1465 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
1466 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
1467
24840
a5e3634ba024 record: change wording for record curses interface
Laurent Charignon <lcharignon@fb.com>
parents: 24779
diff changeset
1468 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
1469 """)
30981
a0c4e57074fe crecord: log blocked time waiting for curses input
Simon Farnsworth <simonfar@fb.com>
parents: 30797
diff changeset
1470 with self.ui.timeblockedsection('crecord'):
a0c4e57074fe crecord: log blocked time waiting for curses input
Simon Farnsworth <simonfar@fb.com>
parents: 30797
diff changeset
1471 response = self.confirmationwindow(confirmtext)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1472 if response is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1473 response = "n"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1474 if response.lower().startswith("y"):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1475 return True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1476 else:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1477 return False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1478
27156
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1479 def toggleamend(self, opts, test):
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1480 """Toggle the amend flag.
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1481
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1482 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
1483 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
1484 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
1485 """
27156
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1486
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1487 try:
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1488 ver = float(util.version()[:3])
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1489 except ValueError:
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1490 ver = 1
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1491 if ver < 2.19:
30535
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1492 msg = _("The amend option is unavailable with hg versions < 2.2\n\n"
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1493 "Press any key to continue.")
27156
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1494 elif opts.get('amend') is None:
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1495 opts['amend'] = True
30535
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1496 msg = _("Amend option is turned on -- committing the currently "
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1497 "selected changes will not create a new changeset, but "
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1498 "instead update the most recently committed changeset.\n\n"
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1499 "Press any key to continue.")
27156
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1500 elif opts.get('amend') is True:
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1501 opts['amend'] = None
30535
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1502 msg = _("Amend option is turned off -- committing the currently "
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1503 "selected changes will create a new changeset.\n\n"
3899c358b45a crecord: filter text via i18n
Jun Wu <quark@fb.com>
parents: 30533
diff changeset
1504 "Press any key to continue.")
27156
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1505 if not test:
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1506 self.confirmationwindow(msg)
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1507
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1508 def recenterdisplayedarea(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1509 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1510 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
1511 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
1512 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
1513 zone and then update the scroll.
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1514 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1515 self.printitem(towin=False)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1516 self.updatescroll()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1517
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1518 def toggleedit(self, item=None, test=False):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1519 """
28580
8b41ad798fb7 crecord: fix docblock indentation
Ryan McElroy <rmcelroy@fb.com>
parents: 28579
diff changeset
1520 edit the currently selected chunk
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1521 """
25555
838fa1932ff8 crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents: 25461
diff changeset
1522 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
1523 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
1524 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
1525 self.updatescroll()
838fa1932ff8 crecord: extract ui refresh code after editing of hunk in a function
Laurent Charignon <lcharignon@fb.com>
parents: 25461
diff changeset
1526 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
1527 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
1528 self.stdscr.keypad(1)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1529
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1530 def editpatchwitheditor(self, chunk):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1531 if chunk is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1532 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
1533 self.ui.write("\n")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1534 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1535 if chunk.header.binary():
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1536 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
1537 self.ui.write("\n")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1538 return None
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1539
28636
de64020bb4ec crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28581
diff changeset
1540 # write the initial patch
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
1541 patch = stringio()
28637
4874b8efe7d2 crecord: break out the help message for editing hunks
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28636
diff changeset
1542 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
1543 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
1544 chunk.write(patch)
de64020bb4ec crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28581
diff changeset
1545
de64020bb4ec crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28581
diff changeset
1546 # 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
1547 try:
28636
de64020bb4ec crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28581
diff changeset
1548 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
1549 extra={"suffix": ".diff"})
de64020bb4ec crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28581
diff changeset
1550 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
1551 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
1552 return None
de64020bb4ec crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28581
diff changeset
1553
de64020bb4ec crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28581
diff changeset
1554 # remove comment lines
de64020bb4ec crecord: refactor hunk edit action to use ui.edit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28581
diff changeset
1555 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
1556 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
1557 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
1558
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1559 if item is None:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1560 item = self.currentselecteditem
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1561 if isinstance(item, uiheader):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1562 return
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1563 if isinstance(item, uihunkline):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1564 item = item.parentitem()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1565 if not isinstance(item, uihunk):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1566 return
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1567
27914
505a10b504ed crecord: edit during hg crecord should preserve cursor position (issue5041)
Laurent Charignon <lcharignon@fb.com>
parents: 27533
diff changeset
1568 # 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
1569 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
1570
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1571 beforeadded, beforeremoved = item.added, item.removed
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1572 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
1573 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
1574 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
1575 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
1576 return
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1577 header = item.header
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1578 editedhunkindex = header.hunks.index(item)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1579 hunksbefore = header.hunks[:editedhunkindex]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1580 hunksafter = header.hunks[editedhunkindex + 1:]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1581 newpatchheader = newpatches[0]
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1582 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
1583 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
1584 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
1585 offset = (newadded - beforeadded) - (newremoved - beforeremoved)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1586
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1587 for h in hunksafter:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1588 h.toline += offset
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1589 for h in newhunks:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1590 h.folded = False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1591 header.hunks = hunksbefore + newhunks + hunksafter
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1592 if self.emptypatch():
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1593 header.hunks = hunksbefore + [item] + hunksafter
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1594 self.currentselecteditem = header
27914
505a10b504ed crecord: edit during hg crecord should preserve cursor position (issue5041)
Laurent Charignon <lcharignon@fb.com>
parents: 27533
diff changeset
1595 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
1596 self.currentselecteditem = header.hunks[itemindex]
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1597
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1598 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
1599 updateui(self)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1600
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1601 def emptypatch(self):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1602 item = self.headerlist
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1603 if not item:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1604 return True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1605 for header in item:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1606 if header.hunks:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1607 return False
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1608 return True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1609
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1610 def handlekeypressed(self, keypressed, test=False):
28581
3c8f0a605504 crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents: 28580
diff changeset
1611 """
3c8f0a605504 crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents: 28580
diff changeset
1612 Perform actions based on pressed keys.
3c8f0a605504 crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents: 28580
diff changeset
1613
3c8f0a605504 crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents: 28580
diff changeset
1614 Return true to exit the main loop.
3c8f0a605504 crecord: add docblock to handlekeypressed
Ryan McElroy <rmcelroy@fb.com>
parents: 28580
diff changeset
1615 """
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1616 if keypressed in ["k", "KEY_UP"]:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1617 self.uparrowevent()
25460
bd4bcfa48c9e crecord: fix three typos introduced while moving crecord into core
Laurent Charignon <lcharignon@fb.com>
parents: 25447
diff changeset
1618 if keypressed in ["K", "KEY_PPAGE"]:
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1619 self.uparrowshiftevent()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1620 elif keypressed in ["j", "KEY_DOWN"]:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1621 self.downarrowevent()
25460
bd4bcfa48c9e crecord: fix three typos introduced while moving crecord into core
Laurent Charignon <lcharignon@fb.com>
parents: 25447
diff changeset
1622 elif keypressed in ["J", "KEY_NPAGE"]:
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1623 self.downarrowshiftevent()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1624 elif keypressed in ["l", "KEY_RIGHT"]:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1625 self.rightarrowevent()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1626 elif keypressed in ["h", "KEY_LEFT"]:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1627 self.leftarrowevent()
25460
bd4bcfa48c9e crecord: fix three typos introduced while moving crecord into core
Laurent Charignon <lcharignon@fb.com>
parents: 25447
diff changeset
1628 elif keypressed in ["H", "KEY_SLEFT"]:
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1629 self.leftarrowshiftevent()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1630 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
1631 raise error.Abort(_('user quit'))
27156
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1632 elif keypressed in ['a']:
55fa7c3900ae commit: add amend mode for commit -i
Laurent Charignon <lcharignon@fb.com>
parents: 27155
diff changeset
1633 self.toggleamend(self.opts, test)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1634 elif keypressed in ["c"]:
28925
ee56a86e2782 crecord: drop the extra confirmation screen
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 28861
diff changeset
1635 return True
28638
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28637
diff changeset
1636 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
1637 return True
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1638 elif keypressed in ["r"]:
28926
0411b7998d9b crecord: cleanup the remains of commit confirmation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 28925
diff changeset
1639 if self.reviewcommit():
28638
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28637
diff changeset
1640 self.opts['review'] = True
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1641 return True
28638
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28637
diff changeset
1642 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
1643 self.opts['review'] = True
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1644 return True
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1645 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
1646 self.toggleapply()
30797
0bde7372e4c0 crecord: add an experimental option for space key to move cursor down
Anton Shestakov <av6@dwimlabs.net>
parents: 30548
diff changeset
1647 if self.ui.configbool('experimental', 'spacemovesdown'):
0bde7372e4c0 crecord: add an experimental option for space key to move cursor down
Anton Shestakov <av6@dwimlabs.net>
parents: 30548
diff changeset
1648 self.downarrowevent()
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1649 elif keypressed in ['A']:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1650 self.toggleall()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1651 elif keypressed in ['e']:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1652 self.toggleedit(test=test)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1653 elif keypressed in ["f"]:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1654 self.togglefolded()
25447
093d38165e5a crecord: fix a typo introduced when moving crecord to core
Laurent Charignon <lcharignon@fb.com>
parents: 24840
diff changeset
1655 elif keypressed in ["F"]:
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1656 self.togglefolded(foldparent=True)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1657 elif keypressed in ["?"]:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1658 self.helpwindow()
25419
6e62a5b3442d crecord: fix blue artifact bug coming back from help screen
Laurent Charignon <lcharignon@fb.com>
parents: 25359
diff changeset
1659 self.stdscr.clear()
6e62a5b3442d crecord: fix blue artifact bug coming back from help screen
Laurent Charignon <lcharignon@fb.com>
parents: 25359
diff changeset
1660 self.stdscr.refresh()
29957
7d053ba73178 crecord: add an event that scrolls the selected line to the top of the screen
Nathan Goldbaum <ngoldbau@illinois.edu>
parents: 29942
diff changeset
1661 elif curses.unctrl(keypressed) in ["^L"]:
7d053ba73178 crecord: add an event that scrolls the selected line to the top of the screen
Nathan Goldbaum <ngoldbau@illinois.edu>
parents: 29942
diff changeset
1662 # scroll the current line to the top of the screen
7d053ba73178 crecord: add an event that scrolls the selected line to the top of the screen
Nathan Goldbaum <ngoldbau@illinois.edu>
parents: 29942
diff changeset
1663 self.scrolllines(self.selecteditemstartline)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1664
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1665 def main(self, stdscr):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1666 """
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1667 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
1668 """
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1669
31931
0130c3e1b1d9 crecord: avoid setting non-existing signal SIGWINCH on windows
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31930
diff changeset
1670 origsigwinch = sentinel = object()
0130c3e1b1d9 crecord: avoid setting non-existing signal SIGWINCH on windows
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31930
diff changeset
1671 if util.safehasattr(signal, 'SIGWINCH'):
0130c3e1b1d9 crecord: avoid setting non-existing signal SIGWINCH on windows
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31930
diff changeset
1672 origsigwinch = signal.signal(signal.SIGWINCH,
0130c3e1b1d9 crecord: avoid setting non-existing signal SIGWINCH on windows
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31930
diff changeset
1673 self.sigwinchhandler)
31930
7e7743a01103 crecord: ensure we reinstall the SIGWINCH handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31929
diff changeset
1674 try:
7e7743a01103 crecord: ensure we reinstall the SIGWINCH handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31929
diff changeset
1675 return self._main(stdscr)
7e7743a01103 crecord: ensure we reinstall the SIGWINCH handler
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31929
diff changeset
1676 finally:
31931
0130c3e1b1d9 crecord: avoid setting non-existing signal SIGWINCH on windows
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31930
diff changeset
1677 if origsigwinch is not sentinel:
0130c3e1b1d9 crecord: avoid setting non-existing signal SIGWINCH on windows
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31930
diff changeset
1678 signal.signal(signal.SIGWINCH, origsigwinch)
31929
bf6b44da1d8e crecord: extract most of 'main' into a sub function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31649
diff changeset
1679
bf6b44da1d8e crecord: extract most of 'main' into a sub function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31649
diff changeset
1680 def _main(self, stdscr):
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1681 self.stdscr = stdscr
25820
701d8c362aa2 crecord: add error reporting for failure in curses interface initialization
Laurent Charignon <lcharignon@fb.com>
parents: 25807
diff changeset
1682 # 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
1683 # 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
1684 self.initerr = None
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1685 self.yscreensize, self.xscreensize = self.stdscr.getmaxyx()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1686
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1687 curses.start_color()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1688 curses.use_default_colors()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1689
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1690 # 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
1691 # 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
1692 self.initcolorpair(None, None, name="normal")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1693 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
1694 name="selected")
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1695 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
1696 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
1697 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
1698 # newwin([height, width,] begin_y, begin_x)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1699 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
1700 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
1701
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1702 # 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
1703 # used for displaying the patch
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1704
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1705 # stupid hack to prevent getnumlinesdisplayed from failing
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1706 self.chunkpad = curses.newpad(1, self.xscreensize)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1707
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1708 # 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
1709 self.numpadlines = self.getnumlinesdisplayed(ignorefolding=True) + 1
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1710
25821
d68544b69736 crecord: throws error instead of crashing for large diffs
Laurent Charignon <lcharignon@fb.com>
parents: 25820
diff changeset
1711 try:
d68544b69736 crecord: throws error instead of crashing for large diffs
Laurent Charignon <lcharignon@fb.com>
parents: 25820
diff changeset
1712 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
1713 except curses.error:
d68544b69736 crecord: throws error instead of crashing for large diffs
Laurent Charignon <lcharignon@fb.com>
parents: 25820
diff changeset
1714 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
1715 return
30332
318a24b52eeb spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents: 30315
diff changeset
1716 # initialize selecteditemendline (initial start-line is 0)
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1717 self.selecteditemendline = self.getnumlinesdisplayed(
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1718 self.currentselecteditem, recursechildren=False)
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1719
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1720 while True:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1721 self.updatescreen()
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1722 try:
30981
a0c4e57074fe crecord: log blocked time waiting for curses input
Simon Farnsworth <simonfar@fb.com>
parents: 30797
diff changeset
1723 with self.ui.timeblockedsection('crecord'):
a0c4e57074fe crecord: log blocked time waiting for curses input
Simon Farnsworth <simonfar@fb.com>
parents: 30797
diff changeset
1724 keypressed = self.statuswin.getkey()
25556
40f0e9e5b821 crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents: 25555
diff changeset
1725 if self.errorstr is not None:
40f0e9e5b821 crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents: 25555
diff changeset
1726 self.errorstr = None
40f0e9e5b821 crecord: add mechanism for error reporting
Laurent Charignon <lcharignon@fb.com>
parents: 25555
diff changeset
1727 continue
24310
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1728 except curses.error:
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1729 keypressed = "foobar"
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1730 if self.handlekeypressed(keypressed):
6409fb6c934d record: add crecord's ui logic to core
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1731 break