import curses

CHECKBOX_INDEX = -1
CHECKBOX_POSITION = 1
CHECKBOX_WIDTH = 4


class Item:
    def __init__(self, text, completed=False):
        self.text = text
        self.completed = completed

    def __str__(self):
        format_string = '[x] {}' if self.completed else '[ ] {}'
        return format_string.format(self.text)


class Position:
    def __init__(self, y, x):
        self.y = y
        self.x = x

    def __add__(self, other):
        new_y, new_x = self.y + other.y, self.x + other.x
        return Position(new_y, new_x)

    def to_screen(self):
        screen_y = self.y
        screen_x = CHECKBOX_POSITION if self.x == CHECKBOX_INDEX else CHECKBOX_WIDTH + self.x
        return screen_y, screen_x


def initialize():
    stdscr = curses.initscr()
    curses.noecho()
    curses.cbreak()
    stdscr.keypad(True)
    return stdscr


def draw_screen(scr, items, position):
    for i in range(len(items)):
        item = items[i]
        scr.addstr(i, 0, str(item))

    scr.move(*position.to_screen())
    scr.refresh()


def finalize(stdscr):
    curses.nocbreak()
    stdscr.keypad(False)
    curses.echo()
    curses.endwin()


def main():
    stdscr = initialize()
    items = [Item('', False), Item('', False), Item('', True)]
    movement = {'h': Position(0, -1), 'j': Position(1, 0), 'k': Position(-1, 0), 'l': Position(0, 1)}
    position = Position(0, 0)

    while True:
        draw_screen(stdscr, items, position)
        key = stdscr.getkey()

        if key == 'q':
            break
        elif key in movement:
            new_position = position + movement[key]
            if 0 <= new_position.y < len(items):
                if CHECKBOX_INDEX <= new_position.x <= len(items[new_position.y].text):
                    position = new_position


    finalize(stdscr)

if __name__ == '__main__':
    main()
@@ -6,16 +6,28 @@
 t curses
+%0Aimport enum
 %0A%0ACHECKB
@@ -81,16 +81,103 @@
 DTH = 4%0A
+KEY_ESCAPE = 27%0A%0A%0Aclass Mode(enum.Enum):%0A    normal = 1%0A    insert = 2%0A    replace = 3%0A
 %0A%0Aclass 
@@ -820,16 +820,302 @@
 een_x%0A%0A%0A
+MODE_STRINGS = %7BMode.normal: '',%0A                Mode.insert: '-- INSERT --',%0A                Mode.replace: '-- REPLACE --'%7D%0A%0AMOVE_KEYS = %7Bord('h'): Position(0, -1),%0A             ord('j'): Position(1, 0),%0A             ord('k'): Position(-1, 0),%0A             ord('l'): Position(0, 1)%7D%0A%0A%0A
 def init
@@ -1198,32 +1198,8 @@
 k()%0A
-    stdscr.keypad(True)%0A
     
@@ -1250,18 +1250,41 @@
 position
-):
+, mode):%0A    scr.clear()%0A
 %0A    for
@@ -1377,57 +1377,385 @@
     
-scr.move(*position.to_screen())%0A    scr.refresh()
+max_y = scr.getmaxyx()%5B0%5D - 1%0A    scr.addstr(max_y, 0, MODE_STRINGS%5Bmode%5D)%0A%0A    scr.refresh()%0A    scr.move(*position.to_screen())%0A%0A%0Adef safe_move(position, move, items):%0A    new_position = position + move%0A    if 0 %3C= new_position.y %3C len(items):%0A        if CHECKBOX_INDEX %3C= new_position.x %3C= len(items%5Bnew_position.y%5D.text):%0A            return new_position%0A    return position
 %0A%0A%0Ad
@@ -1766,22 +1766,16 @@
 inalize(
-stdscr
 ):%0A    c
@@ -1795,33 +1795,8 @@
 k()%0A
-    stdscr.keypad(False)%0A
     
@@ -1942,103 +1942,24 @@
   mo
-vement = %7B'h': Position(0, -1), 'j': Position(1, 0), 'k': Position(-1, 0), 'l': Position(0, 1)%7D
+de = Mode.normal
 %0A   
@@ -2045,16 +2045,22 @@
 position
+, mode
 )%0A      
@@ -2077,19 +2077,18 @@
 dscr.get
-key
+ch
 ()%0A%0A    
@@ -2105,11 +2105,16 @@
  == 
+ord(
 'q'
+)
 :%0A  
@@ -2146,258 +2146,325 @@
 lif 
-key in movement:%0A            new_position = position + movement%5Bkey%5D%0A            if 0 %3C= new_position.y %3C len(items):%0A                if CHECKBOX_INDEX %3C= new_position.x %3C= len(items%5Bnew_position.y%5D.text):%0A                    position = new_position%0A
+mode == Mode.normal and key == ord('i'):%0A            mode = Mode.insert%0A        elif mode == Mode.normal and key == ord('r'):%0A            mode = Mode.replace%0A        elif key == KEY_ESCAPE:%0A            mode = Mode.normal%0A        elif key in MOVE_KEYS:%0A            position = safe_move(position, MOVE_KEYS%5Bkey%5D, items)
 %0A%0A  
@@ -2474,22 +2474,16 @@
 inalize(
-stdscr
 )%0A%0Aif __

Implement basic mode swapping