From 23e09eb7f480ea383b1ccb40e6b6434291cc8840 Mon Sep 17 00:00:00 2001 From: Peter Elliott Date: Tue, 28 Dec 2021 10:26:12 -0700 Subject: [PATCH] less: Handle tabs in line wrapping Before tabs were treated as a width of 1, which would cause issues with man page headers. --- Userland/Utilities/less.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Userland/Utilities/less.cpp b/Userland/Utilities/less.cpp index 319712a59b..756befba63 100644 --- a/Userland/Utilities/less.cpp +++ b/Userland/Utilities/less.cpp @@ -75,9 +75,15 @@ static Vector wrap_line(String const& string, size_t width) if (*it == '\e') in_ansi = true; - if (!in_ansi) - // FIXME: calculate the printed width of the character. - offset++; + if (!in_ansi) { + if (*it == '\t') { + // Tabs are a special case, because their width is variable. + offset += (8 - (offset % 8)); + } else { + // FIXME: calculate the printed width of the character. + offset++; + } + } if (isalpha(*it)) in_ansi = false;