Removes test file and updates to more complete path handling and string indentation
This commit is contained in:
parent
38b9f23d36
commit
f97907df0c
11
adf
11
adf
|
@ -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
27
chalk
|
@ -99,9 +99,9 @@ def print_help():
|
|||
" {}!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), # TODO
|
||||
" {}!p{} - Paste from the paste buffer (will request destination)".format(c.b_green, c.end), # TODO
|
||||
" {}!b{} - Buffer view (print the paste buffer)".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),
|
||||
" {}!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),
|
||||
|
@ -145,15 +145,16 @@ def build_contents_from_file(path):
|
|||
global content
|
||||
global filepath
|
||||
global filename
|
||||
filepath = os.path.abspath(path)
|
||||
filename = path.split('/')[-1]
|
||||
path = os.path.abspath(path)
|
||||
filepath = os.path.expanduser(path)
|
||||
filename = filepath.split('/')[-1]
|
||||
try:
|
||||
valid_path = validate_path(filepath)
|
||||
if not valid_path:
|
||||
print('Invalid file path')
|
||||
os.exit(2)
|
||||
|
||||
with open(os.path.abspath(filepath), 'r') as f:
|
||||
with open(filepath, 'r') as f:
|
||||
content = f.read().split('\n')
|
||||
if content[-1] == '':
|
||||
content.pop()
|
||||
|
@ -266,14 +267,14 @@ def save_changes():
|
|||
try:
|
||||
with open(filepath, 'w') as f:
|
||||
f.write(text)
|
||||
print('Saved \033[1m{}\033[0m'.format(filename))
|
||||
print(' Saved \033[1m{}\033[0m'.format(filename))
|
||||
file_changed = False
|
||||
return True
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
|
@ -293,7 +294,8 @@ def save_as():
|
|||
if not continue_save_as:
|
||||
print('{:9}Save canceled.'.format(' '))
|
||||
|
||||
fp = os.path.abspath(path)
|
||||
path = os.path.abspath(path)
|
||||
fp = os.path.expanduser(path)
|
||||
fn = path.split('/')[-1]
|
||||
valid = check_file_writable(fp)
|
||||
if not valid:
|
||||
|
@ -309,17 +311,16 @@ def save_as():
|
|||
# are any unsaved changes
|
||||
def quit():
|
||||
if not file_changed:
|
||||
print('{}exiting...{}\n'.format(c.white, c.end))
|
||||
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:
|
||||
saved = save_changes()
|
||||
if saved:
|
||||
print(' File "{}" has been saved.'.format(filename))
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.exit(1)
|
||||
else:
|
||||
print('{}exiting...{}\n'.format(c.white, c.end))
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue