mirror of
https://github.com/vlang/v.git
synced 2025-09-10 16:00:31 -04:00
flag, examples: add compact
to flag.DocOptions
(#21888)
This commit is contained in:
parent
6d3a2acf23
commit
3bc6d30b69
@ -36,6 +36,8 @@ enum Edit {
|
|||||||
description_padding
|
description_padding
|
||||||
description_width
|
description_width
|
||||||
flag_indent
|
flag_indent
|
||||||
|
// DocOptions.compact
|
||||||
|
compact
|
||||||
// DocOptions.show flags
|
// DocOptions.show flags
|
||||||
name
|
name
|
||||||
version
|
version
|
||||||
@ -56,6 +58,9 @@ pub fn (e Edit) next() Edit {
|
|||||||
.flag_indent
|
.flag_indent
|
||||||
}
|
}
|
||||||
.flag_indent {
|
.flag_indent {
|
||||||
|
.compact
|
||||||
|
}
|
||||||
|
.compact {
|
||||||
.name
|
.name
|
||||||
}
|
}
|
||||||
.name {
|
.name {
|
||||||
@ -124,6 +129,9 @@ fn event(e &tui.Event, mut app App) {
|
|||||||
.description_width {
|
.description_width {
|
||||||
app.layout.description_width += incr_decr
|
app.layout.description_width += incr_decr
|
||||||
}
|
}
|
||||||
|
.compact {
|
||||||
|
app.options.compact = !app.options.compact
|
||||||
|
}
|
||||||
.name {
|
.name {
|
||||||
app.options.show.toggle(.name)
|
app.options.show.toggle(.name)
|
||||||
}
|
}
|
||||||
@ -165,6 +173,9 @@ fn frame(mut app App) {
|
|||||||
.description_width {
|
.description_width {
|
||||||
'${app.layout.description_width}'
|
'${app.layout.description_width}'
|
||||||
}
|
}
|
||||||
|
.compact {
|
||||||
|
if app.options.compact { 'on' } else { 'off' }
|
||||||
|
}
|
||||||
.name {
|
.name {
|
||||||
if app.options.show.has(.name) { 'on' } else { 'off' }
|
if app.options.show.has(.name) { 'on' } else { 'off' }
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,8 @@ pub mut:
|
|||||||
pub struct DocOptions {
|
pub struct DocOptions {
|
||||||
pub mut:
|
pub mut:
|
||||||
flag_header string = '\nOptions:'
|
flag_header string = '\nOptions:'
|
||||||
show Show = ~Show.zero()
|
compact bool
|
||||||
|
show Show = ~Show.zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
// max_width returns the total width of the `DocLayout`.
|
// max_width returns the total width of the `DocLayout`.
|
||||||
@ -732,12 +733,20 @@ pub fn (fm FlagMapper) fields_docs(dc DocConfig) ![]string {
|
|||||||
flag_line_diff := flag_line.len - pad_desc
|
flag_line_diff := flag_line.len - pad_desc
|
||||||
if flag_line_diff < 0 {
|
if flag_line_diff < 0 {
|
||||||
diff := -flag_line_diff
|
diff := -flag_line_diff
|
||||||
docs << flag_line + ' '.repeat(diff) +
|
mut line := flag_line + ' '.repeat(diff) +
|
||||||
keep_at_max(doc, desc_max).replace('\n', '\n${empty_padding}') + '\n'
|
keep_at_max(doc, desc_max).replace('\n', '\n${empty_padding}')
|
||||||
|
if !dc.options.compact {
|
||||||
|
line += '\n'
|
||||||
|
}
|
||||||
|
docs << line
|
||||||
} else {
|
} else {
|
||||||
docs << flag_line
|
docs << flag_line
|
||||||
docs << empty_padding + keep_at_max(doc, desc_max).replace('\n', '\n${empty_padding}') +
|
mut line := empty_padding +
|
||||||
'\n'
|
keep_at_max(doc, desc_max).replace('\n', '\n${empty_padding}')
|
||||||
|
if !dc.options.compact {
|
||||||
|
line += '\n'
|
||||||
|
}
|
||||||
|
docs << line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Look for custom flag entries starting with delimiter
|
// Look for custom flag entries starting with delimiter
|
||||||
@ -746,12 +755,20 @@ pub fn (fm FlagMapper) fields_docs(dc DocConfig) ![]string {
|
|||||||
flag_line_diff := entry.len - pad_desc + indent_flags
|
flag_line_diff := entry.len - pad_desc + indent_flags
|
||||||
if flag_line_diff < 0 {
|
if flag_line_diff < 0 {
|
||||||
diff := -flag_line_diff
|
diff := -flag_line_diff
|
||||||
docs << indent_flags_padding + entry.trim(' ') + ' '.repeat(diff) +
|
mut line := indent_flags_padding + entry.trim(' ') + ' '.repeat(diff) +
|
||||||
keep_at_max(doc, desc_max).replace('\n', '\n${empty_padding}') + '\n'
|
keep_at_max(doc, desc_max).replace('\n', '\n${empty_padding}')
|
||||||
|
if !dc.options.compact {
|
||||||
|
line += '\n'
|
||||||
|
}
|
||||||
|
docs << line
|
||||||
} else {
|
} else {
|
||||||
docs << indent_flags_padding + entry.trim(' ')
|
docs << indent_flags_padding + entry.trim(' ')
|
||||||
docs << empty_padding +
|
mut line := empty_padding +
|
||||||
keep_at_max(doc, desc_max).replace('\n', '\n${empty_padding}') + '\n'
|
keep_at_max(doc, desc_max).replace('\n', '\n${empty_padding}')
|
||||||
|
if !dc.options.compact {
|
||||||
|
line += '\n'
|
||||||
|
}
|
||||||
|
docs << line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user