mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 09:12:11 +08:00
Migrate reformat_for_screen to new termsize container
This commit is contained in:
parent
340c8490f6
commit
db909605b8
@ -27,6 +27,7 @@
|
||||
#include "parser_keywords.h"
|
||||
#include "proc.h"
|
||||
#include "signal.h"
|
||||
#include "termsize.h"
|
||||
#include "wcstringutil.h"
|
||||
#include "wgetopt.h"
|
||||
#include "wutil.h" // IWYU pragma: keep
|
||||
@ -371,7 +372,7 @@ int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
buff.append(name);
|
||||
buff.append(L", ");
|
||||
}
|
||||
streams.out.append(reformat_for_screen(buff));
|
||||
streams.out.append(reformat_for_screen(buff, termsize_last()));
|
||||
} else {
|
||||
for (const auto &name : names) {
|
||||
streams.out.append(name.c_str());
|
||||
|
@ -62,6 +62,7 @@
|
||||
#include "parser.h"
|
||||
#include "proc.h"
|
||||
#include "signal.h"
|
||||
#include "termsize.h"
|
||||
#include "wcstringutil.h"
|
||||
#include "wildcard.h"
|
||||
#include "wutil.h" // IWYU pragma: keep
|
||||
@ -778,10 +779,10 @@ void narrow_string_safe(char buff[64], const wchar_t *s) {
|
||||
buff[idx] = '\0';
|
||||
}
|
||||
|
||||
wcstring reformat_for_screen(const wcstring &msg) {
|
||||
wcstring reformat_for_screen(const wcstring &msg, const termsize_t &termsize) {
|
||||
wcstring buff;
|
||||
int line_width = 0;
|
||||
int screen_width = common_get_width();
|
||||
int screen_width = termsize.width;
|
||||
|
||||
if (screen_width) {
|
||||
const wchar_t *start = msg.c_str();
|
||||
|
@ -38,6 +38,8 @@
|
||||
typedef std::wstring wcstring;
|
||||
typedef std::vector<wcstring> wcstring_list_t;
|
||||
|
||||
struct termsize_t;
|
||||
|
||||
// Maximum number of bytes used by a single utf-8 character.
|
||||
#define MAX_UTF8_BYTES 6
|
||||
|
||||
@ -662,8 +664,8 @@ int common_get_height();
|
||||
/// variable used by common_get_wisth and common_get_height().
|
||||
void common_handle_winch(int signal);
|
||||
|
||||
/// Write the given paragraph of output, redoing linebreaks to fit the current screen.
|
||||
wcstring reformat_for_screen(const wcstring &msg);
|
||||
/// Write the given paragraph of output, redoing linebreaks to fit \p termsize.
|
||||
wcstring reformat_for_screen(const wcstring &msg, const termsize_t &termsize);
|
||||
|
||||
/// Print a short message about how to file a bug report to stderr.
|
||||
void bugreport();
|
||||
|
@ -107,4 +107,7 @@ struct termsize_container_t {
|
||||
friend termsize_tester_t;
|
||||
};
|
||||
|
||||
/// Convenience helper to return the last known termsize.
|
||||
inline termsize_t termsize_last() { return termsize_container_t::shared().last(); }
|
||||
|
||||
#endif // FISH_TERMSIZE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user