mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-10-22 07:21:21 +00:00
Automatically break help output at the actual terminal width.
Works only with programs using the cli_parser_c class. This is only mkvpropedit so far, but the others will follow. Oh, and this only works if ioctl & TIOCGWINSZ are available.
This commit is contained in:
parent
8047b67309
commit
50b994599b
14
ac/tiocgwinsz.m4
Normal file
14
ac/tiocgwinsz.m4
Normal file
@ -0,0 +1,14 @@
|
||||
AC_CACHE_CHECK([for ioctl & TIOCGWINSZ], [ac_cv_tiocgwinsz],[
|
||||
ac_cv_tiocgwinsz="no"
|
||||
AC_LANG_PUSH(C++)
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/ioctl.h>
|
||||
],[
|
||||
struct winsize ws;
|
||||
ioctl(0, TIOCGWINSZ, &ws);
|
||||
],[ac_cv_tiocgwinsz="yes"])
|
||||
AC_LANG_POP
|
||||
])
|
||||
if test x"$ac_cv_posix_fadvise" = "xyes" ; then
|
||||
AC_DEFINE([HAVE_TIOCGWINSZ], 1, [define if ioctl & TIOCGWINSZ are available])
|
||||
fi
|
@ -43,6 +43,7 @@ m4_include(ac/ax_boost_foreach.m4)
|
||||
m4_include(ac/boost.m4)
|
||||
m4_include(ac/etags.m4)
|
||||
m4_include(ac/ax_docbook.m4)
|
||||
m4_include(ac/tiocgwinsz.m4)
|
||||
|
||||
AC_OUTPUT(
|
||||
Makefile
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "common/common.h"
|
||||
#include "common/strings/formatting.h"
|
||||
#include "common/strings/utf8.h"
|
||||
#include "common/terminal.h"
|
||||
#include "common/translation.h"
|
||||
|
||||
std::string
|
||||
@ -152,6 +153,9 @@ format_paragraph(const std::wstring &text_to_wrap,
|
||||
int current_column = get_width_in_em(text);
|
||||
bool break_anywhere = translation_c::get_active_translation().m_line_breaks_anywhere;
|
||||
|
||||
if (WRAP_AT_TERMINAL_WIDTH == wrap_column)
|
||||
wrap_column = get_terminal_columns() - 1;
|
||||
|
||||
if ((0 != indent_column) && (current_column >= indent_column)) {
|
||||
text += L"\n";
|
||||
current_column = 0;
|
||||
|
@ -34,21 +34,21 @@
|
||||
(int32_t)( (t) % 1000000000)
|
||||
#define ARG_TIMECODEN(t) ARG_TIMECODENINT((int64_t)(t))
|
||||
|
||||
#define WRAP_COLUMN 79
|
||||
#define WRAP_AT_TERMINAL_WIDTH -1
|
||||
|
||||
std::string MTX_DLL_API format_timecode(int64_t timecode, unsigned int precision = 9);
|
||||
std::string MTX_DLL_API format_paragraph(const std::string &text_to_wrap,
|
||||
int indent_column = 0,
|
||||
const std::string &indent_first_line = empty_string,
|
||||
std::string indent_following_lines = empty_string,
|
||||
int wrap_column = WRAP_COLUMN,
|
||||
int wrap_column = WRAP_AT_TERMINAL_WIDTH,
|
||||
const char *break_chars = " ,.)/:");
|
||||
|
||||
std::wstring MTX_DLL_API format_paragraph(const std::wstring &text_to_wrap,
|
||||
int indent_column = 0,
|
||||
const std::wstring &indent_first_line = L" ",
|
||||
std::wstring indent_following_lines = L" ",
|
||||
int wrap_column = WRAP_COLUMN,
|
||||
int wrap_column = WRAP_AT_TERMINAL_WIDTH,
|
||||
const std::wstring &break_chars = L" ,.)/:");
|
||||
|
||||
void MTX_DLL_API fix_format(const char *fmt, std::string &new_fmt);
|
||||
|
37
src/common/terminal.cpp
Normal file
37
src/common/terminal.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
mkvmerge -- utility for splicing together matroska files
|
||||
from component media subtypes
|
||||
|
||||
Distributed under the GPL
|
||||
see the file COPYING for details
|
||||
or visit http://www.gnu.org/copyleft/gpl.html
|
||||
|
||||
terminal access functions
|
||||
|
||||
Written by Moritz Bunkus <moritz@bunkus.org>.
|
||||
*/
|
||||
|
||||
#include "common/os.h"
|
||||
|
||||
#if defined(HAVE_TIOCGWINSZ)
|
||||
# include <sys/ioctl.h>
|
||||
#endif // HAVE_TIOCGWINSZ
|
||||
|
||||
#include "common/terminal.h"
|
||||
|
||||
#define DEFAULT_TERMINAL_COLUMNS 80
|
||||
|
||||
int
|
||||
get_terminal_columns() {
|
||||
#if defined(HAVE_TIOCGWINSZ)
|
||||
struct winsize ws;
|
||||
|
||||
if (ioctl(0, TIOCGWINSZ, &ws) != 0)
|
||||
return DEFAULT_TERMINAL_COLUMNS;
|
||||
return ws.ws_col;
|
||||
|
||||
#else // HAVE_TIOCGWINSZ
|
||||
return DEFAULT_TERMINAL_COLUMNS;
|
||||
#endif // HAVE_TIOCGWINSZ
|
||||
}
|
||||
|
21
src/common/terminal.h
Normal file
21
src/common/terminal.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
mkvmerge -- utility for splicing together matroska files
|
||||
from component media subtypes
|
||||
|
||||
Distributed under the GPL
|
||||
see the file COPYING for details
|
||||
or visit http://www.gnu.org/copyleft/gpl.html
|
||||
|
||||
terminal access functions
|
||||
|
||||
Written by Moritz Bunkus <moritz@bunkus.org>.
|
||||
*/
|
||||
|
||||
#ifndef __MTX_COMMON_TERMINAL_H
|
||||
#define __MTX_COMMON_TERMINAL_H
|
||||
|
||||
#include "common/os.h"
|
||||
|
||||
int MTX_DLL_API get_terminal_columns();
|
||||
|
||||
#endif // __MTX_COMMON_TERMINAL_H
|
Loading…
Reference in New Issue
Block a user