Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

long_desc: force keeping spaces and not break lines #398

Closed
mdesantis opened this issue Jan 17, 2014 · 15 comments
Closed

long_desc: force keeping spaces and not break lines #398

mdesantis opened this issue Jan 17, 2014 · 15 comments

Comments

@mdesantis
Copy link

Hello,

I have a long_desc method like this:

long_desc <<-LONGDESC.gsub("\n", "\x5")
  Examples:

  bin/ruby-rails-documentations                             \\
    generate ~/ruby-rails-documentations                    \\
    --sdoc-dir=~/sdoc --ruby-dir=~/ruby --rails-dir=~/rails \\
    --ruby-versions=1.9.3p484 2.0.0p353 2.1.0               \\
    --rails-versions=3.0.20 3.1.12 3.2.16 4.0.2 4.1.0.beta1
LONGDESC
def generate(output_dir)
  ...
end

Executing ruby-rails-documentations help generate I want my output to be like this:

Examples:

bin/ruby-rails-documentations                             \
  generate ~/ruby-rails-documentations                    \
  --sdoc-dir=~/sdoc --ruby-dir=~/ruby --rails-dir=~/rails \
  --ruby-versions=1.9.3p484 2.0.0p353 2.1.0               \
  --rails-versions=3.0.20 3.1.12 3.2.16 4.0.2 4.1.0.beta1

Instead, I get this:

Examples:

bin/ruby-rails-documentations \
 generate ~/ruby-rails-documentations \
 --sdoc-dir=~/sdoc --ruby-dir=~/ruby --rails-dir=~/rails \
 --ruby-versions=1.9.3p484 2.0.0p353 2.1.0 \
 --rails-versions=3.0.20 3.1.12 
3.2.16 4.0.2 4.1.0.beta1

The merged spaces is not a big problem, but the added newlines is - they break the command syntax, and I can't predict where they will be.

Is there any way to force keeping spaces and, above all, force to not break lines?

@tonytonyjan
Copy link

+1

tonytonyjan added a commit to tonytonyjan/thor that referenced this issue Aug 3, 2014
@bradland
Copy link

bradland commented Dec 4, 2014

Experiencing issues with long_desc line breaks as well. When formatting documentation, it is essential that the author have control over the way that the text will break. This is especially true for console applications, where an incorrect line break can cause unrecoverable, or even destructive, errors.

It looks like the long description is being printed using the Shell::Basic#print_wrapped method, which is a pretty basic text wrapping implementation. Given the likelihood that long descriptions will contain code examples, would the maintainers be open to changing the method used to render the long description?

@jinhianlee
Copy link

+1 for @bradland's comment.

@xWayfinder
Copy link

Is this change ever getting merged into master?

@hfossli
Copy link

hfossli commented Aug 13, 2015

Bump

@jsuwo
Copy link

jsuwo commented Jan 6, 2016

+1

1 similar comment
@vigo
Copy link

vigo commented Jul 23, 2016

+1

@meissadia
Copy link

+1

Finding it impossible to get my long_desc displayed correctly. Line-wraps are sporadic once I use \x5.

For my sanity, I've simply redefined Basic#print_wrapped in my project to output the long_desc as-is.

class Thor
  module Shell
    class Basic
      def print_wrapped(message, options = {})
         stdout.puts message
       end
    end
  end
end

@aks
Copy link

aks commented Feb 9, 2018

I like an option to long_desc, that disables the wrapping. eg:

long_desc <<~MSG, wrapping: false
  formatted text that is not wrapped
 ...
MSG

@jutonz
Copy link

jutonz commented Mar 5, 2018

fwiw you can insert tabs with \t until there's a better option available

@vicmunoz
Copy link

+1

2 similar comments
@sonjz
Copy link

sonjz commented Oct 24, 2018

+1

@djhoffman-stripe
Copy link

+1

@artob
Copy link

artob commented May 2, 2020

+1

Finding it impossible to get my long_desc displayed correctly. Line-wraps are sporadic once I use \x5.

For my sanity, I've simply redefined Basic#print_wrapped in my project to output the long_desc as-is.

class Thor
  module Shell
    class Basic
      def print_wrapped(message, options = {})
         stdout.puts message
       end
    end
  end
end

Thanks for that, @meissadia. Though it was a little too simplistic for me, given a need for indented multi-line output, so I expanded on it slightly:

# Fix for https://github.com/erikhuda/thor/issues/398
class Thor::Shell::Basic
  def print_wrapped(message, options = {})
    indent = (options[:indent] || 0).to_i
    if indent.zero?
      self.stdout.puts message
    else
      message.each_line do |message_line|
        self.stdout.print ' ' * indent
        self.stdout.puts message_line.chomp
      end
    end
  end
end # Thor::Shell::Basic

@doudou
Copy link
Contributor

doudou commented Sep 11, 2020

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests