Add some doscstings, fix formatting

master
Nick Paul 2017-08-07 18:29:20 -04:00
parent bb8a27909e
commit 288f8fd35a
3 changed files with 70 additions and 18 deletions

View File

@ -21,7 +21,7 @@ A pure julia text editor
# Installing
```
```julia
Pkg.clone("https://github.com/nick-paul/Acorn.jl.git")
```
@ -30,7 +30,7 @@ Pkg.clone("https://github.com/nick-paul/Acorn.jl.git")
From within the REPL:
```
using Acorn
julia> using Acorn
julia> acorn("filename")
```
@ -78,8 +78,28 @@ Commands are easy to create and allow for greater editor usability. To create yo
# function(::Editor, ::String)
function sampleCommand(ed::Editor, args::String)
# Perform operation here
# If you need to store state variables use ed.params
# ed.params[:YOUR CMD NAME][VAR NAME]
ed.params[:sample][:var_name] = some_val
# If you need to request input from the user:
editorPrompt(ed, "Enter your name: ",
callback=sampleCallback # Callback fucntion: function(ed::Editor, buf::String, key::Char
buf="", # Starting point for the input buffer. This text is
# 'automatically' typed into the input when the
# prompt loads
showcursor=true) # Move the cursor to the prompt
end
# Optional: If you request input from the user and need a
# callback function, use the following format:
function sampleCallback(ed::Editor, buf::String, key::Char)
# Perform callback action here...
end
# Call `addCommand` to add
addCommand(:sample, # The command name
sampleCommand, # The command function
@ -101,4 +121,10 @@ include("cmds/sample.jl") # Add this line
## Features
Text selection, copy/paste, syntax highlighting, etc..
Text selection, copy/paste, syntax highlighting, etc. have not yet been implemented. I will try to keep up with issues and pull requests regarding features so feel free to add whatever you like to the editor.
## Bug Fixes / Compatability
Acorn has not been tested on OSX and currently has compatability issues with Windows. If you run into any problems on your platform feel free to patch it and send a pull request.
If you experience any bugs, please submit an issue or patch it and send a pull request.

View File

@ -20,25 +20,49 @@ end
##########
# EDITOR #
##########
"Editor instance"
mutable struct Editor
"row view offset"
rowoff::Int
"column view offset"
coloff::Int
"terminal width"
width::Int
"terminal height"
height::Int
"currently edited file"
filename::String
"current status message"
statusmsg::String
"time reaining to display status"
status_time::Float64
"true if the buffer has been edited"
dirty::Bool
"if true, the key input loop will exit"
quit::Bool
"the cursor position"
csr::Cursor
"the test buffer"
rows::Rows
"terminal hosting this editor"
term::Base.Terminals.TTYTerminal
"used by commands to store variables"
params::Dict{Symbol, Dict{Symbol, Any}}
end
"""create a new editor with default params"""
function Editor()
rowoff = 0
coloff = 0
@ -111,6 +135,7 @@ function editorOpen(ed::Editor)
end
end
""" Save the buffer to the file using the current file name """
function editorSave(ed::Editor)
editorSave(ed, "")
end
@ -118,7 +143,7 @@ end
""" Save the contents of the file buffer to disc """
function editorSave(ed::Editor, path::String)
prev_filename = ed.filename
try
if path == ""
if ed.filename == ""

View File

@ -2,17 +2,18 @@
# ROW #
#############
""" Holds file true data and render data """
"""Holds file true data and render data"""
mutable struct Row
# file data, a row of text
"file data, a row of text"
chars::String
# a row of text as rendered on screen
"a row of text as rendered on screen"
render::String
end
Row(s::String) = Row(s, "")
""" Update the `render` string using the `chars` string """
"""Update the `render` string using the `chars` string"""
function update!(row::Row)
# Count the number of tabs
tabs = 0
@ -74,7 +75,7 @@ function charX(row::Row, rx::Int)
end
""" Insert a char into a string """
"""Insert a char or string into a string"""
function insert(s::String, i::Int, c::Union{Char,String})
if s == ""
string(c)
@ -83,19 +84,19 @@ function insert(s::String, i::Int, c::Union{Char,String})
end
end
""" Delete char from string """
"""Delete char from string"""
function delete(s::String, i::Int)
i < 1 || i > length(s) && return s
string(s[1:i-1], s[i+1:end])
end
""" Insert a char into the row at a given location """
"""Insert a char into the row at a given location"""
function insertChar!(row::Row, i::Int, c::Char)
row.chars = insert(row.chars, i, c)
update!(row)
end
""" Insert a tab into the row at a given location. Return the number of chars inserted """
"""Insert a tab into the row at a given location. Return the number of chars inserted"""
function insertTab!(row::Row, i::Int)
num_chars = 1
t = '\t'
@ -114,7 +115,7 @@ function insertTab!(row::Row, i::Int)
end
""" Delete char from row """
"""Delete char from row"""
function deleteChar!(row::Row, i::Int)
row.chars = delete(row.chars, i)
update!(row)
@ -135,10 +136,10 @@ end
# ROWS #
########
""" type alias for Array{Row, 1} """
"""type alias for Array{Row, 1}"""
Rows = Array{Row, 1}
""" delete all rows from a Rows """
"""delete all rows from a Rows"""
function clearRows(rows::Rows)
while length(rows) > 0
pop!(rows)
@ -146,7 +147,7 @@ function clearRows(rows::Rows)
end
""" Add a row to the end of the document """
"""Add a row to the end of the document"""
function appendRow(rows::Rows, s::String)
row = Row(s)
update!(row)
@ -154,7 +155,7 @@ function appendRow(rows::Rows, s::String)
end
""" Convert all ROW data to a single string """
"""Convert all ROW data to a single string"""
function rowsToString(rows::Rows)
join(map(row -> row.chars, rows), '\n')
end