Skip to content

Commit

Permalink
add wrap and keepWords option to less #641
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 20, 2021
1 parent 37e002f commit 083e14e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.21.0
### Features
* add wrap and keepWords option to less [#641](https://github.com/jcubic/jquery.terminal/issues/641)

## 2.20.2
### Bugfix
* fix bold background and default color in Unix formatting (another ANSI artwork issue)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ https://terminal.jcubic.pl

[![npm](https://img.shields.io/badge/npm-2.20.2-blue.svg)](https://www.npmjs.com/package/jquery.terminal)
![bower](https://img.shields.io/badge/bower-2.20.2-yellow.svg)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&dcc0c4ea2a55c9a5e4d6ebc2d893f5e80c0b77c8)](https://travis-ci.org/jcubic/jquery.terminal)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&37e002f35335aed4c9ba2e54355671f525c122b7)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=master&2aa4fec1b099d52d90ea7eb6cfd50fc7)](https://coveralls.io/github/jcubic/jquery.terminal?branch=master)
![downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
[![](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded)](https://www.jsdelivr.com/package/npm/jquery.terminal)
Expand Down
6 changes: 5 additions & 1 deletion js/jquery.terminal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ interface JQuery<TElement = HTMLElement> {
visible(): JQuery;
hidden(): JQuery;
// plugins
less(text: JQueryTerminal.LessArgument, options?: {formatters?: boolean}): JQueryTerminal;
less(text: JQueryTerminal.LessArgument, options?: {
formatters?: boolean,
wrap?: boolean,
keepWords?: boolean
}): JQueryTerminal;
}

interface JQueryStatic {
Expand Down
40 changes: 31 additions & 9 deletions js/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
}
term.set_prompt(prompt);
var to_print = lines.slice(pos, pos + rows - 1);
var should_substring = to_print.filter(function(line) {
var should_substring = options.wrap ? false : to_print.filter(function(line) {
var len = $.terminal.length(line);
return len > cols;
}).length;
Expand All @@ -187,6 +187,11 @@
}
}
term.echo(to_print.join('\n'));
if (term.find('.terminal-output').is(':empty')) {
// sometimes the output is not flushed not idea why
// TODO: investigate
term.flush();
}
}
// -------------------------------------------------------------------------------
function quit() {
Expand Down Expand Up @@ -227,14 +232,27 @@
rows = term.rows();
fixed_output();
function cont(l) {
original_lines = l;
original_lines = process_optional_wrap(l);
lines = original_lines.slice();
if (in_search) {
search(last_found);
} else {
print();
}
}
function process_optional_wrap(arg) {
if (arg instanceof Array) {
if (options.wrap) {
arg = arg.join('\n');
return $.terminal.split_equal(arg, cols, options.keepWords);
}
return arg;
} else if (options.wrap) {
return $.terminal.split_equal(arg, cols, options.keepWords);
} else {
return [arg];
}
}
function run(arg) {
var text;
if (arg instanceof Array) {
Expand Down Expand Up @@ -441,15 +459,19 @@
} else if (key === 'Q') {
quit();
} else if (key === 'ARROWRIGHT') {
left += Math.round(cols / 2);
print();
if (!options.wrap) {
left += Math.round(cols / 2);
print();
}
} else if (key === 'ARROWLEFT') {
left -= Math.round(cols / 2);
if (left < 0) {
left = 0;
if (!options.wrap) {
left -= Math.round(cols / 2);
if (left < 0) {
left = 0;
}
print();
// scroll
}
print();
// scroll
} else if (lines.length > rows) {
if (key === 'ARROWUP') { //up
if (pos > 0) {
Expand Down

0 comments on commit 083e14e

Please sign in to comment.