Skip to content

Commit

Permalink
No longer ask to save when there are no changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sloumdrone committed Feb 1, 2019
1 parent 2c2551d commit afe2d41
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions chalk
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def chalk(path):
if content[-1] == '':
content.pop()

edited_file = False

print('\n Chalk 0.8 by sloum')
print('\n{} Writing:{} {}{}'.format(c.yellow, c.white, fn, c.end))
print(" For a command list, enter {}!?\n{}".format(c.green, c.end))
Expand Down Expand Up @@ -134,6 +136,7 @@ def chalk(path):
if beg < 0:
continue
content = content[:beg] + content[end:]
edited_file = True
except:
print('{}{:8} Invalid entry{}'.format(c.red, ' ', c.end))
print('')
Expand All @@ -151,6 +154,7 @@ def chalk(path):
while count > 0:
content.insert(beg,'')
count -= 1
edited_file = True
except:
print('{}{:8} Invalid entry{}'.format(c.red, ' ', c.end))
print('')
Expand Down Expand Up @@ -187,12 +191,19 @@ def chalk(path):
print('{:8} Cancelled...'.format(' '))
else:
content[row] = newln
edited_file = True
except:
print('{}{:8} Invalid entry!{}'.format(c.b_red, ' ', c.end))
print('')
print(header)
else:
edited_file = True
content.append(ln)
edited_file = True

if not edited_file:
print('{}exiting...{}\n'.format(c.white, c.end))
sys.exit(0)

confirmation = ''
while confirmation.lower() not in ['y','yes','n','no']:
Expand All @@ -209,10 +220,13 @@ def chalk(path):
with open(valid_path, 'w') as f:
f.write(text)
print('Done.\n')
sys.exit(0)
except:
print('{} You do not have permission to write to this file.{}'.format(c.red, c.end))
sys.exit(1)
else:
print('{}exiting...{}\n'.format(c.white, c.end))
sys.exit(0)


if __name__ == '__main__':
Expand Down

0 comments on commit afe2d41

Please sign in to comment.