Commit Graph

140 Commits

Author SHA1 Message Date
Robin Krahl
ce06129976
Remove Notable Traits section from definitions
Rust 1.47.0 introduced the Notable Traits section that lists information
about types used in code block.  As we only want to display the code
block itself without meta-information, this patch ignores the
notable-traits class when extracting the text from nodes.
2020-10-08 21:10:35 +02:00
Robin Krahl
9832c22b4d
Add tests for Rust 1.47.0
This patch adds unit tests for the new Rust 1.47.0 release.  Except for
the new Notable Traits section, we’re already parsing the output
correctly.
2020-10-08 21:07:52 +02:00
Robin Krahl
9dd54e3219
Add vim-like keybindings to tui viewer
This patch adds vim-like keybindings to the tui viewer:  hjkl for
navigation, G and g (instead of gg) for End and Home, and Ctrl+F and
Ctrl+B for Page Down and Up.
2020-10-08 11:00:48 +02:00
Robin Krahl
7756803e35
Remove textwrap dependency
The textwrap dependency was added mistakenly.
2020-10-08 10:33:39 +02:00
Robin Krahl
b93dbca7f0
Replace ansi_term, atty, terminal_size with termion
In the last patch, we added the termion dependency for the tui viewer.
With this patch, we remove the ansi_term, atty and terminal_size
dependencies and use termion instead.
2020-10-08 10:32:05 +02:00
Robin Krahl
8db34e33b2
Use termion backend for cursive
With this patch, we replace cursive’s default ncurses backend with the
termion backend.  This has multiple reasons:
- The ncurses backend has safety issues, see [0].
- ncurses requires a pre-installed library and a C compiler, introducing
  additional build dependencies.  Termion is implemented in Rust only.
- ncurses does not work on Windows, while termion works in all terminals
  that support ANSI escape codes.

Per default, the termion backend does not buffer the output which may
cause flickering [1].  Therefore, we also use the
cursive_buffered_backend that buffers the output and fixes the
flickering problem.

[0] https://github.com/gyscos/cursive/issues/488
[1] https://github.com/gyscos/cursive/issues/142
2020-10-08 10:30:17 +02:00
Robin Krahl
568fb0acc8
Use cursive-markup to replace HtmlView
We’ve moved the HtmlView into a separate crate, so we can replace our
own HtmlView with cursive_markup::MarkupView.  We only have to implement
a custom Renderer that applies the syntax highlighting to code snippets.
2020-10-08 10:00:26 +02:00
Robin Krahl
4c5d5808aa
Add links to module items
This patch adds links to the items in the module member list.  This only
applies for the tui viewer, as the links wouldn’t provide any additional
information for the plain and rich viewers.
2020-10-06 20:35:25 +02:00
Robin Krahl
8e8f7728e2
Replace Option::zip with custom function
In the previous commit, we used the Option::zip method to make querying
the focus and the links in the HtmlView struct easier.  But Option::zip
has only been added in Rust 1.46, so we replace it with a custom utility
function to keep compatibility with Rust 1.40.
2020-10-06 19:43:06 +02:00
Robin Krahl
e222a1f443
Add TUI viewer using cursive
This patch adds a new viewer, tui, that provides an interactive
interface using cursive.  This viewer makes it possible to follow links
to other documentation items and to open external links in a web
browser.
2020-10-06 19:19:13 +02:00
Robin Krahl
4260aab85a
Display link targets in rich viewer
Previously, we only used the underline effect to highlight links in the
rich viewer, but we did not provide any information about their target.
With this patch, we print a list of link at the end of a block, similar
to the plain text viewer.
2020-10-06 14:42:49 +02:00
Robin Krahl
6ea5f070d2
Remove Decorator::show_links field
We are currently always listing the links in the plain text viewer when
rendering HTML, so we no longer need the show_links field that could be
used to disable link listing.
2020-10-06 11:34:15 +02:00
Robin Krahl
bf47310f51
Fix link formatting in rich viewer
When changing the viewer to use the text-style crate, we mistakenly
changed the format for links in the rich viewer from underline to bold.
This patch fixes that mistake.
2020-10-04 20:25:11 +02:00
Robin Krahl
ae1e7ebddf
Use custom rich text decorator
This patch changes the rich viewer to use a custom rich text decorator.
As we use colors to highlight code, and as we print the string text with
a bold font, we don’t need a backtick or an asterix to indicate these
elements.
2020-10-04 20:22:52 +02:00
Robin Krahl
f92fc3e9f6
Refactor HTML processing into viewer::utils
This patch moves the HTML processing (i. e. syntax highlighting for code
snippets) into the viewer::utils method.  This allows us to use it for
other viewers too.
2020-10-04 19:52:23 +02:00
Robin Krahl
ecf810929a
Add syntax highlighting for doc comments
This patch adds syntax highlighting for code blocks in the doc comments.
Previously, we only highlighted the definition of the documented
elements.  With this patch, we also highlight code blocks in the doc
blocks, like examples.
2020-10-03 19:06:21 +02:00
Robin Krahl
ecc05ddc7d
Update html2text dependency to v0.2.1
This patch updates the html2text dependency to v0.2.1.  This release
fixed the handling of preformatted blocks, allowing us to add syntax
highlighting for code blocks in the next patch.
2020-10-03 19:04:45 +02:00
Robin Krahl
970277d32c
Refactor syntax highlighting into viewer::utils
This patch introduces the viewer::utils::Highlighter struct that takes
care of syntax highlighting.  This will make it easier to use syntax
highlighting from others viewers once we add them.
2020-10-03 15:57:09 +02:00
Robin Krahl
9458b280d4
Use text-style crate to format text
This patch replaces the direct text formatting with ansi_term with the
text-style crate.  This also allows us to directly convert the syntect
annotations to styled strings.
2020-10-03 15:44:00 +02:00
Robin Krahl
ecb3d40c59
Use ansi_term, atty, terminal_size
This patch replaces the crossterm dependency with ansi_term, atty and
terminal_size.  This allows us for an easier integration with the
text_style crate in an upcoming patch, and it reduces the total number
of dependencies from 166 to 160.

