Skip to content

Commit 1bd15a7

Browse files
authored
Merge pull request #688 from bashly-framework/add/settings-word-wrap
Add word_wrap option to settings
2 parents d663616 + 3e14527 commit 1bd15a7

File tree

15 files changed

+39
-11
lines changed

15 files changed

+39
-11
lines changed

examples/render-mandoc/docs/download.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Automatically generated by Pandoc 3.2
22
.\"
3-
.TH "download" "1" "November 2025" "Version 0.1.0" "Sample application"
3+
.TH "download" "1" "December 2025" "Version 0.1.0" "Sample application"
44
.SH NAME
55
\f[B]download\f[R] \- Sample application
66
.SH SYNOPSIS

examples/render-mandoc/docs/download.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% download(1) Version 0.1.0 | Sample application
22
% Lana Lang
3-
% November 2025
3+
% December 2025
44

55
NAME
66
==================================================

lib/bashly/concerns/renderable.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def user_file_exist?(file)
5151
File.exist? user_file_path(file)
5252
end
5353

54+
# Returns a wrapped, indented and sanitized string
55+
# Designed to place help and example messages inside bash's 'printf'
56+
def user_string(text, indent: 0)
57+
wrap = Settings.word_wrap - indent
58+
text.wrap(wrap).indent(indent).sanitize_for_print
59+
end
60+
5461
private
5562

5663
def view_path(view)

lib/bashly/extensions/string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def to_path
3333
tr(' ', '/').downcase
3434
end
3535

36-
def wrap(length = 80)
36+
def wrap(length)
3737
strip!
3838
split("\n").collect! do |line|
3939
if line.length > length

lib/bashly/libraries/settings/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ strict: false
8484
# (every 2 leading spaces will be converted to a tab character)
8585
tab_indent: false
8686

87+
# Set the character width used to wrap help and example messages
88+
word_wrap: 80
89+
8790
# Choose a post-processor for the generated script:
8891
# formatter: internal # Use Bashly’s built-in formatter (removes extra newlines)
8992
# formatter: external # Run the external command `shfmt --case-indent --indent 2`

lib/bashly/settings.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class << self
2727
:tab_indent,
2828
:target_dir,
2929
:usage_colors,
30-
:var_aliases
30+
:var_aliases,
31+
:word_wrap
3132
)
3233

3334
def commands_dir
@@ -173,6 +174,10 @@ def var_aliases
173174
@var_aliases ||= get :var_aliases
174175
end
175176

177+
def word_wrap
178+
@word_wrap ||= get :word_wrap
179+
end
180+
176181
private
177182

178183
def get(key)

lib/bashly/views/argument/usage.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
= view_marker
22

33
> printf " %s\n" "{{ label.color(:arg) }}"
4-
> printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
4+
> printf "{{ user_string help, indent: 4 }}\n"
55

66
if allowed
77
> printf " %s\n" "{{ strings[:allowed] % { values: allowed.join(', ') } }}"

lib/bashly/views/command/examples_on_error.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ if Settings.show_examples_on_error && examples
33

44
> printf "{{ strings[:examples_caption_on_error] }}\n" >&2
55
examples.each do |example|
6-
> printf "{{ example.wrap(78).indent(2).sanitize_for_print }}\n" >&2
6+
> printf "{{ user_string example, indent: 2 }}\n" >&2
77
end
88
end

lib/bashly/views/command/usage.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else
99
= help_header_override.indent 4
1010
else
1111
> printf "{{ full_name }}\n\n"
12-
> printf "{{ help.wrap(78).indent(2).sanitize_for_print }}\n\n"
12+
> printf "{{ user_string help, indent: 2 }}\n\n"
1313
end
1414
> else
1515
> printf "{{ caption_string.sanitize_for_print }}\n\n"

lib/bashly/views/command/usage_args.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ end
1212
if catch_all.help
1313
>
1414
> echo " {{ catch_all.label }}"
15-
> printf "{{ catch_all.help.wrap(76).indent(4).sanitize_for_print }}\n"
15+
> printf "{{ user_string catch_all.help, indent: 4 }}\n"
1616
> echo
1717
end
1818

0 commit comments

Comments
 (0)