rnag / cargo-rx Goto Github PK
View Code? Open in Web Editor NEWA simple, modern fuzzy finder tool to run examples in a Cargo project.
License: MIT License
A simple, modern fuzzy finder tool to run examples in a Cargo project.
License: MIT License
rustc
) version: ?In powershell i see weird characters being shown instead of normal color output, for ex. when script outputs the >> cargo run --example <name>
before running the script, for example.
I need to research why it's happening and how to resolve it. I think it's the way we're invoking shell command in code, the pipe command which basically performs the equivalent of echo 'one\ntwo\nthree' | fzf
apparently is not supported well in windows / powershell, at least from what I could tell when searching online.
We need a way to not break colored text output in powershell when piping output of echo
to another process like fzf
.
$ rx
demo link:
https://asciinema.org/a/483363
This might be a bit of a stupid thing, but I need help to strip out the first few seconds (~5 seconds or so) from the start, where it shows as session restored
. I tried with asciinema-edit but couldn't get it to work on my side (using mac). In case curious, I open an issue in the linked project.
For now my setting on asciinema.org are to set idle_time_limit=1.0
but that's not ideal as it speeds up commands in general. so I just want to know how can i strip out first few seconds from the start (and maybe last second or too too). thx ~
trying with asciinema-edit (anyone else have this problem btw?)
$ cat ~/Downloads/483363.cast | asciinema-edit cut --start=0.0 --end=5.0
failed to transform cast: couldn't find initial frame
rustc
) version: 1.59The current output in preview window displayed with skim
is nice and works currently for our purposes, but a future idea might be to customize what gets displayed in preview pane on the right side.
For example, do still want to continue displaying the source code of the example file -- might it make sense to instead display the doc comments, or just any regular comments in the example, for instance? also in that case, would we want to automatically strip out the //!
and leading spaces, and format the comments nicely?
Side note: I've noticed that in some projects there are comments or info on a specific example that is encapsulated as part of a separate file, generally a text/markdown file. For example, for an example like my_example.rs
, in the same directory there is often a separate my_example.md
file which documents info about the example. Maybe, in such cases it would be nice to populate the preview pane with the contents of this markdown file, rather than the source file contents.
Future, future idea: maybe we implement a terminal-based parser for Markdown? I think it would be cool to see **text**
be translated as bold text in the terminal, and ## Header
as a slightly bigger font size or maybe text with a custom background, for example.
Some libraries like tract and axum use workspaces to indicate examples, but current cargo-rx
does not seem to able to identify them.
Identify workspaces for examples based on directory names?
No.
See #11 for sample terminal output.
Essentially, we need to figure out a way to support identifying block comments within /*! <snip> !*/
(for doc comments) or within /* <snip> */
for regular comments, so that we can format and stylize such comments (colored text, bolding, etc.) as expected.
I just went into my project folder and ran:
$ rx
It would be nice to pre-select the last-run example on a per crate basis, whenever rx
is invoked without arguments.
For instance, if the last run example was my_example
and the arguments passed to the example were --my-arg test
, then in the selection list that gets displayed when rx
is run without arguments, it would be nice to pre-select my_example
from the list of available examples for the crate; and the same arguments from last time should be passed in to the example when a user confirms the selection with the Enter key.
rustc
) version: 1.59Output with list of examples is not sorted alphabetically (or even reverse sorted Z->A would be nice), but ideally I suppose it should be.
example for my project smartsheet-rs
:
I just cd
into my project folder after a git clone
and run:
$ rx
It would be nice to set up tab completion for the first positional argument after rx
, similar to how it auto completes when you type cd
to switch into a directory and press tab after entering a partial match, for example.
The rx
command in this case should offer auto-completion suggestions based on the list of examples
for the current Cargo project.
For example if there is a single example in a project called hello_world.rs
, when I enter hello
it should auto complete to hello_world
. If there is more than one example that starts with the entered term, it should offer all possible examples that match the query.
rustc
) version: 1.59I want rx
to automatically prompt for arguments -- i.e. same as invoking --parse-args
-- when we can determine that an example script requires arguments passed in from command-line.
Some ideas on what might work:
//! # Arguments
rx:requires_args
. This way our script knows for certain that a script requires command-line arguments, and can prompt user to input arguments automatically.I don't know if it's possible but I'd like to suggest auto-correction if a user misspells or mistypes an example name, similar to how cargo run --example
does it already currently.
Potentially something like:
Sorry bud, no such example `my_exmaple` exists.
Did you mean `my_example`? [Y/N]: $
Did you mean `my_example`? [Y/N]: $ y
[Runs the example file `my_example`...]
I haven't actually looked into any existing solutions for spelling correction yet. It would be cool to implement this, I feel. Preferably with the least overhead in terms of overall dependency size, compilation or build time, etc.
It's not too necessary as when we call cargo run --example
, it'll already offer an auto correction hint. But I think it's nice to add proactive spellchecking and correction -- this way it'll be a little faster, as we can catch the error earlier, and we don't need to waste time spawning a new process to call cargo run --example
when we already know the example name is misspelled, for example.
Just for completeness sake, Here's a sample auto correction hint from cargo run --example
on one of my projects, which I think is really cool/nice:
PS serde-this-or-that> cargo run --example d
error: no example target named `d`
Did you mean `demo`?
I would like to be able to pass options such as --features
or --release
-- which cargo run
supports currently -- to the rx
command.
I would like to update rx
to also accept same options that cargo run --example
does.
I need to pass --features
in another project currently for some examples occasionally, so this would be helpful to enable. My use case is I have a separate feature for dev/prod environments; and occasionally I would like to run an example for a production environment, i.e. with the relevant feature
enabled.
rustc
) version:Instead of displaying the example file contents directly in the preview pane, it'd be ideal to leverage a text wrapping library such as textwrap to wrap the doc comments -- and regular comments if feasible -- so that we can be sure that the comments completely fit within the preview pane, and are displayed as expected without any text cutting off near the end.
For example, note that comments in a line that are past a max width are hidden in the preview pane currently:
This issue goes with #12
I just cd
into my project folder and ran:
$ rx
This is a simple fix, but basically nested examples like examples/some_example/main.rs
are not captured currently, since we only look one level deep, specifically for rust (.rs
) source files.
Here we will need to update our code to traverse directories in examples/
folder (at least one level deep for now, not sure if Cargo itself supports examples deeply nested in sub-folders) and search for any main.rs
files. The example name displayed should of course be the subfolder name in this case.
Support following paths for rust files in the examples/
folder:
cargo
by default, for instance example/my_folder/my_example_here.rs
[[example]]
sections in the Cargo.toml
filemain.rs
file that cargo
supports, such as examples/my_folder/main.rs
rustc
) version: 1.59It would be ideal to calculate the current console width, then calculate the max width of the stem of each example file (filename without the extension). The max stem width can then be used to set the width of the left pane, and the remaining console width can be taken up by the preview pane on the right.
For example (note the three dots ...
below):
Within my project folder, I just ran:
$ rx
It would be cool if we can automatically replace dashes -
with underscores _
(or vice versa) if we determine that a user-entered example name with dashes -
is not a valid example, but that it would be instead valid with _
.
The main impetus for this is that it is somewhat easier to type a dash -
on a keyboard - don't need to make a beeline for the shift key, for example. ๐ค
Current output when running cargo run --example
, when mis-typing _
as -
for instance:
PS serde-this-or-that> cargo run --example as-string
error: no example target named `as-string`
Did you mean `as_string`?
Desired output:
PS serde-this-or-that> rx as-string
>> cargo run --example as_string
[result of running the `as_string` example]
0.1.0
Mac OS X
When running rx
against an example that takes arguments, when I add quotes around an argument, I would expect the terminal output which displays the command to similarly include quotes around my argument.
For example, when I run following command and select an example my_example
:
$rx -- --my-arg 'my "name" here'
the terminal output of the command being run is currently like:
>> cargo run --example my_example -- --my-arg my name here
when instead, I want it to display like:
>> cargo run --example my_example -- --my-arg "my \"name\" here"
...which more closely matches the format of the command being run. it's also helpful so that we can use the command being printed out for debugging purposes, and if we just copy-paste the command into a terminal window verbatim, it should work the same to run cargo run --example
and not cause any errors when running the example using that approach.
Let's use this project as an example:
https://github.com/sonos/tract
src/bin
I try to run cargo run
at root level, I get following output:
$ cargo run
error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
available binaries: example-dump-nnef-mobilenet-v2, example-nnef-mobilenet-v2, example-onnx-mobilenet-v2, example-pytorch-resnet, example-tensorflow-mobilenet-v2, jupyter-keras-tract-tf1, jupyter-keras-tract-tf2, pytorch-albert-v2, reset-test-list, tract
Hmm - that's strange! Where did all those binaries come from? It's really interesting, because those are not ones defined at root level either. Looks like those are binaries/examples of workspace members actually.
Take this binary target: reset-test-list
It looks like that is actually coming from a workspace member, harness/onnx-test-suite
> src > bin > reset-test-list.rs
. So we need to support this use case first of all - binaries in src/bin
of a workspace member.
Now, when I run cargo run --example
:
$ cargo run --example
error: "--example" takes one argument.
Available examples:
plus3
Hmm - that's really interesting! There is no such example at root level, under example > plus3.rs
. What gives? It looks like this is actually an example from a workspace member, tensorflow
> examples > plus3.rs
. So we will also need to support such examples within workspace members as well.
All runnable targets are included in output when rx
is entered in a terminal.
n/a
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.