Mercurial > hg
comparison hgext/histedit.py @ 48203:8dd2422b0109
chistedit: move renderrules() onto state class
Differential Revision: https://phab.mercurial-scm.org/D11639
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 11 Oct 2021 23:04:29 -0700 |
parents | 9006eafa0942 |
children | 33ece8857efa |
comparison
equal
deleted
inserted
replaced
48202:9006eafa0942 | 48203:8dd2422b0109 |
---|---|
1515 b'commit': (12, maxx), | 1515 b'commit': (12, maxx), |
1516 b'help': (helplen, maxx), | 1516 b'help': (helplen, maxx), |
1517 b'main': (mainlen, maxx), | 1517 b'main': (mainlen, maxx), |
1518 } | 1518 } |
1519 | 1519 |
1520 | 1520 def render_rules(self, rulesscr): |
1521 def _chisteditmain(repo, rules, stdscr): | 1521 rules = self.rules |
1522 try: | 1522 pos = self.pos |
1523 curses.use_default_colors() | 1523 selected = self.selected |
1524 except curses.error: | 1524 start = self.modes[MODE_RULES][b'line_offset'] |
1525 pass | |
1526 | |
1527 # initialize color pattern | |
1528 curses.init_pair(COLOR_HELP, curses.COLOR_WHITE, curses.COLOR_BLUE) | |
1529 curses.init_pair(COLOR_SELECTED, curses.COLOR_BLACK, curses.COLOR_WHITE) | |
1530 curses.init_pair(COLOR_WARN, curses.COLOR_BLACK, curses.COLOR_YELLOW) | |
1531 curses.init_pair(COLOR_OK, curses.COLOR_BLACK, curses.COLOR_GREEN) | |
1532 curses.init_pair(COLOR_CURRENT, curses.COLOR_WHITE, curses.COLOR_MAGENTA) | |
1533 curses.init_pair(COLOR_DIFF_ADD_LINE, curses.COLOR_GREEN, -1) | |
1534 curses.init_pair(COLOR_DIFF_DEL_LINE, curses.COLOR_RED, -1) | |
1535 curses.init_pair(COLOR_DIFF_OFFSET, curses.COLOR_MAGENTA, -1) | |
1536 curses.init_pair(COLOR_ROLL, curses.COLOR_RED, -1) | |
1537 curses.init_pair( | |
1538 COLOR_ROLL_CURRENT, curses.COLOR_BLACK, curses.COLOR_MAGENTA | |
1539 ) | |
1540 curses.init_pair(COLOR_ROLL_SELECTED, curses.COLOR_RED, curses.COLOR_WHITE) | |
1541 | |
1542 # don't display the cursor | |
1543 try: | |
1544 curses.curs_set(0) | |
1545 except curses.error: | |
1546 pass | |
1547 | |
1548 def renderrules(rulesscr, state): | |
1549 rules = state.rules | |
1550 pos = state.pos | |
1551 selected = state.selected | |
1552 start = state.modes[MODE_RULES][b'line_offset'] | |
1553 | 1525 |
1554 conflicts = [r.ctx for r in rules if r.conflicts] | 1526 conflicts = [r.ctx for r in rules if r.conflicts] |
1555 if len(conflicts) > 0: | 1527 if len(conflicts) > 0: |
1556 line = b"potential conflict in %s" % b','.join( | 1528 line = b"potential conflict in %s" % b','.join( |
1557 map(pycompat.bytestr, conflicts) | 1529 map(pycompat.bytestr, conflicts) |
1558 ) | 1530 ) |
1559 addln(rulesscr, -1, 0, line, curses.color_pair(COLOR_WARN)) | 1531 addln(rulesscr, -1, 0, line, curses.color_pair(COLOR_WARN)) |
1560 | 1532 |
1561 for y, rule in enumerate(rules[start:]): | 1533 for y, rule in enumerate(rules[start:]): |
1562 if y >= state.page_height: | 1534 if y >= self.page_height: |
1563 break | 1535 break |
1564 if len(rule.conflicts) > 0: | 1536 if len(rule.conflicts) > 0: |
1565 rulesscr.addstr(y, 0, b" ", curses.color_pair(COLOR_WARN)) | 1537 rulesscr.addstr(y, 0, b" ", curses.color_pair(COLOR_WARN)) |
1566 else: | 1538 else: |
1567 rulesscr.addstr(y, 0, b" ", curses.COLOR_BLACK) | 1539 rulesscr.addstr(y, 0, b" ", curses.COLOR_BLACK) |
1589 rule.desc, | 1561 rule.desc, |
1590 curses.color_pair(rollcolor), | 1562 curses.color_pair(rollcolor), |
1591 ) | 1563 ) |
1592 | 1564 |
1593 rulesscr.noutrefresh() | 1565 rulesscr.noutrefresh() |
1566 | |
1567 | |
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 | 1594 |
1595 def renderstring(win, state, output, diffcolors=False): | 1595 def renderstring(win, state, output, diffcolors=False): |
1596 maxy, maxx = win.getmaxyx() | 1596 maxy, maxx = win.getmaxyx() |
1597 length = min(maxy - 1, len(output)) | 1597 length = min(maxy - 1, len(output)) |
1598 for y in range(0, length): | 1598 for y in range(0, length): |
1677 if curmode == MODE_PATCH: | 1677 if curmode == MODE_PATCH: |
1678 renderpatch(mainwin, state) | 1678 renderpatch(mainwin, state) |
1679 elif curmode == MODE_HELP: | 1679 elif curmode == MODE_HELP: |
1680 renderstring(mainwin, state, __doc__.strip().splitlines()) | 1680 renderstring(mainwin, state, __doc__.strip().splitlines()) |
1681 else: | 1681 else: |
1682 renderrules(mainwin, state) | 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() |
1686 # done rendering | 1686 # done rendering |
1687 ch = encoding.strtolocal(stdscr.getkey()) | 1687 ch = encoding.strtolocal(stdscr.getkey()) |