diff --git a/chalk b/chalk index b47188b..d0e39ea 100755 --- a/chalk +++ b/chalk @@ -28,6 +28,7 @@ paste_buffer = [] file_changed = False filepath = '' filename = '' +view_loc = {'last': 0, 'count': 0} ########################################################### @@ -98,23 +99,24 @@ def print_help(): "", "{}Commands are entered as the only entry for their row:{}".format(c.yellow, c.end), "", - " {}!?{} - Print this help message".format(c.b_green, c.end), - " {}!g{} - Print the ruler/guide".format(c.b_green, c.end), + " {}.?{} - Print this help message".format(c.b_green, c.end), + " {}.g{} - Print the ruler/guide".format(c.b_green, c.end), "", - " {}!d{} - Display the whole file".format(c.b_green, c.end), - " {}!v{} - View range of lines (will request line range)".format(c.b_green, c.end), + " {}.d{} - Display the whole file".format(c.b_green, c.end), + " {}.v{} - View range of lines (will request location/count)".format(c.b_green, c.end), + " {}.m{} - View MORE (use after using !v to see more)".format(c.b_green, c.end), "", - " {}!#{} - Edit a line (i.e. !27)".format(c.b_green, c.end), - " {}!i{} - Insert empty line(s) (will request location/count)".format(c.b_green, c.end), - " {}!x{} - Cut/copy line(s) (will request line range)".format(c.b_green, c.end), + " {}.#{} - Edit a line (eg .27)".format(c.b_green, c.end), + " {}.i{} - Insert empty line(s) (will request location/count)".format(c.b_green, c.end), + " {}.x{} - Cut/copy line(s) (will request line range)".format(c.b_green, c.end), "", - " {}!c{} - Copy to the paste buffer (will request line range)".format(c.b_green, c.end), - " {}!p{} - Paste from the paste buffer (will request destination)".format(c.b_green, c.end), - " {}!b{} - Buffer view (print the paste buffer)".format(c.b_green, c.end), + " {}.c{} - Copy to the paste buffer (will request line range)".format(c.b_green, c.end), + " {}.p{} - Paste from the paste buffer (will request destination)".format(c.b_green, c.end), + " {}.b{} - Buffer view (print the paste buffer)".format(c.b_green, c.end), "", - " {}!s{} - Save changes to the document".format(c.b_green, c.end), - " {}!a{} - Save as a new file (will request file location)".format(c.b_green, c.end), - " {}.{} - Finish writing/exit (will prompt for save)".format(c.b_green, c.end), + " {}.s{} - Save changes to the document".format(c.b_green, c.end), + " {}.a{} - Save as a new file (will request file location)".format(c.b_green, c.end), + " {}. {} - Finish writing/exit (will prompt for save)".format(c.b_green, c.end), "", "{}- - -{}".format(c.yellow, c.end), "" @@ -204,10 +206,10 @@ def chalk(path): # End the editing session (quit) # Will query for save if the file has been changed quit() - elif re.match(r'^\!\d+$',ln): + elif re.match(r'^\.\d+$',ln): # Edit a previous line edit_line(ln) - elif len(ln) == 2 and ln[0] == '!': + elif len(ln) == 2 and ln[0] == '.': # Route a command command_router(ln) else: @@ -218,28 +220,30 @@ def chalk(path): # Command router takes a command line and routes it to its # command function def command_router(ln): - if ln == '!?': + if ln == '.?': print_help() - elif ln == '!g': - print_ruler() - elif ln == '!d': - display_file() - elif ln == '!v': - view_rows() - elif ln == '!i': - insert_lines() - elif ln == '!x': - cut_lines() - elif ln == '!c': - copy_rows() - elif ln == '!p': - paste_from_buffer() - elif ln == '!b': - view_paste_buffer() - elif ln == '!s': - save_changes() - elif ln == '!a': + elif ln == '.a': save_as() + elif ln == '.b': + view_paste_buffer() + elif ln == '.c': + copy_rows() + elif ln == '.d': + display_file() + elif ln == '.g': + print_ruler() + elif ln == '.i': + insert_lines() + elif ln == '.m': + view_continue() + elif ln == '.p': + paste_from_buffer() + elif ln == '.v': + view_rows() + elif ln == '.x': + cut_lines() + elif ln == '.s': + save_changes() else: print('{:9}{}Unknown command: {}{}'.format(' ', c.red, ln, c.end)) @@ -407,31 +411,56 @@ def insert_lines(): def view_rows(): + global view_loc print('{:9}{}Enter the line number you want to start viewing from:{}'.format(' ', c.cyan, c.end)) start = input('{:6} {}>{} '.format(' ', c.yellow, c.end)) - print('{:9}{}Enter the last line you want to view ($ for end of file):{}'.format(' ', c.cyan, c.end)) - finish = input('{:6} {}>{} '.format(' ', c.yellow, c.end)) - if finish == '$': - finish = len(content) - 1 + print('{:9}{}Enter the number of rows you want to view{}:'.format(' ', c.cyan, c.end)) + count = input('{:6} {}>{} '.format(' ', c.yellow, c.end)) try: beg = int(start) - end = int(finish) + counter = int(count) - if beg > end or beg < 0 or end > len(content) - 1: - print('{}{:9}Invalid entry x{}'.format(c.red, ' ', c.end)) + if beg > len(content) - 1: + print('{}{:9}Cannot start viewing past the end of the file{}') + + + if beg < 0 or beg > len(content) - 1: + print('{}{:9}Invalid view location{}'.format(c.red, ' ', c.end)) return else: + view_loc['count'] = counter print('') - for num, ln in enumerate(content[beg:end+1]): - print('{:6} - {}{}{}'.format(num+beg, c.green, ln, c.end)) + while counter > 0 and beg < len(content): + print('{:6} - {}{}{}'.format(beg, c.green, content[beg], c.end)) + counter -= 1 + beg += 1 print('') + view_loc['last'] = beg if beg < len(content) - 1 else None except: print('{}{:8} Invalid entry{}'.format(c.red, ' ', c.end)) +def view_continue(): + global view_loc + if not view_loc['count'] or view_loc['last'] is None: + print('{}{:9}There is not a current view opperation to continue{}'.format(c.red, ' ', c.end)) + return + beg = view_loc['last'] + counter = view_loc['count'] + print('') + while counter > 0 and beg < len(content): + print('{:6} - {}{}{}'.format(beg, c.green, content[beg], c.end)) + counter -= 1 + beg += 1 + print('') + view_loc['last'] = beg if beg < len(content) - 1 else None + + + + def copy_rows(): global paste_buffer