Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove wordwrap for links so they don't break (on mobile and smaller #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions js/terminal-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,10 @@ extend = (term) => {
// Hyperlinks
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
const urlMatches = text.matchAll(urlRegex);
let allowWrapping = true;
for (match of urlMatches) {
allowWrapping = match[0].length < 76;
text = text.replace(match[0], colorText(match[0], "hyperlink"));
}

// Text Wrap
if (allowWrapping && wrap) {
text = _wordWrap(text, Math.min(term.cols, 76));
}

// Commands
const cmds = Object.keys(commands);
for (cmd of cmds) {
Expand Down Expand Up @@ -192,31 +185,3 @@ extend = (term) => {
}
}

// https://stackoverflow.com/questions/14484787/wrap-text-in-javascript
// TODO: This doesn't work well at detecting newline
function _wordWrap(str, maxWidth) {
var newLineStr = "\r\n"; done = false; res = '';
while (str.length > maxWidth) {
found = false;
// Inserts new line at first whitespace of the line
for (i = maxWidth - 1; i >= 0; i--) {
if (_testWhite(str.charAt(i))) {
res = res + [str.slice(0, i), newLineStr].join('');
str = str.slice(i + 1);
found = true;
break;
}
}
// Inserts new line at maxWidth position, the word is too long to wrap
if (!found) {
res += [str.slice(0, maxWidth), newLineStr].join('');
str = str.slice(maxWidth);
}
}
return res + str;
}

function _testWhite(x) {
var white = new RegExp(/^\s$/);
return white.test(x.charAt(0));
};