This means that we drop support for non-ANSI terminals, but as this only
affects old versions of cmd.exe/PowerShell, we don’t care about it.
2020-10-02 13:10:37 +02:00
Robin Krahl
225e19a024
Use merge to merge arguments and configuration
This patch adds the merge dependency to automatically merge the
command-line arguments and the settings from the configuration file.
This means that we no longer have to manually maintain the Args::merge
function.
2020-09-20 22:18:28 +02:00
Robin Krahl
0bf2f15186
Refactor text viewers into ManRenderer
This patch introduces the ManRenderer trait that can be used by viewers
that render documentation in a man-like style.  This is a more general
version of the previous Printer trait.
2020-09-17 17:05:09 +02:00
Robin Krahl
b7f5d3b855
Introduce viewer::utils module
This patch adds the viewer::utils module with utility methods for viewer
implementations.  It contains common functions for text rendering and
syntax highlighting.
2020-09-17 17:05:02 +02:00
Robin Krahl
0c38bf9606
Remove suffix from duplicate members
We use the HTML ID of a member element to get its name.  If there are
multiple members with the same type and name (e. g. from a Deref
implementation), the ID has a suffix to make it unique.  Previosuly, we
just interpreted this suffix as part of the name.  With this patch, we
strip the suffix and only use the actual name.
2020-09-17 17:04:53 +02:00
Robin Krahl
642bec6687
Release v0.3.0
This minor release adds support for Rust 1.46.0 and significantly
improves the test suite.
2020-09-11 21:58:29 +02:00
Robin Krahl
c97ac33dc9
Add test case for Index::find
As we only support the new search index format introduced in April 2020,
the test is only run for Rust >= 1.44.0.
2020-09-11 21:11:07 +02:00
Robin Krahl
77a9163bb1
Add test case for Parser::find_member 2020-09-11 20:55:23 +02:00
Robin Krahl
229b1bdd5c
Add test suite for Rust 1.46.0 2020-09-11 20:30:19 +02:00
Robin Krahl
71280ddb16
Refactor member lookup
Up to rustdoc version 1.45.2, the code element containing the definition
of a member always had the ID "<name>.v".  This ID has been dropped in
rustdoc 1.46.0.  Therefore we now look for members by searching for the
heading which has the id "<ty>.<name>" (for all possible types).
2020-09-11 20:30:12 +02:00
Robin Krahl
628377c83b
Refactor test suite to check multiple versions
This patch refactors the test suite:
- Instead of always generating the documentation with the available
  rustdoc version, we now store generated documentation for all
  supported rustdoc versions in the test/html directory.
- Instead of using one snapshot per test case, we now use one snapshot
  per test case and rustdoc version.
