Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.1, 1.1.1, and 1.1.2

hgtk: hgcmd color highlighting based on ui.write(msg, label="foo")

This adds support for ui.write() style labels; a feature that will be soon
be added to the Mercurial default branch - to be released in 1.6.

Closes #1122

Changeset c8fc4e8c5e64

Parent f4f7e81ec30b

by Steve Borho

Changes to 5 files · Browse files at c8fc4e8c5e64 Showing diff from parent f4f7e81ec30b Diff from another changeset...

 
10
11
12
 
13
14
15
 
60
61
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
64
65
 
10
11
12
13
14
15
16
 
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@@ -10,6 +10,7 @@
 import sys  import gtk  import gobject +import pango  import Queue  import urllib  import threading @@ -60,6 +61,25 @@
 NEW_REV_COLOR = DGREEN  CHANGE_HEADER = GREY   +TextBufferTags = { + 'error' : dict(weight=pango.WEIGHT_HEAVY, foreground=DRED), + 'control' : dict(weight=pango.WEIGHT_HEAVY, foreground=BLACK), + 'ui.status': dict(foreground=DGRAY), + 'ui.note': dict(foreground=BLACK), + 'log.description': dict(foreground=DGRAY), + 'log.changeset': dict(foreground=GREY), + 'log.tag': dict(foreground=RED), + 'log.user': dict(foreground=BLUE), + 'log.date': dict(foreground=BLACK), + 'log.files': dict(foreground=BLACK), + 'diff.diffline': dict(foreground=BLACK), + 'diff.inserted': dict(foreground=DGREEN), + 'diff.deleted': dict(foreground=RED), + 'diff.hunk': dict(foreground=BLUE), + 'diff.file_a' : dict(weight=pango.WEIGHT_HEAVY, foreground=BLACK), + 'diff.file_b' : dict(weight=pango.WEIGHT_HEAVY, foreground=BLACK), +} +  UP_ARROW_COLOR = '#feaf3e'  DOWN_ARROW_COLOR = '#8ae234'  STAR_COLOR = '#fce94f'
 
88
89
90
91
92
 
 
93
94
95
 
159
160
161
162
163
 
 
 
 
 
 
 
 
 
 
 
 
 
164
165
166
 
554
555
556
557
 
558
559
560
 
634
635
636
637
638
 
 
639
640
641
 
872
873
874
875
 
876
877
878
 
88
89
90
 
 
91
92
93
94
95
 
159
160
161
 
 
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
 
565
566
567
 
568
569
570
571
 
645
646
647
 
 
648
649
650
651
652
 
883
884
885
 
886
887
888
889
@@ -88,8 +88,8 @@
  self.textview.modify_font(pango.FontDescription(fontlog))   scrolledwindow.add(self.textview)   self.textbuffer = self.textview.get_buffer() - self.textbuffer.create_tag('error', weight=pango.WEIGHT_HEAVY, - foreground=gtklib.DRED) + for tag, argdict in gtklib.TextBufferTags.iteritems(): + self.textbuffer.create_tag(tag, **argdict)     self.vbox.pack_start(scrolledwindow, True, True)   self.connect('map_event', self._on_window_map_event) @@ -159,8 +159,19 @@
  enditer = self.textbuffer.get_end_iter()   while self.hgthread.getqueue().qsize():   try: - msg = self.hgthread.getqueue().get(0) - self.textbuffer.insert(enditer, hglib.toutf(msg)) + msg, label = self.hgthread.getqueue().get(0) + tags = [] + for tag in label.split(): + tag.strip() + if tag in gtklib.TextBufferTags: + tags.append(tag) + #else: + # print 'unknown tag:', tag + msg = hglib.toutf(msg) + if tags: + self.textbuffer.insert_with_tags_by_name(enditer, msg, *tags) + else: + self.textbuffer.insert(enditer, msg)   self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)   except Queue.Empty:   pass @@ -554,7 +565,7 @@
  # output to buffer   while self.hgthread.getqueue().qsize():   try: - msg = self.hgthread.getqueue().get(0) + msg, label = self.hgthread.getqueue().get(0)   self.log.append(hglib.toutf(msg))   except Queue.Empty:   pass @@ -634,8 +645,8 @@
    # text buffer   self.buffer = self.textview.get_buffer() - self.buffer.create_tag('error', weight=pango.WEIGHT_HEAVY, - foreground=gtklib.DRED) + for tag, argdict in gtklib.TextBufferTags.iteritems(): + self.buffer.create_tag(tag, **argdict)     ### public functions ###   @@ -872,7 +883,7 @@
  # receive messages from queue   while self.hgthread.getqueue().qsize():   try: - msg = hglib.toutf(self.hgthread.getqueue().get(0)) + msg = hglib.toutf(self.hgthread.getqueue().get(0)[0])   self.buffer.append((msg, LOG_NORMAL))   self.dlg.log.append(msg)   except Queue.Empty:
 
