Skip to content

Commit 42144a1

Browse files
committed
added more status and display commands to the parser
1 parent cec3ee8 commit 42144a1

File tree

7 files changed

+114
-23
lines changed

7 files changed

+114
-23
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "VerTeX"
2-
uuid = "19dc0ece-cb56-5e38-8a38-9a14b2d7df9c"
2+
uuid = "cc48e778-429c-5593-b60f-2bcf41d5649c"
33

44
[deps]
55
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# VerTeX.jl
22

3-
*Typeset scattered graph data rewriter based on tagged VerTeX nodes*
3+
*Typeset scattered graph data rewriter based on LaTeX nodes*
44

55
[![Build Status](https://travis-ci.org/chakravala/VerTeX.jl.svg?branch=master)](https://travis-ci.org/chakravala/VerTeX.jl)
66
[![Build status](https://ci.appveyor.com/api/projects/status/8poc90nqimq5903s/branch/master?svg=true)](https://ci.appveyor.com/project/chakravala/vertex-jl/branch/master)

REQUIRE

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
julia 0.7
2-
Pkg
3-
UUIDs
4-
Dates
5-
Markdown
62
TerminalMenus

src/args.jl

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
# This file is part of VerTeX.jl. It is licensed under the MIT license
33
# Copyright (C) 2019 Michael Reed
44

5-
import ..load, ..save, ..checkmerge, ..writetex, ..tex2dict, ..save, ..article
5+
import ..load, ..save, ..checkmerge, ..readtex, ..writetex, ..tex2dict, ..save, ..article, ..manifest, ..readmanifest, ..getdepot, ..readdictionary, ..dictionary
66

77
export zathura, latexmk, pdf, texedit
88

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

12-
function showpdf(str::String)
12+
function showpdf(str::String,o=stdout)
1313
try
14-
latexmk(str,devnull)
14+
latexmk(str,o)
1515
catch
1616
end
17-
zathura(replace(str,r".tex$"=>".pdf"))
17+
zathura(replace(str,r".tex$"=>".pdf"),o)
1818
end
1919

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

27-
pdf(data::Dict) = showpdf(VerTeX.writetex(data))
27+
pdf(data::Dict,o=stdout) = showpdf(writetex(data),o)
2828

2929
function texedit(data::Dict,file::String="/tmp/doc.tex")
3030
haskey(data,"dir") && (file == "/tmp/doc.tex") && (file = data["dir"])
@@ -33,7 +33,7 @@ function texedit(data::Dict,file::String="/tmp/doc.tex")
3333
if (old nothing)
3434
cmv = checkmerge(data["revised"],old,data["title"],data["author"],data["date"],data["tex"],"Memory buffer out of sync with vertex, proceed?")
3535
if cmv == 0
36-
throw(error("VerTeX unable to proceed due to merge failure"))
36+
vtxerror("VerTeX unable to proceed due to merge failure")
3737
elseif cmv < 2
3838
@warn "merged into buffer from $path"
3939
data = old
@@ -46,7 +46,7 @@ function texedit(data::Dict,file::String="/tmp/doc.tex")
4646
load = writetex(data,file)
4747
run(`vim --servername julia $load`)
4848
try
49-
ret = tex2dict(VerTeX.readtex(load),data)
49+
ret = tex2dict(readtex(load),data)
5050
return load == file ? ret : save(ret,file)
5151
catch
5252
return save(data,file)
@@ -65,3 +65,27 @@ function texedit(file::String="/tmp/doc.tex")
6565
end
6666
return texedit(v,file)
6767
end
68+
69+
function display_manifest(repo)
70+
readmanifest()
71+
for x manifest["julia"]
72+
data = x[2]
73+
@info "$(data["dir"])"
74+
end
75+
end
76+
77+
function display_manifest()
78+
readmanifest()
79+
g = getdepot()
80+
for key keys(g)
81+
@info "$key$(g[key])"
82+
end
83+
end
84+
85+
function display_dictionary()
86+
readdictionary()
87+
for key keys(dictionary)
88+
x = dictionary[key]
89+
@info "$key => $(join(["$(x[k][3])$(x[k][2])" for k keys(x)],", "))"
90+
end
91+
end

src/cmd.jl

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,67 @@ command_declarations = [
1313
:description => "edit with vim",
1414
:help => md"""
1515
16-
vi [-p|--project] pkg[=uuid] ...
16+
vi path
1717
1818
edit with vim
1919
"""
20+
],[ :kind => CMD_HELP,
21+
:name => "help",
22+
:short_name => "?",
23+
:arg_count => 0 => Inf,
24+
:arg_parser => identity,
25+
:completions => complete_help,
26+
:description => "show this message",
27+
:help => md"""
28+
29+
help
30+
31+
List available commands along with short descriptions.
32+
33+
help cmd
34+
35+
If `cmd` is a partial command, display help for all subcommands.
36+
If `cmd` is a full command, display help for `cmd`.
37+
""",
38+
],[ :kind => CMD_PDF,
39+
:name => "pdf",
40+
:short_name => "p",
41+
:handler => do_pdf!,
42+
:arg_count => 1 => 2,
43+
:arg_parser => identity,
44+
:description => "display as pdf",
45+
:help => md"""
46+
47+
pdf path [repo] ...
48+
49+
display as pdf
50+
"""
51+
],[ :kind => CMD_STATUS,
52+
:name => "status",
53+
:short_name => "st",
54+
:handler => do_status!,
55+
:arg_count => 0 => 1,
56+
:arg_parser => identity,
57+
:description => "display manifest",
58+
:help => md"""
59+
60+
st [repo]
61+
62+
display manifest
63+
"""
64+
],[ :kind => CMD_DICT,
65+
:name => "dictionary",
66+
:short_name => "dict",
67+
:handler => do_dict!,
68+
:arg_count => 0 => 0,
69+
:arg_parser => identity,
70+
:description => "display dictionary",
71+
:help => md"""
72+
73+
dict
74+
75+
display dictionary
76+
"""
2077
],
2178
], #package
2279
] #command_declarations

src/completions.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ function complete_remote_package(s, i1, i2)
3838
return cmp, i1:i2, !isempty(cmp)
3939
end=#
4040

41+
function complete_help(options, partial)
42+
names = String[]
43+
for cmds in values(super_specs)
44+
append!(names, [spec.canonical_name for spec in values(cmds)])
45+
end
46+
return sort!(unique!(append!(names, collect(keys(super_specs)))))
47+
end
48+
4149
function complete_argument(to_complete, i1, i2, lastcommand, project_opt
4250
)::Tuple{Vector{String},UnitRange{Int},Bool}
4351
if lastcommand == CMD_HELP

src/repl.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import REPL: LineEdit, REPLCompletions
1212
import Pkg: Types.casesensitive_isdir
1313
using Pkg.Types, Pkg.Display, Pkg.Operations
1414

15+
vtxerror(msg::String...) = throw(PkgError(join(msg)))
16+
1517
#########################
1618
# Specification Structs #
1719
#########################
@@ -26,7 +28,7 @@ const OptionDeclaration = Vector{Pair{Symbol,Any}}
2628
#----------#
2729
# Commands #
2830
#----------#
29-
@enum(CommandKind, CMD_VIM)
31+
@enum(CommandKind, CMD_HELP, CMD_VIM, CMD_PDF, CMD_STATUS, CMD_DICT)
3032
#=@enum(CommandKind, CMD_HELP, CMD_RM, CMD_ADD, CMD_DEVELOP, CMD_UP,
3133
CMD_STATUS, CMD_TEST, CMD_GC, CMD_BUILD, CMD_PIN,
3234
CMD_FREE, CMD_GENERATE, CMD_RESOLVE, CMD_PRECOMPILE,
@@ -61,7 +63,7 @@ function do_cmd!(command::Command, repl)
6163
context = Dict{Symbol,Any}(:preview => command.preview)
6264

6365
# REPL specific commands
64-
#command.spec.kind == CMD_HELP && return Base.invokelatest(do_help!, command, repl)
66+
command.spec.kind == CMD_HELP && return Base.invokelatest(do_help!, command, repl)
6567

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

83-
function do_vim!(a,b)
84-
texedit(a[1].raw)
85-
end
86-
87-
#=function do_help!(command::Command, repl::REPL.AbstractREPL)
85+
function do_help!(command::Command, repl::REPL.AbstractREPL)
8886
disp = REPL.REPLDisplay(repl)
8987
if isempty(command.arguments)
9088
Base.display(disp, help)
@@ -106,7 +104,15 @@ end
106104
end
107105
!isempty(command.arguments) && @warn "More than one command specified, only rendering help for first"
108106
Base.display(disp, help_md)
109-
end=#
107+
end
108+
109+
do_vim!(a,b) = texedit(a[1].raw)
110+
111+
do_pdf!(a,b) = pdf(load([x.raw for x a]...))
112+
113+
do_status!(a,b) = display_manifest([x.raw for x a]...)
114+
115+
do_dict!(a,b) = display_dictionary()
110116

111117
######################
112118
# REPL mode creation #
@@ -285,6 +291,6 @@ Multiple commands can be given on the same line by interleaving a `;` between th
285291
return help
286292
end
287293

288-
#const help = gen_help()
294+
const help = gen_help()
289295

290296
end #module

0 commit comments

Comments
 (0)