<commit_before>import curses
import re
from editor import Editor


nonwords = ' .,;-_'

def main():
    running = True
    
    import settings

    default_note = settings.args['default_note']
    editor = Editor(default_note)

    end_state = None

    while running:
        try:
            editor.draw_screen()
            cy, cx = editor.cursor

            c = editor.screen.getch()
            handled_key = False
            for key, shortcut in settings.shortcuts:
                if c == ord(key)-64:
                    if shortcut == 'quit':
                        if editor.altered:
                            result = editor.dialog('Save before quitting? (Y or N)', yesno=True)
                            
                            if result is None: 
                                pass
                            elif result:
                                editor.save_note(editor.current_note)
                                running = False
                            else: running = False
                        else: running = False
                        
                    elif shortcut == 'save':
                        editor.save_note(editor.current_note)
                        if editor.current_note == '**settings**':
                            settings = reload(settings)
                        
                    elif shortcut == 'goto note':
                        result = editor.dialog('Enter the name of the note to load (^C to cancel):')
                        if result:
                            editor.load_note(result)
                            
                    elif shortcut == 'forward':
                        editor.forward()
                        
                    elif shortcut == 'back':
                        editor.back()
                        
                    elif shortcut == 'new note':
                        editor.load_note(None)
                        
                    elif shortcut == 'settings':
                        editor.load_note('**settings**')
                        
                    elif shortcut == 'paste':
                        # TODO: paste multiple lines bug
                        if editor.cuts:
                            if cy == len(editor.buffer): editor.buffer.append('')
                            editor.buffer = editor.buffer[:cy] + editor.cuts + editor.buffer[cy:]
                            editor.correct_cursor(cy+len(editor.cuts), cx)
                            editor.cutting = False
                    
                    elif shortcut == 'cut':
                        if cy < len(editor.buffer):
                            if editor.cutting:
                                editor.cuts += [editor.buffer[cy]]
                            else:
                                editor.cuts = [editor.buffer[cy]]
                            
                            editor.buffer = editor.buffer[:cy] + (editor.buffer[cy+1:] if cy < len(editor.buffer)-1 else [])
                            editor.correct_cursor(cy, 0)
                            editor.cutting = True
                        
                    handled_key = True
            if not handled_key:
                if c == curses.KEY_UP:
                    editor.correct_cursor(cy-1, min(cx, len(editor.buffer[cy-1]) if 0 <= cy-1 < len(editor.buffer) else 0))
                    editor.cutting = False
                elif c == curses.KEY_DOWN:
                    editor.correct_cursor(cy+1, cx)
                    editor.cutting = False
                elif c == curses.KEY_LEFT:
                    editor.correct_cursor(cy, cx-1)<commit_msg>Removing obsolete TODO.<commit_after>import curses
import re
from editor import Editor


nonwords = ' .,;-_'

def main():
    running = True
    
    import settings

    default_note = settings.args['default_note']
    editor = Editor(default_note)

    end_state = None

    while running:
        try:
            editor.draw_screen()
            cy, cx = editor.cursor

            c = editor.screen.getch()
            handled_key = False
            for key, shortcut in settings.shortcuts:
                if c == ord(key)-64:
                    if shortcut == 'quit':
                        if editor.altered:
                            result = editor.dialog('Save before quitting? (Y or N)', yesno=True)
                            
                            if result is None: 
                                pass
                            elif result:
                                editor.save_note(editor.current_note)
                                running = False
                            else: running = False
                        else: running = False
                        
                    elif shortcut == 'save':
                        editor.save_note(editor.current_note)
                        if editor.current_note == '**settings**':
                            settings = reload(settings)
                        
                    elif shortcut == 'goto note':
                        result = editor.dialog('Enter the name of the note to load (^C to cancel):')
                        if result:
                            editor.load_note(result)
                            
                    elif shortcut == 'forward':
                        editor.forward()
                        
                    elif shortcut == 'back':
                        editor.back()
                        
                    elif shortcut == 'new note':
                        editor.load_note(None)
                        
                    elif shortcut == 'settings':
                        editor.load_note('**settings**')
                        
                    elif shortcut == 'paste':
                        if editor.cuts:
                            if cy == len(editor.buffer): editor.buffer.append('')
                            editor.buffer = editor.buffer[:cy] + editor.cuts + editor.buffer[cy:]
                            editor.correct_cursor(cy+len(editor.cuts), cx)
                            editor.cutting = False
                    
                    elif shortcut == 'cut':
                        if cy < len(editor.buffer):
                            if editor.cutting:
                                editor.cuts += [editor.buffer[cy]]
                            else:
                                editor.cuts = [editor.buffer[cy]]
                            
                            editor.buffer = editor.buffer[:cy] + (editor.buffer[cy+1:] if cy < len(editor.buffer)-1 else [])
                            editor.correct_cursor(cy, 0)
                            editor.cutting = True
                        
                    handled_key = True
            if not handled_key:
                if c == curses.KEY_UP:
                    editor.correct_cursor(cy-1, min(cx, len(editor.buffer[cy-1]) if 0 <= cy-1 < len(editor.buffer) else 0))
                    editor.cutting = False
                elif c == curses.KEY_DOWN:
                    editor.correct_cursor(cy+1, cx)
                    editor.cutting = False
                elif c == curses.KEY_LEFT:
                    editor.correct_cursor(cy, cx-1)
{'fraction_non_alphanumeric': 0.08291078525421407, 'fraction_numerical': 0.0032890228861175825, 'mean_word_length': 0.8789907312049433, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1935104', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1537, 'n_words': 378}