42
43
44
45
46
 
 
 
 
47
48
 
49
50
 
51
52
53
 
 
 
54
55
56
 
168
169
170
 
171
172
173
 
174
175
176
 
 
177
178
179
 
42
43
44
 
 
45
46
47
48
49
 
50
51
 
52
53
54
55
56
57
58
59
60
61
 
173
174
175
176
177
178
 
179
180
 
 
181
182
183
184
185
@@ -42,15 +42,20 @@
  self.setconfig('ui', 'interactive', 'on')   self.setconfig('progress', 'disable', 'True')   - def write(self, *args): - if hglib.uiwrite(self, args): + def write(self, *args, **opts): + if self._buffers: + self._buffers[-1].extend([str(a) for a in args]) + else:   for a in args: - self.outputq.put(str(a)) + self.outputq.put((str(a), opts.get('label', '')))   - def write_err(self, *args): + def write_err(self, *args, **opts):   for a in args:   self.errorq.put(str(a))   + def label(self, msg, label): + return msg +   def flush(self):   pass   @@ -168,12 +173,13 @@
  try:   for k, v in self.ui.configitems('defaults'):   self.ui.setconfig('defaults', k, '') + l = 'control'   ret = hglib.dispatch._dispatch(self.ui, self.args)   if ret: - self.ui.write(_('[command returned code %d ') % int(ret)) + self.ui.write(_('[command returned code %d ') % int(ret), label=l)   else: - self.ui.write(_('[command completed successfully ')) - self.ui.write(time.asctime() + ']\n') + self.ui.write(_('[command completed successfully '), label=l) + self.ui.write(time.asctime() + ']\n', label=l)   self.ret = ret or 0   if self.postfunc:   self.postfunc(ret)
 
245
246
247
248
249
 
 
250
251
252
 
601
602
603
 
604
605
606
607
 
 
 
 
 
 
 
 
 
 
 
 
608
609
610
 
245
246
247
 
 
248
249
250
251
252
 
601
602
603
604
605
606
 
 
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
@@ -245,8 +245,8 @@
  scrolledwindow.add(self.textview)   self.textview.connect('populate-popup', self.add_to_popup)   self.textbuffer = self.textview.get_buffer() - self.textbuffer.create_tag('error', weight=pango.WEIGHT_HEAVY, - foreground=gtklib.DRED) + for tag, argdict in gtklib.TextBufferTags.iteritems(): + self.textbuffer.create_tag(tag, **argdict)   basevbox.pack_start(scrolledwindow, True, True)     # statusbar @@ -601,10 +601,21 @@
  Handle all the messages currently in the queue (if any).   """   self.hgthread.process_dialogs() + enditer = self.textbuffer.get_end_iter()   while self.hgthread.getqueue().qsize():   try: - msg = self.hgthread.getqueue().get(0) - self.write(msg) + msg, label = self.hgthread.getqueue().get(0) + tags = [] + for tag in label.split(): + tag.strip() + if tag in gtklib.TextBufferTags: + tags.append(tag) + msg = hglib.toutf(msg) + if tags: + self.textbuffer.insert_with_tags_by_name(enditer, msg, *tags) + else: + self.textbuffer.insert(enditer, msg) + self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)   except Queue.Empty:   pass   while self.hgthread.geterrqueue().qsize():
 
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
 
330
331
332
333
334
 
 
 
 
335
336
337
 
162
163
164
 
 
 
 
 
 
 
 
 
 
165
166
167
 
320
321
322
 
 
323
324
325
326
327
328
329
@@ -162,16 +162,6 @@
  _fontconfig[name] = val   return _fontconfig   -def uiwrite(u, args): - ''' - write args if there are buffers - returns True if the caller shall handle writing - ''' - if u._buffers: - ui.ui.write(u, *args) - return False - return True -  def invalidaterepo(repo):   repo.dirstate.invalidate()   if isinstance(repo, bundlerepo.bundlerepository): @@ -330,8 +320,10 @@
  super(Qui, self).__init__(src)   self.setconfig('ui', 'interactive', 'off')   - def write(self, *args): - if uiwrite(self, args): + def write(self, *args, **opts): + if self._buffers: + self._buffers[-1].extend([str(a) for a in args]) + else:   for a in args:   q.put(str(a))   u = Qui()