Add some doscstings, fix formatting
parent
bb8a27909e
commit
288f8fd35a
32
README.md
32
README.md
|
@ -21,7 +21,7 @@ A pure julia text editor
|
||||||
|
|
||||||
# Installing
|
# Installing
|
||||||
|
|
||||||
```
|
```julia
|
||||||
Pkg.clone("https://github.com/nick-paul/Acorn.jl.git")
|
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:
|
From within the REPL:
|
||||||
|
|
||||||
```
|
```
|
||||||
using Acorn
|
julia> using Acorn
|
||||||
julia> acorn("filename")
|
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(::Editor, ::String)
|
||||||
function sampleCommand(ed::Editor, args::String)
|
function sampleCommand(ed::Editor, args::String)
|
||||||
# Perform operation here
|
# 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
|
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
|
# Call `addCommand` to add
|
||||||
addCommand(:sample, # The command name
|
addCommand(:sample, # The command name
|
||||||
sampleCommand, # The command function
|
sampleCommand, # The command function
|
||||||
|
@ -101,4 +121,10 @@ include("cmds/sample.jl") # Add this line
|
||||||
|
|
||||||
## Features
|
## 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.
|
||||||
|
|
|
@ -20,25 +20,49 @@ end
|
||||||
##########
|
##########
|
||||||
# EDITOR #
|
# EDITOR #
|
||||||
##########
|
##########
|
||||||
|
"Editor instance"
|
||||||
mutable struct Editor
|
mutable struct Editor
|
||||||
|
"row view offset"
|
||||||
rowoff::Int
|
rowoff::Int
|
||||||
|
|
||||||
|
"column view offset"
|
||||||
coloff::Int
|
coloff::Int
|
||||||
|
|
||||||
|
"terminal width"
|
||||||
width::Int
|
width::Int
|
||||||
|
|
||||||
|
"terminal height"
|
||||||
height::Int
|
height::Int
|
||||||
|
|
||||||
|
"currently edited file"
|
||||||
filename::String
|
filename::String
|
||||||
|
|
||||||
|
"current status message"
|
||||||
statusmsg::String
|
statusmsg::String
|
||||||
|
|
||||||
|
"time reaining to display status"
|
||||||
status_time::Float64
|
status_time::Float64
|
||||||
|
|
||||||
|
"true if the buffer has been edited"
|
||||||
dirty::Bool
|
dirty::Bool
|
||||||
|
|
||||||
|
"if true, the key input loop will exit"
|
||||||
quit::Bool
|
quit::Bool
|
||||||
|
|
||||||
|
"the cursor position"
|
||||||
csr::Cursor
|
csr::Cursor
|
||||||
|
|
||||||
|
"the test buffer"
|
||||||
rows::Rows
|
rows::Rows
|
||||||
|
|
||||||
|
"terminal hosting this editor"
|
||||||
term::Base.Terminals.TTYTerminal
|
term::Base.Terminals.TTYTerminal
|
||||||
|
|
||||||
|
"used by commands to store variables"
|
||||||
params::Dict{Symbol, Dict{Symbol, Any}}
|
params::Dict{Symbol, Dict{Symbol, Any}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
"""create a new editor with default params"""
|
||||||
function Editor()
|
function Editor()
|
||||||
rowoff = 0
|
rowoff = 0
|
||||||
coloff = 0
|
coloff = 0
|
||||||
|
@ -111,6 +135,7 @@ function editorOpen(ed::Editor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
""" Save the buffer to the file using the current file name """
|
||||||
function editorSave(ed::Editor)
|
function editorSave(ed::Editor)
|
||||||
editorSave(ed, "")
|
editorSave(ed, "")
|
||||||
end
|
end
|
||||||
|
@ -118,7 +143,7 @@ end
|
||||||
""" Save the contents of the file buffer to disc """
|
""" Save the contents of the file buffer to disc """
|
||||||
function editorSave(ed::Editor, path::String)
|
function editorSave(ed::Editor, path::String)
|
||||||
prev_filename = ed.filename
|
prev_filename = ed.filename
|
||||||
|
|
||||||
try
|
try
|
||||||
if path == ""
|
if path == ""
|
||||||
if ed.filename == ""
|
if ed.filename == ""
|
||||||
|
|
27
src/row.jl
27
src/row.jl
|
@ -2,17 +2,18 @@
|
||||||
# ROW #
|
# ROW #
|
||||||
#############
|
#############
|
||||||
|
|
||||||
""" Holds file true data and render data """
|
"""Holds file true data and render data"""
|
||||||
mutable struct Row
|
mutable struct Row
|
||||||
# file data, a row of text
|
"file data, a row of text"
|
||||||
chars::String
|
chars::String
|
||||||
# a row of text as rendered on screen
|
|
||||||
|
"a row of text as rendered on screen"
|
||||||
render::String
|
render::String
|
||||||
end
|
end
|
||||||
|
|
||||||
Row(s::String) = Row(s, "")
|
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)
|
function update!(row::Row)
|
||||||
# Count the number of tabs
|
# Count the number of tabs
|
||||||
tabs = 0
|
tabs = 0
|
||||||
|
@ -74,7 +75,7 @@ function charX(row::Row, rx::Int)
|
||||||
end
|
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})
|
function insert(s::String, i::Int, c::Union{Char,String})
|
||||||
if s == ""
|
if s == ""
|
||||||
string(c)
|
string(c)
|
||||||
|
@ -83,19 +84,19 @@ function insert(s::String, i::Int, c::Union{Char,String})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
""" Delete char from string """
|
"""Delete char from string"""
|
||||||
function delete(s::String, i::Int)
|
function delete(s::String, i::Int)
|
||||||
i < 1 || i > length(s) && return s
|
i < 1 || i > length(s) && return s
|
||||||
string(s[1:i-1], s[i+1:end])
|
string(s[1:i-1], s[i+1:end])
|
||||||
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)
|
function insertChar!(row::Row, i::Int, c::Char)
|
||||||
row.chars = insert(row.chars, i, c)
|
row.chars = insert(row.chars, i, c)
|
||||||
update!(row)
|
update!(row)
|
||||||
end
|
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)
|
function insertTab!(row::Row, i::Int)
|
||||||
num_chars = 1
|
num_chars = 1
|
||||||
t = '\t'
|
t = '\t'
|
||||||
|
@ -114,7 +115,7 @@ function insertTab!(row::Row, i::Int)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
""" Delete char from row """
|
"""Delete char from row"""
|
||||||
function deleteChar!(row::Row, i::Int)
|
function deleteChar!(row::Row, i::Int)
|
||||||
row.chars = delete(row.chars, i)
|
row.chars = delete(row.chars, i)
|
||||||
update!(row)
|
update!(row)
|
||||||
|
@ -135,10 +136,10 @@ end
|
||||||
# ROWS #
|
# ROWS #
|
||||||
########
|
########
|
||||||
|
|
||||||
""" type alias for Array{Row, 1} """
|
"""type alias for Array{Row, 1}"""
|
||||||
Rows = Array{Row, 1}
|
Rows = Array{Row, 1}
|
||||||
|
|
||||||
""" delete all rows from a Rows """
|
"""delete all rows from a Rows"""
|
||||||
function clearRows(rows::Rows)
|
function clearRows(rows::Rows)
|
||||||
while length(rows) > 0
|
while length(rows) > 0
|
||||||
pop!(rows)
|
pop!(rows)
|
||||||
|
@ -146,7 +147,7 @@ function clearRows(rows::Rows)
|
||||||
end
|
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)
|
function appendRow(rows::Rows, s::String)
|
||||||
row = Row(s)
|
row = Row(s)
|
||||||
update!(row)
|
update!(row)
|
||||||
|
@ -154,7 +155,7 @@ function appendRow(rows::Rows, s::String)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
""" Convert all ROW data to a single string """
|
"""Convert all ROW data to a single string"""
|
||||||
function rowsToString(rows::Rows)
|
function rowsToString(rows::Rows)
|
||||||
join(map(row -> row.chars, rows), '\n')
|
join(map(row -> row.chars, rows), '\n')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue