hgext/histedit.py
changeset 48204 33ece8857efa
parent 48203 8dd2422b0109
child 48205 3fdeb657602f
equal deleted inserted replaced
48203:8dd2422b0109 48204:33ece8857efa
  1562                     curses.color_pair(rollcolor),
  1562                     curses.color_pair(rollcolor),
  1563                 )
  1563                 )
  1564 
  1564 
  1565         rulesscr.noutrefresh()
  1565         rulesscr.noutrefresh()
  1566 
  1566 
  1567 
  1567     def render_string(self, win, output, diffcolors=False):
  1568 def _chisteditmain(repo, rules, stdscr):
       
  1569     try:
       
  1570         curses.use_default_colors()
       
  1571     except curses.error:
       
  1572         pass
       
  1573 
       
  1574     # initialize color pattern
       
  1575     curses.init_pair(COLOR_HELP, curses.COLOR_WHITE, curses.COLOR_BLUE)
       
  1576     curses.init_pair(COLOR_SELECTED, curses.COLOR_BLACK, curses.COLOR_WHITE)
       
  1577     curses.init_pair(COLOR_WARN, curses.COLOR_BLACK, curses.COLOR_YELLOW)
       
  1578     curses.init_pair(COLOR_OK, curses.COLOR_BLACK, curses.COLOR_GREEN)
       
  1579     curses.init_pair(COLOR_CURRENT, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
       
  1580     curses.init_pair(COLOR_DIFF_ADD_LINE, curses.COLOR_GREEN, -1)
       
  1581     curses.init_pair(COLOR_DIFF_DEL_LINE, curses.COLOR_RED, -1)
       
  1582     curses.init_pair(COLOR_DIFF_OFFSET, curses.COLOR_MAGENTA, -1)
       
  1583     curses.init_pair(COLOR_ROLL, curses.COLOR_RED, -1)
       
  1584     curses.init_pair(
       
  1585         COLOR_ROLL_CURRENT, curses.COLOR_BLACK, curses.COLOR_MAGENTA
       
  1586     )
       
  1587     curses.init_pair(COLOR_ROLL_SELECTED, curses.COLOR_RED, curses.COLOR_WHITE)
       
  1588 
       
  1589     # don't display the cursor
       
  1590     try:
       
  1591         curses.curs_set(0)
       
  1592     except curses.error:
       
  1593         pass
       
  1594 
       
  1595     def renderstring(win, state, output, diffcolors=False):
       
  1596         maxy, maxx = win.getmaxyx()
  1568         maxy, maxx = win.getmaxyx()
  1597         length = min(maxy - 1, len(output))
  1569         length = min(maxy - 1, len(output))
  1598         for y in range(0, length):
  1570         for y in range(0, length):
  1599             line = output[y]
  1571             line = output[y]
  1600             if diffcolors:
  1572             if diffcolors:
  1612                     win.addstr(y, 0, line)
  1584                     win.addstr(y, 0, line)
  1613             else:
  1585             else:
  1614                 win.addstr(y, 0, line)
  1586                 win.addstr(y, 0, line)
  1615         win.noutrefresh()
  1587         win.noutrefresh()
  1616 
  1588 
  1617     def renderpatch(win, state):
  1589     def render_patch(self, win):
  1618         start = state.modes[MODE_PATCH][b'line_offset']
  1590         start = self.modes[MODE_PATCH][b'line_offset']
  1619         content = state.modes[MODE_PATCH][b'patchcontents']
  1591         content = self.modes[MODE_PATCH][b'patchcontents']
  1620         renderstring(win, state, content[start:], diffcolors=True)
  1592         self.render_string(win, content[start:], diffcolors=True)
       
  1593 
       
  1594 
       
  1595 def _chisteditmain(repo, rules, stdscr):
       
  1596     try:
       
  1597         curses.use_default_colors()
       
  1598     except curses.error:
       
  1599         pass
       
  1600 
       
  1601     # initialize color pattern
       
  1602     curses.init_pair(COLOR_HELP, curses.COLOR_WHITE, curses.COLOR_BLUE)
       
  1603     curses.init_pair(COLOR_SELECTED, curses.COLOR_BLACK, curses.COLOR_WHITE)
       
  1604     curses.init_pair(COLOR_WARN, curses.COLOR_BLACK, curses.COLOR_YELLOW)
       
  1605     curses.init_pair(COLOR_OK, curses.COLOR_BLACK, curses.COLOR_GREEN)
       
  1606     curses.init_pair(COLOR_CURRENT, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
       
  1607     curses.init_pair(COLOR_DIFF_ADD_LINE, curses.COLOR_GREEN, -1)
       
  1608     curses.init_pair(COLOR_DIFF_DEL_LINE, curses.COLOR_RED, -1)
       
  1609     curses.init_pair(COLOR_DIFF_OFFSET, curses.COLOR_MAGENTA, -1)
       
  1610     curses.init_pair(COLOR_ROLL, curses.COLOR_RED, -1)
       
  1611     curses.init_pair(
       
  1612         COLOR_ROLL_CURRENT, curses.COLOR_BLACK, curses.COLOR_MAGENTA
       
  1613     )
       
  1614     curses.init_pair(COLOR_ROLL_SELECTED, curses.COLOR_RED, curses.COLOR_WHITE)
       
  1615 
       
  1616     # don't display the cursor
       
  1617     try:
       
  1618         curses.curs_set(0)
       
  1619     except curses.error:
       
  1620         pass
  1621 
  1621 
  1622     def drawvertwin(size, y, x):
  1622     def drawvertwin(size, y, x):
  1623         win = curses.newwin(size[0], size[1], y, x)
  1623         win = curses.newwin(size[0], size[1], y, x)
  1624         y += size[0]
  1624         y += size[0]
  1625         return win, y, x
  1625         return win, y, x
  1673             # start rendering
  1673             # start rendering
  1674             commitwin.erase()
  1674             commitwin.erase()
  1675             helpwin.erase()
  1675             helpwin.erase()
  1676             mainwin.erase()
  1676             mainwin.erase()
  1677             if curmode == MODE_PATCH:
  1677             if curmode == MODE_PATCH:
  1678                 renderpatch(mainwin, state)
  1678                 state.render_patch(mainwin)
  1679             elif curmode == MODE_HELP:
  1679             elif curmode == MODE_HELP:
  1680                 renderstring(mainwin, state, __doc__.strip().splitlines())
  1680                 state.render_string(mainwin, __doc__.strip().splitlines())
  1681             else:
  1681             else:
  1682                 state.render_rules(mainwin)
  1682                 state.render_rules(mainwin)
  1683                 state.render_commit(commitwin)
  1683                 state.render_commit(commitwin)
  1684             state.render_help(helpwin)
  1684             state.render_help(helpwin)
  1685             curses.doupdate()
  1685             curses.doupdate()