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

View File

@ -4,9 +4,10 @@
"""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
@ -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)