17 个版本

0.4.7 2024年4月20日
0.4.0 2022年12月10日
0.3.2 2021年7月4日
0.3.1 2020年10月9日
0.2.0 2019年10月23日

#847 in 命令行工具

MIT/Apache

33KB
490

prose

Build Status Crates.io Crates.io

一个用于重新格式化文本的 CLI 工具。

prosepar 启发,旨在相似,尽管功能较少,同时也具有 Unicode 支持。

安装

通过预构建的二进制发布版

下载您平台的最新发布版,解压,并将 prose 二进制文件放在您想要的位置。

注意:在最近版本的 Mac OS 上,您可能需要取消隔离下载的二进制文件才能运行。要这样做

xattr -d com.apple.quarantine path/to/prose

通过 cargo

如果您是 Rust 程序员,可以使用 cargo 安装 prose。请注意,prose 最低支持的 Rust 版本是 1.38.0,尽管它可能适用于旧版本。

cargo install prose

示例

给定以下输入,一个来自 STDIN 的 Angela Davis 的引言

I believe profoundly in the possibilities of democracy, but democracy needs
to be emancipated from capitalism. As long as we inhabit
a capitalist democracy, a future of
racial equality, gender equality, economic equality will elude us.

让我们看看一些调用及其输出。

作为基准,我们可以查看标准 fmt 会产生什么。

fmt -44
I believe profoundly in the possibilities of
democracy, but democracy needs to be
emancipated from capitalism. As long as we
inhabit a capitalist democracy, a future of
racial equality, gender equality, economic
equality will elude us.

使用相同的宽度选项,prose 产生更整齐的输出。

prose -w 44
I believe profoundly in the possibilities
of democracy, but democracy needs to be
emancipated from capitalism. As long as we
inhabit a capitalist democracy, a future of
racial equality, gender equality, economic
equality will elude us.

使用相同的宽度选项,prose 产生更整齐的输出。

前缀和后缀(如代码注释)

prose 尝试保持前缀/后缀行装饰(如边框、代码注释标记和缩进)完整。

考虑以下输入

/* Lorem ipsum dolor sit ameÞ, sea ðicat instructíor deterrúisset cu, ex */
/* graéce scriptæ minimum eós. Nö qui plæcérat eloquentiam, alíenum */
/* sæluÞæÞus evertitur éam nö, mucíus tibíque ad esÞ. Atqui fêugâit eum */
/* id. Síngulis, id meí chöro essent. Íð æssentior moderatius intellégam */
/* næm, solet abhorreant ne cum. Qúod æssum intellegam ad vím, pró diam */
/* vítae nónumy ei, cúm inaní primís té. */
/*  */
/* Ex dicunt åssentiør eum, ad nusquam definiebæs qui, */
/* vidit åtqui per ut. Qui ut simul dicunt */
/* sålutændi. Dūō scaevōla vulputaÞe ut. Quō volupÞua rætiōnibus uÞ, et */
/* postulǽnt intellegǽt vitupērata vim. Primis legimus haȝemus sit æð, */
/* seæ hǣrum, fâcilisi, êum ôfficiis iudicabit âd. */

和输出

prose -w 44 -l
/* Lorem ipsum dolor sit ameÞ, sea        */
/* ðicat instructíor deterrúisset cu,     */
/* ex graéce scriptæ minimum eós. Nö      */
/* qui plæcérat eloquentiam, alíenum      */
/* sæluÞæÞus evertitur éam nö, mucíus     */
/* tibíque ad esÞ. Atqui fêugâit eum      */
/* id. Síngulis, id meí chöro essent.     */
/* Íð æssentior moderatius intellégam     */
/* næm, solet abhorreant ne cum. Qúod     */
/* æssum intellegam ad vím, pró diam      */
/* vítae nónumy ei, cúm inaní primís té.  */
/*                                        */
/* Ex dicunt åssentiør eum, ad nusquam    */
/* definiebæs qui, vidit åtqui per        */
/* ut. Qui ut simul dicunt sålutændi.     */
/* Dūō scaevōla vulputaÞe ut. Quō         */
/* volupÞua rætiōnibus uÞ, et postulǽnt   */
/* intellegǽt vitupērata vim. Primis      */
/* legimus haȝemus sit æð, seæ hǣrum,     */
/* fâcilisi, êum ôfficiis iudicabit âd.   */