2020-09-11 20:30:05 +02:00
Robin Krahl
5b2003b979
Respect item type in documentation lookup
Sometimes, there might be multiple items with the same name, for example
std::u8 is both a module and a primitive.  Previously, we could not
determine which one Source::load_doc would return.  With this patch, we
add the ty parameter that can be used to filter by the item type.
2020-08-18 22:30:55 +02:00
Robin Krahl
c672a65d59
Add item type to the IndexItem struct
Previously, we only used the name and the description to represent index
items.  Therefore we consider e. g. the std::u8 module and the std::u8
primitive to be the same.  With this patch, we also take the item type
into account when comparing index items.
2020-08-18 21:55:00 +02:00
Robin Krahl
8e97ad269b
Store member groups in BTreeMap
With this patch, we change the type of the Doc::groups field to
BTreeMap<ItemType, Vec<MemberGroup>>.  This makes it clearer and easier
to read.  We also reorder the ItemType module so that the output order
of the member groups is not changed by this patch.
2020-08-17 13:53:41 +02:00
Robin Krahl
e74ef86ebe
Move ItemType u8 representations into index module
Previosuly, we used the u8 values for the ItemType variants used in the
search index as the discriminant.  But as the ID used in the search
index is an implementation detail of the index parser, this patch moves
the mapping to the index module.
2020-08-17 13:42:10 +02:00
Robin Krahl
861a2e8861
Wrap code snippets in Code struct
In commit 729414cbfe16324379ac0b886ba65349bbf44ff6, we introduced the
Text struct that wraps HTML and plain text to make it clear what data we
store in the fields of the Doc and Example structs.  This patch adds the
Code struct that stores a plain-text representation of code snippets to
make the structs even clearer and to make it easier to transition to
plain-text-only code, e. g. provided by the new JSON backend.
2020-08-17 12:01:23 +02:00
Robin Krahl
fefac9f2fc
Move doc::ItemType::group_id to the parser module
Previously, the doc::ItemType::group_id method returned the ID of the
section for the item type in the HTML documentation files.  This patch
refactors the method into the get_item_group_id function in the parser
module as it is an implementation detail of the HTML parser.
2020-08-17 11:45:46 +02:00
Robin Krahl
ebc9c58838
Remove doc::ItemType::class method
We only query the item class for two variants.  It is easier to hardcode
this two classes instead of providing all available classes.
2020-08-17 11:40:33 +02:00
Robin Krahl
473b091fca
Move parser utility methods into submodule
This patch introduces the parser::util mod with utility methods for HTML
parsing.  These utility methods are members of the new NodeRefExt trait
that is implemented for kuchiki::NodeRef and kuchiki::NodeDataRef<T>.
2020-08-17 11:31:47 +02:00
Robin Krahl
1e9da34694
Refactor Parser::parse_item_doc
This patch simplifies the Parser::parse_item_doc function by collecting
all members before pushing them into the member groups.
2020-08-17 11:08:09 +02:00
Robin Krahl
93575ab452
Move public parser interface into Parser struct
To avoid parsing the same file multiple times under some circumstances,
we introduce the Parser struct that stores the document node and
provides the public interface of the parser module.
2020-08-17 11:08:03 +02:00
Robin Krahl
d1c171c385
Refactor documentation lookup into source
Previously, the Crate, Item and Doc struct made assumptions about the
structure of the documentation source by calling the parser directly.
This works with our current setup with only one documentation format and
one documentation source.  But as we intend to add other formats in the
future, we refactor the documentation lookup into the source module
where the format and the source can be taken into account.
2020-08-15 00:18:20 +02:00
Robin Krahl
76845785ee
Release v0.2.0
This minor release adds support for syntax highlighting of code snippets
and for configuration files.
2020-08-11 10:31:03 +02:00
Robin Krahl
3affe94234
Update installation instructions
This patch updates the installation instructions with information on the
AUR packgage and on the tarball downloads.
2020-08-11 09:59:43 +02:00
Robin Krahl
28c025fd4f
Add --width and --max-width options
This patch adds the --width option to select a fixed output width and
the --max-width to set a maximum output width if the width is
dynamically set using the terminal size.
2020-08-11 09:42:21 +02:00
Robin Krahl
1a518d7509
Add integration tests
This patch adds an integration test suite using the insta crate for
snapshot testing.  The test suite is tested for all supported Rust
versions and should always succeed for the MSRV (currently 1.40.0) and
the current stable Rust version.

However there are some minor changes in the configuration format between
Rust versions, so tests that don’t work on all supported Rust versions
are marked with the ignore attribute.  But even the ignored tests should
work on the stable Rust release.
2020-08-11 09:31:20 +02:00
Robin Krahl
17e407d6b1
Improve line breaks for code
kuchiki’s NodeRef::text_contents() implementation does not take into
account the value of the display attribute or line breaks caused by br
elements.  Therefore we have to implement our own converter that
produces readable output for the HTML code generated by rustdoc.
2020-08-11 01:08:00 +02:00
Robin Krahl
7d1bf00d31
Show links in item description
In commit 81c9cf53d6, I accidentally
disabled the links when rendering the item description.  This patch
fixes this mistake.
2020-08-11 01:02:00 +02:00
Robin Krahl
a6b2d570b3
Add --config-file option to set custom config file
This patch adds the --config-file option that allows the user to specify
a custom configuration file (or to disable reading configuration files
if the option is set to "-").
2020-08-10 23:49:13 +02:00
Robin Krahl
e5ee4df73b
Add support for configuration files
With this patch, we load defaults for the command-line arguments from
the configuration file located in the user configuration directory
according to the XDG Base Directory Specification.
2020-08-10 23:37:26 +02:00
Robin Krahl
3a20d662c5
Move command-line arguments into args module
This patch crates the args module, renames the Opt struct to Args and
moves it to the new args module.  This makes the main.rs file easier to
read and allows us to add more details to the Args struct in the future.
2020-08-10 23:07:57 +02:00