Skip to content

Commit

Permalink
Pulling Abstract Trees into 2.0 (#198)
Browse files Browse the repository at this point in the history
* CompatHelper: add new compat entry for WordTokenizers at version 0.5, (keep existing compat) (#171)

Co-authored-by: CompatHelper Julia <[email protected]>

* Stack traces (#179)

* styling

* now excludes other installed packages + fmt and tests

* small improvements ot hidden frames

* format and docs

* small fixes

* fmt

* kwarg func call fmt

* show each error line code

* covergage

* stacktrace formatting

* traces rendering improvements

* test fix

* new text reshaping function from chatgpt

* fixed tests

* cleanup

* cleanup

* bump

* bump

* bump

* prompt init

* small fixes to repr and error

* fixed small repr bugs

* removed deps

* wip errors

* method error kwargs call

* parsed kwargs calls in stackrace

* fixes

* method error edge cases

* bump

* bump

* bump

* fixed textlen bug for orphaned tags

* Update Project.toml

* Update Project.toml

* errors with no backtrace are now shown

* logger doesn't cut msgs

* CI fix

* error msg panel now always shows

* reworked logs rendering code

* msg reshaping

* refactored stacktrace code + further logs improvements

* fixed bug with markdown rendering

* Link renderable development (#180)

* bump

* bump

* working on making Link work

* functional link?

* fixing them errors

* fixed behavior of hidden frames in stacktrace and docs

* fixed bugs

* bugs fixed and more test

* bugfix

* tests fix

* tests fixing

* tests fix

* tests fix

* Fix #181 (#182)

* small fixes

* bump

* `Prompt` (#175)

* prompt init

* small fixes to repr and error

* fixed small repr bugs

* removed deps

* wip errors

* bump

* bump

* bump

* bump

* prompt wip

* bump

* prompt almost finished

* added tests and docs for prompt

* bump

* coverage and CI

* docs fix

* Update _error_messages.jl

* Annotations (#185)

* init

* more extensive precompilation

* small fixes for error IO

* 204 method invalidation at startup ops

* bump

* working on annotation

* added style

* bump

* disabled precompilation

* new code reshaping function

* new annotation system

* tests for annotations passing

* fmt

* more tests

* bump

* bump

* ci fix

* bump

Co-authored-by: Federico Claudi <[email protected]>

* Create Invalidations.yml

* Create unused_dependencies.yml

* Update Invalidations.yml

* Update Invalidations.yml

* Update CI.yml

* Update CI.yml

* Coverage - adding more tests (#186)

* increasing test coverage

* fixed bug with markup tags including newline

* test coverage

* bump

* bump

* bump

* bump

* bump

* CI fix

* CI fix

* CI fix

* CI fix

* bump

* Update CI.yml

* bump

* refactored tree

* CI fix

* docs

* Update unused_dependencies.yml

* ci fix

* Update Invalidations.yml

* removed fillin(segments)

* Update CI.yml

* fmt

* bump

* removed error message functionality, using base

* bump

* fix_markup_across_lines (#188)

* fix_markup_across_lines

* tests passing

* fixed small things

* bump

* wip for fix_ansi_across_lines

* fixed nested style tags

* reshaping with ANSI and markup works well

* fmt

* bump

* bump

* bump

* removed unused funcs

* docstring

* small fixes

* bump

* Update CI.yml

* Working on pre-compilation (#173)

* init

* more extensive precompilation

* small fixes for error IO

* 204 method invalidation at startup ops

* bump

* cleaned up precompilation

* removed deps

* bump

Co-authored-by: Federico Claudi <[email protected]>

* CompatHelper: add new compat entry for AbstractTrees at version 0.4, (keep existing compat) (#189)

Co-authored-by: CompatHelper Julia <[email protected]>

* bump

* no stdout in precomp (#191)

* no stdout in precomp

* ignore precompilation code in coverage

* finished re-factoring tree

* CI fix

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: CompatHelper Julia <[email protected]>
Co-authored-by: Rémi Vezy <[email protected]>
Co-authored-by: Federico Claudi <[email protected]>
  • Loading branch information
5 people authored Feb 4, 2023
1 parent 7593c16 commit d3e94a1
Show file tree
Hide file tree
Showing 678 changed files with 7,550 additions and 2,560 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
name: CI
on:
push:
branches:
- 'master'
tags: '*'
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
test:
Expand All @@ -21,7 +16,7 @@ jobs:
version:
- '1.6'
- '1' # latest 1.X
# - 'nightly'
- 'nightly'
os:
- ubuntu-latest
- windows-latest
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Invalidations

on:
pull_request:
types:
- ready_for_review

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: always.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
evaluate:
# Only run on PRs to the default branch.
# In the PR trigger above branches can be specified only explicitly whereas this check should work for master, main, or any other default branch
if: github.base_ref == github.event.repository.default_branch
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- uses: actions/checkout@v3
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_pr


- uses: actions/checkout@v3
with:
ref: ${{ github.event.repository.default_branch }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_default


- name: Report invalidation counts
run: |
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
- name: Check if the PR does increase number of invalidations
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
run: exit 1
18 changes: 18 additions & 0 deletions .github/workflows/unused_dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check for unused dependencies

on:
pull_request:
types:
- ready_for_review


jobs:
treeshake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: 1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-treeshake@main
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "Term"
uuid = "22787eb5-b846-44ae-b979-8e399b8463ab"
authors = ["FedeClaudi <[email protected]> and contributors"]
version = "1.1.1"
version = "1.2.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Highlights = "eafb193a-b7ab-5a9e-9068-77385905fa72"
Expand All @@ -19,9 +20,9 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
WordTokenizers = "796a5d58-b03d-544a-977e-18100b691f6e"

[compat]
AbstractTrees = "0.4"
CodeTracking = "1"
Highlights = "0.5"
MyterialColors = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions README.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Term
import Term.Renderables: Renderable
import Term: rint
import Term: typestree, inspect
import Term: inspect
using Term.Layout
import Term.Measures: height

Expand Down Expand Up @@ -172,7 +172,7 @@ lorem1 = TextBox(_lorem; width = 62, fit = false, padding = (0, 0, 0, 0))
lorem2 = TextBox(_lorem; width = 42, fit = false, padding = (0, 0, 0, 0))

expr = :(2x + 2π / θ)
tree = Renderable(sprint(typestree, Float64))
tree = Renderable(sprint(Tree, Float64))
dendo = Renderable(sprint(inspect, expr))
renderables_info = TextBox(
"""{bold bright_blue}Renderables types{/bold bright_blue}
Expand Down
1 change: 1 addition & 0 deletions codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
ignore:
- "./src/errors.jl"
- "./src/_errors.jl"
- "./src/__precompilation.jl"
- "./test"
- "./scripts"
4 changes: 3 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ makedocs(;
"basics/renderables.md",
"basics/tprint.md",
"basics/console.md",
"basics/prompt.md",
"basics/markdown.md",
],
"Renderables" => Any[
"ren/intro.md",
"ren/text.md",
"ren/panel.md",
"ren/table.md",
"ren/layout_rens.md",
"ren/annotation.md",
"ren/dendogram.md",
"ren/tree.md",
],
Expand All @@ -48,7 +51,6 @@ makedocs(;
"adv/logging.md",
"adv/errors_tracebacks.md",
"adv/introspection.md",
"adv/markdown.md",
],
"API" => Any[
"api/api_term.md",
Expand Down
22 changes: 18 additions & 4 deletions docs/src/adv/errors_tracebacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,26 @@ test()
![](stacktrace.png)


!!! warning "Term is opinionated"
In altering Julia's default stacktraces handling, a few choices where made such as: inveriting the order in which the backtrace's stack frames are shown and hiding frames from `Base` or other packages installed through `Pkg` (similarly to [AbbreviatedStackTraces.jl](https://github.com/BioTurboNick/AbbreviatedStackTraces.jl)).
When installing `Term`'s stacktrace system with `install_term_stacktrace`, you can use the keyword arguments to alter this behavior
### Term is opinionated

In altering Julia's default stacktraces handling, a few choices where made such as: inveriting the order in which the backtrace's stack frames are shown and hiding frames from `Base` or other packages installed through `Pkg` (similarly to [AbbreviatedStackTraces.jl](https://github.com/BioTurboNick/AbbreviatedStackTraces.jl)).
When installing `Term`'s stacktrace system with `install_term_stacktrace`, you can use the keyword arguments to alter this behavior

```@example
using Term # hide
install_term_repr() # hide
install_term_stacktrace
install_term_stacktrace(;
reverse_backtrace = true, # change me!
max_n_frames = 30,
hide_frames = false,
)
```

but you can also do more, if you just want to quickly change some options (e.g. to deal with a particularly though bug). You can set flags to change the behavior on the fly:

```@example
import Term: STACKTRACE_HIDDEN_MODULES, STACKTRACE_HIDE_FRAMES
STACKTRACE_HIDDEN_MODULES[] = ["REPL", "OhMyREPL"] # list names of modules you want ignored in the stacktrace
STACKTRACE_HIDE_FRAMES[] = false # set to true to hide frame, false to show all of them
```
2 changes: 1 addition & 1 deletion docs/src/adv/introspection.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can now use `inspect(T::DataType)` to get all information you possibly need


```@meta
CurrentModule = Introspection
CurrentModule = Term.Introspection
```

```@docs
Expand Down
13 changes: 13 additions & 0 deletions docs/src/api/api_annotations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Annotations
```@meta
CurrentModule = Term.Annotations
```


```@index
Pages = ["api_annotations.md"]
```

```@autodocs
Modules = [Annotations]
```
14 changes: 14 additions & 0 deletions docs/src/api/api_prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Prompts
```@meta
CurrentModule = Term.Prompts
```


```@index
Pages = ["api_prompt.md"]
```


```@autodocs
Modules = [Prompts]
```
2 changes: 1 addition & 1 deletion docs/src/basics/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tprintln("This is a very long text"^10)
it also works for any `Renderable` made with Term:

```@example
using Term: tprintln # hide
using Term: tprintln, Panel # hide
using Term.Consoles: Console, enable, disable #hide
print(Panel())
Expand Down
3 changes: 2 additions & 1 deletion docs/src/adv/markdown.md → docs/src/basics/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Let's have a look.

```@example md
import Term.Consoles: Console, enable, disable # hide
con = Console(60) |> enable #hide
con = Console(60) # hide
enable(con) #hide
import Term: tprintln
using Term.TermMarkdown
using Markdown
Expand Down
66 changes: 66 additions & 0 deletions docs/src/basics/prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Prompt

Time for a little example of a simple thing you can use `Term.jl` for: asking for some input. Use a `Prompt`, ask a question, get an answer. Simple, but a little extra style. That's what `AbstractPrompt` types are for. There's a few different flavors, which we'll look at in due time, but essentially a prompt is made of a bit of text, the `prompt` that is displayed to the user, and some machinery to capture the user's input and parse it/ validate it.

For example:

```@example prompt
using Term.Prompts
prompt = Prompt("Simple, right?");
```

creates a `Prompt` object and `ask` then prints the propmt and asks for input:
```julia
prompt |> ask
```
the output should look something like
```@example prompt
print(prompt) # hide
```

here we construct a basic `Prompt` and "ask" it: print the message and capture the reply. `ask` returns the answer, which you can do with as you please. A small warning before we carry on:

!!! warning "Using VSCode"
As you can see [here](https://discourse.julialang.org/t/vscode-errors-with-user-input-readline/75097/4?u=fedeclaudi), `readlines`, which `AbstractPrompts` use to get the user's input, is a bit troublesome in VSCode. In VSCode, after the prompt gets printed you need to enter "space" (hit the space bar) and then enter and **after** that you can enter your actual replies.

## Prompt flavours
There's a couple more ways you can use prompts like. One is to ensure you get an answer of the correct `Type`, using the immaginatively names `TypePrompt`:

```@example prompt
# this only accepts `Int`s
prompt = TypePrompt(Int, "give me a number") # don't forget to |> ask
print(prompt) # hide
```


If your answer can't be converted to the correct type you'll get a `AnswerValidationError`, not good.


So, what if you want to get user inputs, but you don't want to handle any crazy input they can provide? Fear not, use `OptionsPrompt` so that only acceptable options will be ok. This will keep "asking" your prompt until the user's answer matches one of the given options

```@example prompt
prompt = OptionsPrompt(["a lot", "so much", "the most"], "How likely would you be to recomend Term.jl to a friend or colleague?") # don't forget to |> ask
print(prompt) # hide
```

Okay, so much typing though. Let's be realistic, most likely you just want to ask a yes/no question and the answer is likely just yes. So just use a `DefaultPrompt`:

```@example prompt
# one says the first option is the default
prompt = DefaultPrompt(["yes", "no"], 1, "Confirm?") # don't forget to |> ask
print(prompt) # hide
```

still too much typing? You can just use the `confirm` function which is equivalent to asking the prompt shown above.


## Style
The style of prompt elements (e.g. the color of the prompt's text or of the options) is defined in `Theme`. You can also pass style information during prompt creation:

```@example prompt
Prompt("Do you like this color?", "red") |> println
DefaultPrompt(["yes", "no"], 1, "Confirm?", "green", "blue", "red") |> println
```
43 changes: 43 additions & 0 deletions docs/src/ren/annotation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# [Annotation](@id AnnotationDocs)

I could describe what an `Annotation` is, but it's easier to show it:
```@example ann
using Term.Annotations
Annotation(
"This is the main text to annotate",
"main"=>"by main we mean most important, the rest is annotations",
"annotate"=>"annotations are just extra bits of info"
)
```

as you can see, `Panel`s with extra messages are displayed underneath the main bit of text.
Each "annotation" is defined by `Pair`, the first element of the `Pair` is a substring of the
main text indicating what we want to annotate. The second element is used to specify what we
want to annotate it with.

If you want to assign some `Style` information to each annotation, you can specify that by using a `Tuple{String, String}` as second element of the `Annotation` `Pair`. In this tuple, the first part refers to the annotation message while the second can store style information.

```@example ann
Annotation("this has some style", "style"=>("style means color or stuff like bold", "bold red"))
```

and of course you can mix your normal `markup` style too:
Annotation("{bold italic}this{/bold italic} has some style", "style"=>("style means {bright_blue}color{/bright_blue} or stuff like {bold}bold{/bold}", "bold red")).

---

`Annotation` objects are `AbstractRenderables`, so you can mix and match them with other things too.
```@example ann
import Term: Panel, highlight_syntax
code = highlight_syntax("Annotation(\"main text\", \"main\"=>\"most important\")")
Panel(
Annotation(code, "\"main text\""=>"main message to be annotated", "\"main\"=>\"most important\""=>"annotation");
padding=(4, 4, 2, 1),
title="Annotation: usage", fit=true, title_style="default green bold",
title_justify=:center, style="green dim"
)
```
8 changes: 3 additions & 5 deletions docs/src/ren/panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,15 @@ You can justify the panel's content to `:left, :center, :right`!
```
And style the title and subtitle, or the whole background too:
```@example panel
import Term: highlight_syntax, apply_style, do_by_line, fillin
syntax_with_bg(t) = do_by_line(ln -> apply_style(ln, "on_red"), fillin(t) |> highlight_syntax)
import Term: highlight_syntax
Panel(
syntax_with_bg("""
highlight_syntax("""
function show_off(x)
print(x)
end
""");
background="on_red"
background="on_black", fit=true, style="on_black"
)
```
Expand Down
Loading

0 comments on commit d3e94a1

Please sign in to comment.