它还尝试保留段落缩进

给定以下缩进输入

    I believe profoundly in the possibilities of democracy, but democracy needs
to be emancipated from capitalism. As long as we inhabit
a capitalist democracy, a future of
racial equality, gender equality, economic equality will elude us.
prose -w 60
    I believe profoundly in the possibilities of democracy,
but democracy needs to be emancipated from capitalism. As
long as we inhabit a capitalist democracy, a future of
racial equality, gender equality, economic equality will
elude us.

电子邮件引用

prose 尝试智能地保持电子邮件引用级别,如果它们是可识别的格式 > 引入每个新的引用级别。以下是一个示例电子邮件输入

Abby,

Whoops! Sorry about that. I forgot to export it as a PDF. Re-attaching
to this message. Again, let me know if you need anything else!

Bill

Abby writes:

> Bill,
> 
> I tried to open the attachment, but it looks like it isn't in the correct format. Could
> you re-send it?
> 
> Thanks,
> 
> Abby
> 
> Bill writes:
> 
> > Abby,
> >
> > I like the way this project is turning out so far! Kudos.
> > 
> > I'm attaching my first pass at working version. Let me know if you need anything else
> > before our meeting on Tuesday.
> > 
> > Cheers,
> > 
> > Bill
> 
>
> This message and its contents are confidential or whatever.
> 

仅设置宽度

prose -w 48
Abby,

Whoops! Sorry about that. I forgot to export it
as a PDF. Re-attaching to this message. Again,
let me know if you need anything else!

Bill

Abby writes:

> Bill,
>
> I tried to open the attachment, but it looks
> like it isn't in the correct format. Could you
> re-send it?
>
> Thanks,
>
> Abby
>
> Bill writes:
>
> > Abby,
> >
> > I like the way this project is turning out
> > so far! Kudos.
> >
> > I'm attaching my first pass at working
> > version. Let me know if you need anything
> > else before our meeting on Tuesday.
> >
> > Cheers,
> >
> > Bill
>
> This message and its contents are confidential
> or whatever.
>

使用 fit 选项,"-f"

没有 -f,结果可以,但边缘可能看起来稍微不那么参差不齐。

prose -w 58
I believe profoundly in the possibilities of democracy,
but democracy needs to be emancipated from capitalism. As
long as we inhabit a capitalist democracy, a future of
racial equality, gender equality, economic equality will
elude us.

56 或左右的宽度参数可以让我们达到那里,如果我们对最长可能的最大行长度小于我们指定的目标(宽度)感到满意,我们可以传递 -f

prose -w 58 -f
I believe profoundly in the possibilities of democracy,
but democracy needs to be emancipated from capitalism.
As long as we inhabit a capitalist democracy, a future
of racial equality, gender equality, economic equality
will elude us.

使用Markdown输入

例如,以下这部分贡献者公约行为准则

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

使用标准调用

prose -w 42
## Our Pledge

In the interest of fostering an open
and welcoming environment, we as
contributors and maintainers pledge to
making participation in our project
and our community a harassment-free
experience for everyone, regardless of
age, body size, disability, ethnicity,
sex characteristics, gender identity
and expression, level of experience,
education, socio-economic status,
nationality, personal appearance,
race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to
creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints
* and experiences Gracefully accepting
* constructive criticism Focusing on
* what is best for the community Showing
* empathy towards other community members

注意项目符号列表是如何合并在一起的。为了保留项目符号列表和其他格式,请使用-m--markdown选项。这样做将输入解释为Markdown,仅格式化普通段落。

prose -w 42 --markdown
## Our Pledge

In the interest of fostering an open
and welcoming environment, we as
contributors and maintainers pledge to
making participation in our project
and our community a harassment-free
experience for everyone, regardless of
age, body size, disability, ethnicity,
sex characteristics, gender identity
and expression, level of experience,
education, socio-economic status,
nationality, personal appearance,
race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to
creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

未来的版本可能会通过更智能地缩进项目符号列表来改进这一点。

许可证

根据您选择的以下任一项许可

自由选择。

依赖项

~5MB
~89K SLoC