0
0
Fork 0

Removes test file and updates to more complete path handling and string indentation

This commit is contained in:
sloum 2020-04-19 15:02:08 -07:00
parent 38b9f23d36
commit f97907df0c
2 changed files with 14 additions and 24 deletions

11
adf
View File

@ -1,11 +0,0 @@
This is
a test
to see
how well
things will
This is
a test
work when
I start
using the
new features

27
chalk
View File

@ -99,9 +99,9 @@ def print_help():
" {}!i{} - Insert empty line(s) (will request location/count)".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), " {}!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), # TODO " {}!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), # TODO " {}!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), # TODO " {}!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), " {}!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), " {}!a{} - Save as a new file (will request file location)".format(c.b_green, c.end),
@ -145,15 +145,16 @@ def build_contents_from_file(path):
global content global content
global filepath global filepath
global filename global filename
filepath = os.path.abspath(path) path = os.path.abspath(path)
filename = path.split('/')[-1] filepath = os.path.expanduser(path)
filename = filepath.split('/')[-1]
try: try:
valid_path = validate_path(filepath) valid_path = validate_path(filepath)
if not valid_path: if not valid_path:
print('Invalid file path') print('Invalid file path')
os.exit(2) os.exit(2)
with open(os.path.abspath(filepath), 'r') as f: with open(filepath, 'r') as f:
content = f.read().split('\n') content = f.read().split('\n')
if content[-1] == '': if content[-1] == '':
content.pop() content.pop()
@ -266,14 +267,14 @@ def save_changes():
try: try:
with open(filepath, 'w') as f: with open(filepath, 'w') as f:
f.write(text) f.write(text)
print('Saved \033[1m{}\033[0m'.format(filename)) print(' Saved \033[1m{}\033[0m'.format(filename))
file_changed = False file_changed = False
return True return True
except PermissionError: except PermissionError:
print('{} You do not have permission to write to this file.{}'.format(c.red, c.end)) print('{} You do not have permission to write to this file.{}'.format(c.red, c.end))
return False return False
except: except:
print('{} Error while writing to file: {}{}'.format(c.red, e, c.end)) print('{} Error while writing to file: {}{}'.format(c.red, e, c.end))
return False return False
@ -293,7 +294,8 @@ def save_as():
if not continue_save_as: if not continue_save_as:
print('{:9}Save canceled.'.format(' ')) print('{:9}Save canceled.'.format(' '))
fp = os.path.abspath(path) path = os.path.abspath(path)
fp = os.path.expanduser(path)
fn = path.split('/')[-1] fn = path.split('/')[-1]
valid = check_file_writable(fp) valid = check_file_writable(fp)
if not valid: if not valid:
@ -309,17 +311,16 @@ def save_as():
# are any unsaved changes # are any unsaved changes
def quit(): def quit():
if not file_changed: if not file_changed:
print('{}exiting...{}\n'.format(c.white, c.end))
sys.exit(0) sys.exit(0)
save = yes_no('{}Save changes to {}?{} (Y/n) '.format(c.b_green, filename, c.end)) save = yes_no(' {}Save changes to {}?{} (Y/n) '.format(c.b_green, filename, c.end))
if save: if save:
saved = save_changes() saved = save_changes()
if saved: if saved:
print(' File "{}" has been saved.'.format(filename))
sys.exit(0) sys.exit(0)
else: else:
sys.exit(1) sys.exit(1)
else: else:
print('{}exiting...{}\n'.format(c.white, c.end))
sys.exit(0) sys.exit(0)