Skip to content

Commit

Permalink
added more status and display commands to the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Mar 23, 2019
1 parent cec3ee8 commit 6614f6b
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "VerTeX"
uuid = "19dc0ece-cb56-5e38-8a38-9a14b2d7df9c"
uuid = "cc48e778-429c-5593-b60f-2bcf41d5649c"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# VerTeX.jl

*Typeset scattered graph data rewriter based on tagged VerTeX nodes*
*Typeset scattered graph data rewriter based on LaTeX nodes*

[![Build Status](https://travis-ci.org/chakravala/VerTeX.jl.svg?branch=master)](https://travis-ci.org/chakravala/VerTeX.jl)
[![Build status](https://ci.appveyor.com/api/projects/status/8poc90nqimq5903s/branch/master?svg=true)](https://ci.appveyor.com/project/chakravala/vertex-jl/branch/master)
Expand Down
38 changes: 31 additions & 7 deletions src/args.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# This file is part of VerTeX.jl. It is licensed under the MIT license
# Copyright (C) 2019 Michael Reed

import ..load, ..save, ..checkmerge, ..writetex, ..tex2dict, ..save, ..article
import ..load, ..save, ..checkmerge, ..readtex, ..writetex, ..tex2dict, ..save, ..article, ..manifest, ..readmanifest, ..getdepot, ..readdictionary, ..dictionary

export zathura, latexmk, pdf, texedit

zathura(f::String,o=stdout) = run(`zathura $f`,(devnull,o,stderr),wait=false)
latexmk(f::String,o=stdout) = run(`latexmk -silent -pdf -cd $f`)

function showpdf(str::String)
function showpdf(str::String,o=stdout)
try
latexmk(str,devnull)
latexmk(str,o)
catch
end
zathura(replace(str,r".tex$"=>".pdf"))
zathura(replace(str,r".tex$"=>".pdf"),o)
end

function pdf(str::String,file::String="doc")
Expand All @@ -24,7 +24,7 @@ function pdf(str::String,file::String="doc")
showpdf("/tmp/$file.tex")
end

pdf(data::Dict) = showpdf(VerTeX.writetex(data))
pdf(data::Dict,o=stdout) = showpdf(writetex(data),o)

function texedit(data::Dict,file::String="/tmp/doc.tex")
haskey(data,"dir") && (file == "/tmp/doc.tex") && (file = data["dir"])
Expand All @@ -33,7 +33,7 @@ function texedit(data::Dict,file::String="/tmp/doc.tex")
if (old nothing)
cmv = checkmerge(data["revised"],old,data["title"],data["author"],data["date"],data["tex"],"Memory buffer out of sync with vertex, proceed?")
if cmv == 0
throw(error("VerTeX unable to proceed due to merge failure"))
vtxerror("VerTeX unable to proceed due to merge failure")
elseif cmv < 2
@warn "merged into buffer from $path"
data = old
Expand All @@ -46,7 +46,7 @@ function texedit(data::Dict,file::String="/tmp/doc.tex")
load = writetex(data,file)
run(`vim --servername julia $load`)
try
ret = tex2dict(VerTeX.readtex(load),data)
ret = tex2dict(readtex(load),data)
return load == file ? ret : save(ret,file)
catch
return save(data,file)
Expand All @@ -65,3 +65,27 @@ function texedit(file::String="/tmp/doc.tex")
end
return texedit(v,file)
end

function display_manifest(repo)
readmanifest()
for x manifest["julia"]
data = x[2]
@info "$(data["dir"])"
end
end

function display_manifest()
readmanifest()
g = getdepot()
for key keys(g)
@info "$key$(g[key])"
end
end

function display_dictionary()
readdictionary()
for key keys(dictionary)
x = dictionary[key]
@info "$key => $(join(["$(x[k][3])$(x[k][2])" for k keys(x)],", "))"
end
end
59 changes: 58 additions & 1 deletion src/cmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,67 @@ command_declarations = [
:description => "edit with vim",
:help => md"""
vi [-p|--project] pkg[=uuid] ...
vi path
edit with vim
"""
],[ :kind => CMD_HELP,
:name => "help",
:short_name => "?",
:arg_count => 0 => Inf,
:arg_parser => identity,
:completions => complete_help,
:description => "show this message",
:help => md"""
help
List available commands along with short descriptions.
help cmd
If `cmd` is a partial command, display help for all subcommands.
If `cmd` is a full command, display help for `cmd`.
""",
],[ :kind => CMD_PDF,
:name => "pdf",
:short_name => "p",
:handler => do_pdf!,
:arg_count => 1 => 2,
:arg_parser => identity,
:description => "display as pdf",
:help => md"""
pdf path [repo] ...
display as pdf
"""
],[ :kind => CMD_STATUS,
:name => "status",
:short_name => "st",
:handler => do_status!,
:arg_count => 0 => 1,
:arg_parser => identity,
:description => "display manifest",
:help => md"""
st [repo]
display manifest
"""
],[ :kind => CMD_DICT,
:name => "dictionary",
:short_name => "dict",
:handler => do_dict!,
:arg_count => 0 => 0,
:arg_parser => identity,
:description => "display dictionary",
:help => md"""
dict
display dictionary
"""
],
], #package
] #command_declarations
8 changes: 8 additions & 0 deletions src/completions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function complete_remote_package(s, i1, i2)
return cmp, i1:i2, !isempty(cmp)
end=#

function complete_help(options, partial)
names = String[]
for cmds in values(super_specs)
append!(names, [spec.canonical_name for spec in values(cmds)])
end
return sort!(unique!(append!(names, collect(keys(super_specs)))))
end

function complete_argument(to_complete, i1, i2, lastcommand, project_opt
)::Tuple{Vector{String},UnitRange{Int},Bool}
if lastcommand == CMD_HELP
Expand Down
24 changes: 15 additions & 9 deletions src/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import REPL: LineEdit, REPLCompletions
import Pkg: Types.casesensitive_isdir
using Pkg.Types, Pkg.Display, Pkg.Operations

vtxerror(msg::String...) = throw(PkgError(join(msg)))

#########################
# Specification Structs #
#########################
Expand All @@ -26,7 +28,7 @@ const OptionDeclaration = Vector{Pair{Symbol,Any}}
#----------#
# Commands #
#----------#
@enum(CommandKind, CMD_VIM)
@enum(CommandKind, CMD_HELP, CMD_VIM, CMD_PDF, CMD_STATUS, CMD_DICT)
#=@enum(CommandKind, CMD_HELP, CMD_RM, CMD_ADD, CMD_DEVELOP, CMD_UP,
CMD_STATUS, CMD_TEST, CMD_GC, CMD_BUILD, CMD_PIN,
CMD_FREE, CMD_GENERATE, CMD_RESOLVE, CMD_PRECOMPILE,
Expand Down Expand Up @@ -61,7 +63,7 @@ function do_cmd!(command::Command, repl)
context = Dict{Symbol,Any}(:preview => command.preview)

# REPL specific commands
#command.spec.kind == CMD_HELP && return Base.invokelatest(do_help!, command, repl)
command.spec.kind == CMD_HELP && return Base.invokelatest(do_help!, command, repl)

# API commands
# TODO is invokelatest still needed?
Expand All @@ -80,11 +82,7 @@ function parse_command(words::Vector{QString})
return statement.spec === nothing ? statement.super : statement.spec
end

function do_vim!(a,b)
texedit(a[1].raw)
end

#=function do_help!(command::Command, repl::REPL.AbstractREPL)
function do_help!(command::Command, repl::REPL.AbstractREPL)
disp = REPL.REPLDisplay(repl)
if isempty(command.arguments)
Base.display(disp, help)
Expand All @@ -106,7 +104,15 @@ end
end
!isempty(command.arguments) && @warn "More than one command specified, only rendering help for first"
Base.display(disp, help_md)
end=#
end

do_vim!(a,b) = texedit(a[1].raw)

do_pdf!(a,b) = pdf(load([x.raw for x a]...))

do_status!(a,b) = display_manifest([x.raw for x a]...)

do_dict!(a,b) = display_dictionary()

######################
# REPL mode creation #
Expand Down Expand Up @@ -285,6 +291,6 @@ Multiple commands can be given on the same line by interleaving a `;` between th
return help
end

#const help = gen_help()
const help = gen_help()

end #module

0 comments on commit 6614f6b

Please sign in to comment.