Adds readme and fixes buggy readline behavior when escape sequences are used
This commit is contained in:
parent
f97907df0c
commit
3e9013ea35
45
README.md
45
README.md
|
@ -1,35 +1,36 @@
|
|||
# chalk
|
||||
# chalk - a line based text editor
|
||||
|
||||
Chalk is a line based text editor for the terminal. It was originally developed for _colorsh_ a custom shell used for ssh accounts on the developers server. It has been split out here as its own application.
|
||||
Chalk is a line based text editor for the terminal. It was originally an integrated part of _colorsh_, a custom shell used for ssh accounts at [Colorfield Space](gopher://colorfield.space:70/). This repo adds features and develops it into a more full and usable application.
|
||||
|
||||
### Install
|
||||
I tend to think about chalk as a simpler ed, similar to how some people use nano as simpler terminal editor than vi. It is far less powerful than ed, but functions in a similar line by line style with easy commands that walk you through the actions you are wanting to perform.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
Requires Python 3.6+. No other Python dependencies, standard library only.
|
||||
Copy the file `chalk` to anywhere on your system path (or add it to your system path).
|
||||
You should now be able to run chalk with the following command:
|
||||
`chalk /path/to/file.txt`
|
||||
The above command will open a file if a valid one is found at the path, or it will create one.
|
||||
Copy the file `chalk` to anywhere on your system path and make sure it is executable. Then just run `chalk [path to file]`.
|
||||
|
||||
|
||||
### Commands
|
||||
## Commands
|
||||
|
||||
Commands are entered as the only text on their row. Enter the command and press enter.
|
||||
|
||||
. - Finish editing and, optionally, save. Then exit.
|
||||
| Command | Action |
|
||||
|:-------:|:------------------------------------------------------------------------------:|
|
||||
| !? | Print the command list |
|
||||
| !g | Print the GUIDE (ruler) |
|
||||
| !d | DISPLAY the whole file |
|
||||
| !v | VIEW a portion of the file |
|
||||
| !# | EDIT a line (eg. "!23" to edit line 23) |
|
||||
| !i | INSERT blank rows (will prompt for location and count) |
|
||||
| !x | CUT rows (will prompt for range and then add the cut data to the paste buffer) |
|
||||
| !c | COPY rows to the paste buffer (will prompt for range) |
|
||||
| !p | PASTE from the paste buffer (will prompt for location) |
|
||||
| !b | Print the contents of the paste BUFFER |
|
||||
| !s | SAVE any unsaved changes to the document |
|
||||
| !a | Save AS (will prompt for new path) |
|
||||
| . | Quit chalk (will prompt for save if there are unsaved changes) |
|
||||
|
||||
!d - Display all text in the document
|
||||
|
||||
!x - Delete line(s). If one number is entered, that line will be removed.
|
||||
If two numbers separated by a space are entered, a range inclusive
|
||||
of both numbers will be removed.
|
||||
|
||||
!i - Insert line(s) after the first line number entered. A second number
|
||||
separated from the first by a space can be included to as a count
|
||||
of how many lines to insert.
|
||||
|
||||
!# - Edit a line, where # is the line number. E.g. `> !23`
|
||||
|
||||
!? - View this list of available commands
|
||||
|
||||
### Notes
|
||||
|
||||
|
|
47
chalk
47
chalk
|
@ -34,19 +34,19 @@ filename = ''
|
|||
|
||||
class c:
|
||||
black = ''
|
||||
red = '\033[0;31m'
|
||||
b_red = '\033[1;31m'
|
||||
yellow = '\033[1;33m'
|
||||
green = '\033[0;32m'
|
||||
b_green = '\033[1;32m'
|
||||
cyan = '\033[0;36m'
|
||||
b_cyan = '\033[1;36m'
|
||||
purple = '\033[1;35m'
|
||||
blue = '\033[0;34m'
|
||||
b_blue = '\033[1;34m'
|
||||
white = '\033[1;37m'
|
||||
end = '\033[0m'
|
||||
bold = '\033[1m'
|
||||
red = '\001\033[0;31m\002'
|
||||
b_red = '\001\033[1;31m\002'
|
||||
yellow = '\001\033[1;33m\002'
|
||||
green = '\001\033[0;32m\002'
|
||||
b_green = '\001\033[1;32m\002'
|
||||
cyan = '\001\033[0;36m\002'
|
||||
b_cyan = '\001\033[1;36m\002'
|
||||
purple = '\001\033[1;35m\002'
|
||||
blue = '\001\033[0;34m\002'
|
||||
b_blue = '\001\033[1;34m\002'
|
||||
white = '\001\033[1;37m\002'
|
||||
end = '\001\033[0m\002'
|
||||
bold = '\001\033[1m\002'
|
||||
|
||||
|
||||
###########################################################
|
||||
|
@ -56,12 +56,17 @@ class c:
|
|||
### #################################
|
||||
### Utilities and helpers #################################
|
||||
|
||||
def pre_input_hook(txt):
|
||||
readline.insert_text(txt)
|
||||
readline.redisplay()
|
||||
|
||||
def input_editable(prompt, prefill=''):
|
||||
readline.set_startup_hook(lambda: readline.insert_text(prefill))
|
||||
readline.set_pre_input_hook(lambda: pre_input_hook(prefill))
|
||||
try:
|
||||
return input(prompt)
|
||||
edin = input(prompt)
|
||||
finally:
|
||||
readline.set_startup_hook()
|
||||
readline.set_pre_input_hook(None)
|
||||
return edin
|
||||
|
||||
|
||||
def validate_path(path):
|
||||
|
@ -245,10 +250,9 @@ def edit_line(ln):
|
|||
global file_changed
|
||||
try:
|
||||
row = int(ln[1:])
|
||||
text = content[row]
|
||||
newln = input_editable('{:6} {}>{} '.format(row, c.b_blue, c.end), content[row])
|
||||
if newln == '!c':
|
||||
print('{:8} Cancelled...'.format(' '))
|
||||
else:
|
||||
if newln != text:
|
||||
content[row] = newln
|
||||
file_changed = True
|
||||
except:
|
||||
|
@ -492,8 +496,9 @@ def view_paste_buffer():
|
|||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv
|
||||
if len(args) < 2:
|
||||
print('Incorrect number of arguments.')
|
||||
if len(args) != 2:
|
||||
print('Incorrect number of arguments:')
|
||||
print('chalk [file path]')
|
||||
sys.exit(1)
|
||||
filepath = args[1]
|
||||
|
||||
|
|
Loading…
Reference in New Issue